Example #1
0
 /**
  * @return object
  * @throws \yii\base\InvalidConfigException
  */
 protected static function getSession()
 {
     if (is_null(static::$session)) {
         static::$session = Instance::ensure(static::$session, Session::className());
     }
     return static::$session;
 }
Example #2
0
 public static function register(Di $di)
 {
     static::$di = $di;
     ini_set('session.use_cookies', 0);
     ini_set('session.cache_limiter', '');
     $di->remove('session');
     static::$session = null;
     $di->setShared('session', function () {
         $default = Config::get('session.default');
         $config = Config::get('session.drivers.' . $default);
         $class = $config['adapter'];
         $options = $config['options'];
         $options += Config::get('session.options');
         $options['cookies'] += Config::get('cookies');
         session_name($options['cookies']['name']);
         strpos($class, '\\') === false and $class = 'Phwoolcon\\Session\\Adapter\\' . $class;
         $session = new $class($options);
         // @codeCoverageIgnoreStart
         if (!$session instanceof AdapterInterface) {
             throw new SessionException('Session class should implement ' . AdapterInterface::class);
         }
         // @codeCoverageIgnoreEnd
         return $session;
     });
 }
Example #3
0
 public static function get_instance()
 {
     if (!isset(static::$session)) {
         static::$session = new static();
     }
     return static::$session;
 }
Example #4
0
 /**
  * Run application
  */
 public function run()
 {
     static::$session = new Session();
     static::$cookies = new Cookies();
     (new ErrorHandler())->register();
     $this->router();
     $this->send();
 }
Example #5
0
 protected static function init()
 {
     if (static::$session === null) {
         $config = Kernel::getConfig('session', array('class' => 'PFinal\\Session\\NativeSession', 'keyPrefix' => 'pfinal.wechat'));
         $class = $config['class'];
         unset($config['class']);
         static::$session = new $class($config);
     }
 }
Example #6
0
 /**
  * Ensure the session instance has been created.
  *
  * @return void
  */
 protected static function getInstance()
 {
     if (static::$session instanceof SessionInstance) {
         return static::$session;
     }
     if (strlen(static::$name) < 1) {
         throw new \Exception("Cannot start session, no name has been specified, you must call Session::name() before using this class");
     }
     static::$session = new SessionInstance(static::$name);
     return static::$session;
 }
Example #7
0
 /**
  * Load a user session by ID.
  *
  * @param  string  $id
  * @return void
  */
 public static function load($id)
 {
     static::$session = !is_null($id) ? static::driver()->load($id) : null;
     if (static::invalid(static::$session)) {
         static::$session = array('id' => Str::random(40), 'data' => array());
     }
     if (!static::has('csrf_token')) {
         static::put('csrf_token', Str::random(16));
     }
     static::$session['last_activity'] = time();
 }
Example #8
0
 /**
  * Create a session handler with singleton method
  * 
  * @param array $config
  * @return \Sugi\Session with type specified in config array
  */
 public static function singleton($config = array())
 {
     // return created session
     if (static::$session) {
         return static::$session;
     }
     // If we did not set type - we will not use Session wrapper
     if (empty($config['type'])) {
         return false;
     }
     // Loading child class
     $type = strtolower($config['type']);
     $Type = ucfirst($type);
     $class_name = "\\Sugi\\Session\\{$Type}";
     $class_file = __DIR__ . "/Session/{$Type}.php";
     if (!class_exists($class_name)) {
         if (!File::exists($class_file)) {
             throw new \Exception("Unknow \\Sugi\\Session type {$Type}");
         }
         include $class_file;
     }
     static::$type = $type;
     session_set_save_handler(array('\\Sugi\\Session', 'open'), array('\\Sugi\\Session', 'close'), array('\\Sugi\\Session', 'read'), array('\\Sugi\\Session', 'write'), array('\\Sugi\\Session', 'destroy'), array('\\Sugi\\Session', 'gc'));
     // Garbage collector settings
     // Max LifeTime in seconds
     if (isset($config['gc_maxlifetime'])) {
         ini_set('session.gc_maxlifetime', (int) $config['gc_maxlifetime']);
     }
     // The garbage collector (GC) probability
     // GC will be executed (gc_probability / gc_divisor)% of the sessions reads
     if (isset($config['gc_probability'])) {
         ini_set('session.gc_probability', (int) $config['gc_probability']);
     }
     if (isset($config['gc_divisor'])) {
         ini_set('session.gc_divisor', (int) $config['gc_divisor']);
     }
     register_shutdown_function('\\Sugi\\Session::close');
     $child_params = isset($config[$type]) ? $config[$type] : array();
     // return instance
     static::$session = new $class_name($child_params);
     return static::$session;
 }
Example #9
0
 public static function run($config)
 {
     if (isset($config['db'])) {
         if (isset($config['db']['username'])) {
             static::$db = new DB($config['db']['dsn'], $config['db']['username'], $config['db']['password']);
         } else {
             static::$db = new DB($config['db']['dsn']);
         }
     }
     static::$assets = new Assets(isset($config['assets']) ? $config['assets'] : []);
     static::$user = new User();
     static::$url = new Url();
     static::$request = new Request();
     static::$session = new Session();
     static::$helper = new Helper();
     static::$params = $config['params'];
     $url = str_replace(static::$url->path(), '', $_SERVER['REQUEST_URI']);
     $options = isset($config['route']) ? $config['route'] : [];
     static::$route = new Route($url, $options);
     static::$route->run();
 }
Example #10
0
 /**
  * @return Session
  */
 public static function getSession()
 {
     if (!isset(static::$session)) {
         static::$session = new Session();
     }
     return static::$session;
 }
Example #11
0
 public function trash($userData = null)
 {
     if (is_string($userData)) {
         unset(static::$session[$userData]);
         //unset(PHPSESSID);
         // static::$session = array();
     }
     /*if (is_array($userData)) {
           foreach ($userData as $key => $val) {
               unset(static::$session[$key]);
               static::$session = array();
           }
       }*/
     if (is_null($userData)) {
         static::$session = array();
     }
     // static::$session = array();
     if (isset($_COOKIE[session_name()])) {
         setcookie($this->getSessionName(), '', time() - 42000, '/');
     }
     //session_destroy();
     /*
              if (isset($_COOKIE[session_name()])) {
             $cookie_params = session_get_cookie_params();
     
             setcookie(
                 session_name(),
                 false,
                 315554400, // strtotime('1980-01-01'),
                 $cookie_falses['path'],
                 $cookie_falses['domain'],
                 $cookie_falses['secure']
                 );
             }*/
     return true;
 }
Example #12
0
 /**
  * Sets the session manager
  * 
  * @param \Xaamin\Whatsapi\Sessions\SessionInterface $session
  */
 public static function setSessionManager(SessionInterface $session)
 {
     static::$session = $session;
 }
Example #13
0
 protected function createStorage($sessionId = null)
 {
     if ($sessionId !== null) {
         // $name = '/Google_Client';
         // $path = session_save_path().'/'.$name;
         $name = 'Recca0120Socialite';
         $path = sys_get_temp_dir() . '/' . $name;
         $sessionId = sha1(serialize($sessionId));
         $file = new Filesystem();
         if ($file->isDirectory($path) === false) {
             $file->makeDirectory($path, 0755, true);
         }
         $handler = new FileSessionHandler($file, $path);
         $session = new LaravelSession($name, $handler, $sessionId);
         // $handler = new SymfonyFileHandler($path);
         // $session = new SymfonySession($handler);
         $session->setId($sessionId);
         $session->start();
         $this->saveSessionWhenShutdown($session);
     } else {
         $session = static::$session;
         if ($session === null) {
             $session = $this->request->getSession();
             if ($session === null) {
                 if (session_status() == PHP_SESSION_NONE) {
                     $handler = new SymfonyNativeSessionHandler();
                 } else {
                     $handler = new SymfonyPhpBridgeSessionHandler();
                 }
                 $session = new SymfonySession($handler);
                 $session->start();
                 $this->saveSessionWhenShutdown($session);
             }
             static::$session = $session;
         }
     }
     $storage = new Storage($session);
     return $storage;
 }
Example #14
0
 /**
  * @return SessionNamespace
  */
 private static function getSession()
 {
     if (!isset(static::$session)) {
         static::$session = new SessionNamespace('notification');
     }
     if (empty(static::$session->notifications) && self::isEnabled()) {
         static::$session->notifications = array();
     }
     return static::$session;
 }
 public static function tearDownAfterClass()
 {
     parent::tearDownAfterClass();
     static::$session = null;
 }
Example #16
0
 public function __construct($url)
 {
     if (is_null(static::$config) && isset($GLOBALS['config'])) {
         static::$config = $GLOBALS['config'];
     }
     if (is_null(static::$conn) && isset($GLOBALS['conn'])) {
         static::$conn = $GLOBALS['conn'];
     }
     if (is_null(static::$cache) && isset($GLOBALS['cache'])) {
         static::$cache = $GLOBALS['cache'];
     }
     if (is_null(static::$session) && isset($GLOBALS['session'])) {
         static::$session = $GLOBALS['session'];
     }
     $this->url = $url;
     $this->Init();
 }
Example #17
0
 public static function instance($ns)
 {
     static::$sessionKey = $ns;
     static::$sessions[$ns] = session('Basket_' . $ns);
     static::$session = static::$sessions[$ns];
 }
Example #18
0
 /**
  * [setSessionStore description]
  * @param Illuminate\Session\Store $session
  */
 public static function setSessionStore(Store $session)
 {
     static::$session = $session;
 }
Example #19
0
 public static function storeSession($session)
 {
     static::$session = $session;
     return true;
 }