Exemplo n.º 1
0
 /**
  * @covers \Phalcon\Session\Bag::get()
  * @covers \Phalcon\Session\Bag::set()
  * @covers \Phalcon\Session\Bag::__get()
  * @covers \Phalcon\Session\Bag::__set()
  */
 public function testGetSet()
 {
     \Phalcon\DI::reset();
     new \Phalcon\DI\FactoryDefault();
     @session_start();
     // Using getters and setters.
     $bag = new Phalcon\Session\Bag('test1');
     $bag->set('a', array('b' => 'c'));
     $this->assertEquals(array('b' => 'c'), $bag->get('a'));
     $this->assertEquals(array('b' => 'c'), $_SESSION['test1']['a']);
     // Using direct access.
     $bag = new Phalcon\Session\Bag('test2');
     $bag->a = array('b' => 'c');
     $this->assertEquals(array('b' => 'c'), $bag->{'a'});
     $this->assertEquals(array('b' => 'c'), $_SESSION['test2']['a']);
     // Using direct access with initialising a variable.
     $bag = new Phalcon\Session\Bag('test3');
     $bag->a['b'] = 'c';
     $this->assertEquals(array('b' => 'c'), $bag->a);
     $this->assertEquals(array('b' => 'c'), $_SESSION['test3']['a']);
 }
Exemplo n.º 2
0
 public function authenticate($access)
 {
     if ($this->checkAccess($access)) {
         $u = new \Phalcon\Session\Bag(self::SESSION_KEY);
         $u->setDI($this->getDI());
         $u->id = $this->user->getId();
         $u->username = $this->user->getUsername();
         $u->gender = $this->user->getGender();
         $u->description = $this->user->getDescription();
         $u->email = $this->user->getEmail();
         $u->firstName = $this->user->getFirstName();
         $u->lastName = $this->user->getLastName();
         $u->groups = $this->getGroupsNames($this->user);
         $u->roles = $this->getNormalizedRoles($this->user);
         return true;
     }
     return false;
 }
Exemplo n.º 3
0
 $di->set('cookies', function () use($config) {
     $cookies = new \Phalcon\Http\Response\Cookies();
     $cookies->useEncryption(true);
     return $cookies;
 }, true);
 $di->set('session', function () use($config) {
     $session = new Session(array('servers' => array(array('host' => $config->memcached[ENVIRONMENT]->host, 'port' => (int) $config->memcached->port, 'weight' => 1)), 'client' => array(\Memcached::OPT_HASH => \Memcached::HASH_MD5, \Memcached::OPT_PREFIX_KEY => $config->memcached->prefix, \Memcached::OPT_RECV_TIMEOUT => 1000, \Memcached::OPT_SEND_TIMEOUT => 1000, \Memcached::OPT_TCP_NODELAY => true, \Memcached::OPT_SERVER_FAILURE_LIMIT => 50, \Memcached::OPT_CONNECT_TIMEOUT => 500, \Memcached::OPT_RETRY_TIMEOUT => 300, \Memcached::OPT_DISTRIBUTION => \Memcached::DISTRIBUTION_CONSISTENT, \Memcached::OPT_REMOVE_FAILED_SERVERS => true, \Memcached::OPT_LIBKETAMA_COMPATIBLE => true), 'lifetime' => (int) $config->memcached->lifetime, 'prefix' => $config->memcached->prefix));
     if ($session->status() !== $session::SESSION_ACTIVE) {
         $domain = Domain::get();
         session_set_cookie_params((int) $config->memcached->lifetime, '/', '.' . $domain, (bool) $config->cookie->secure, (bool) $config->cookie->httponly);
         $session->start();
     }
     return $session;
 }, true);
 $di->set('csrf_session_bag', function () use($di) {
     $csrf_session_bag = new \Phalcon\Session\Bag('CSRF_SESSION_BAG');
     $csrf_session_bag->setDI($di);
     return $csrf_session_bag;
 }, true);
 $di->set('url', function () {
     return new \Phalcon\Mvc\Url();
 }, true);
 /**
  * Router
  */
 $di->set('router', function () {
     require ROOT . DS . 'configs' . DS . 'routes' . DS . ucfirst(SITENAME) . '.php';
     return $router;
 }, true);
 $di->set('url', function () {
     return new \Phalcon\Mvc\Url();
Exemplo n.º 4
0
<?php

$user = new Phalcon\Session\Bag('user');
$user->setDI($di);
$user->name = "Kimbra Johnson";
$user->age = 22;