Lançado Adianti Framework 7.6!
Clique aqui para saber mais
menu

Adianti Solutions

API

Adianti, Framework, PHP, MVC, Active record, Front controller, IDE, RAD, Web, multiplataforma, geração de código, desenvolvimento rápido, relatórios, formulários, listagens, datagrids, gráficos, banco de dados, padrões de projeto, design patterns API do Adianti Framework.
API Docs
code
Selecione a classe

Source for file TSession.php

Documentation is available at TSession.php

  1. <?php
  2. namespace Adianti\Registry;
  3.  
  4. use SessionHandlerInterface;
  5. use Adianti\Registry\AdiantiRegistryInterface;
  6.  
  7. /**
  8.  * Session Data Handler
  9.  *
  10.  * @version    7.4
  11.  * @package    registry
  12.  * @author     Pablo Dall'Oglio
  13.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  14.  * @license    http://www.adianti.com.br/framework-license
  15.  */
  16. class TSession implements AdiantiRegistryInterface
  17. {
  18.     /**
  19.      * Class Constructor
  20.      */
  21.     public function __construct(SessionHandlerInterface $handler NULL$path NULL)
  22.     {
  23.         if ($path)
  24.         {
  25.             session_save_path($path);
  26.         }
  27.         
  28.         if ($handler)
  29.         {
  30.             session_set_save_handler($handlertrue);
  31.         }
  32.         
  33.         // if there's no opened session
  34.         if (!session_id())
  35.         {
  36.             session_start();
  37.         }
  38.     }
  39.     
  40.     /**
  41.      * Returns if the service is active
  42.      */
  43.     public static function enabled()
  44.     {
  45.         if (!session_id())
  46.         {
  47.             return session_start();
  48.         }
  49.         return TRUE;
  50.     }
  51.     
  52.     /**
  53.      * Define the value for a variable
  54.      * @param $var   Variable Name
  55.      * @param $value Variable Value
  56.      */
  57.     public static function setValue($var$value)
  58.     {
  59.         if (defined('APPLICATION_NAME'))
  60.         {
  61.             $_SESSION[APPLICATION_NAME][$var$value;
  62.         }
  63.         else
  64.         {
  65.             $_SESSION[$var$value;
  66.         }
  67.     }
  68.     
  69.     /**
  70.      * Returns the value for a variable
  71.      * @param $var Variable Name
  72.      */
  73.     public static function getValue($var)
  74.     {
  75.         if (defined('APPLICATION_NAME'))
  76.         {
  77.             if (isset($_SESSION[APPLICATION_NAME][$var]))
  78.             {
  79.                 return $_SESSION[APPLICATION_NAME][$var];
  80.             }
  81.         }
  82.         else
  83.         {
  84.             if (isset($_SESSION[$var]))
  85.             {
  86.                 return $_SESSION[$var];
  87.             }
  88.         }
  89.     }
  90.     
  91.     /**
  92.      * Clear the value for a variable
  93.      * @param $var   Variable Name
  94.      */
  95.     public static function delValue($var)
  96.     {
  97.         if (defined('APPLICATION_NAME'))
  98.         {
  99.             unset($_SESSION[APPLICATION_NAME][$var]);
  100.         }
  101.         else
  102.         {
  103.             unset($_SESSION[$var]);
  104.         }
  105.     }
  106.     
  107.     /**
  108.      * Regenerate id
  109.      */
  110.     public static function regenerate()
  111.     {
  112.         session_regenerate_id();
  113.     }
  114.     
  115.     /**
  116.      * Clear session
  117.      */
  118.     public static function clear()
  119.     {
  120.         self::freeSession();
  121.     }
  122.     
  123.     /**
  124.      * Destroy the session data
  125.      * Backward compatibility
  126.      */
  127.     public static function freeSession()
  128.     {
  129.         if (defined('APPLICATION_NAME'))
  130.         {
  131.             $_SESSION[APPLICATION_NAMEarray();
  132.         }
  133.         else
  134.         {
  135.             $_SESSION[array();
  136.         }
  137.     }
  138. }