Exemplo n.º 1
0
 public function setConfig(Config $config)
 {
     parent::setConfig($config);
     // @codeCoverageIgnoreStart
     $this->params += array('callUserSetCookiesHook' => false, 'sessionName' => $config->get('SessionName') ?: $config->get('CookiePrefix') . '_session');
     // @codeCoverageIgnoreStart
     $this->cookieOptions += array('prefix' => $config->get('CookiePrefix'), 'path' => $config->get('CookiePath'), 'domain' => $config->get('CookieDomain'), 'secure' => $config->get('CookieSecure'), 'httpOnly' => $config->get('CookieHttpOnly'));
 }
Exemplo n.º 2
0
 /**
  * @param int $priority Session priority
  * @param array $data
  *  - provider: (SessionProvider|null) If not given, the provider will be
  *    determined from the saved session data.
  *  - id: (string|null) Session ID
  *  - userInfo: (UserInfo|null) User known from the request. If
  *    $provider->canChangeUser() is false, a verified user
  *    must be provided.
  *  - persisted: (bool) Whether this session was persisted
  *  - remembered: (bool) Whether the verified user was remembered.
  *    Defaults to true.
  *  - forceHTTPS: (bool) Whether to force HTTPS for this session
  *  - metadata: (array) Provider metadata, to be returned by
  *    Session::getProviderMetadata().
  *  - idIsSafe: (bool) Set true if the 'id' did not come from the user.
  *    Generally you'll use this from SessionProvider::newEmptySession(),
  *    and not from any other method.
  *  - copyFrom: (SessionInfo) SessionInfo to copy other data items from.
  */
 public function __construct($priority, array $data)
 {
     if ($priority < self::MIN_PRIORITY || $priority > self::MAX_PRIORITY) {
         throw new \InvalidArgumentException('Invalid priority');
     }
     if (isset($data['copyFrom'])) {
         $from = $data['copyFrom'];
         if (!$from instanceof SessionInfo) {
             throw new \InvalidArgumentException('Invalid copyFrom');
         }
         $data += array('provider' => $from->provider, 'id' => $from->id, 'userInfo' => $from->userInfo, 'persisted' => $from->persisted, 'remembered' => $from->remembered, 'forceHTTPS' => $from->forceHTTPS, 'metadata' => $from->providerMetadata, 'idIsSafe' => $from->idIsSafe);
         // @codeCoverageIgnoreEnd
     } else {
         $data += array('provider' => null, 'id' => null, 'userInfo' => null, 'persisted' => false, 'remembered' => true, 'forceHTTPS' => false, 'metadata' => null, 'idIsSafe' => false);
         // @codeCoverageIgnoreEnd
     }
     if ($data['id'] !== null && !SessionManager::validateSessionId($data['id'])) {
         throw new \InvalidArgumentException('Invalid session ID');
     }
     if ($data['userInfo'] !== null && !$data['userInfo'] instanceof UserInfo) {
         throw new \InvalidArgumentException('Invalid userInfo');
     }
     if (!$data['provider'] && $data['id'] === null) {
         throw new \InvalidArgumentException('Must supply an ID when no provider is given');
     }
     if ($data['metadata'] !== null && !is_array($data['metadata'])) {
         throw new \InvalidArgumentException('Invalid metadata');
     }
     $this->provider = $data['provider'];
     if ($data['id'] !== null) {
         $this->id = $data['id'];
         $this->idIsSafe = $data['idIsSafe'];
     } else {
         $this->id = $this->provider->getManager()->generateSessionId();
         $this->idIsSafe = true;
     }
     $this->priority = (int) $priority;
     $this->userInfo = $data['userInfo'];
     $this->persisted = (bool) $data['persisted'];
     if ($data['provider'] !== null) {
         if ($this->userInfo !== null && !$this->userInfo->isAnon() && $this->userInfo->isVerified()) {
             $this->remembered = (bool) $data['remembered'];
         }
         $this->providerMetadata = $data['metadata'];
     }
     $this->forceHTTPS = (bool) $data['forceHTTPS'];
 }
 /**
  * @param array $params Keys include:
  *  - sessionCookieName: Session cookie name, if multiple sessions per
  *    client are to be supported.
  *  - sessionCookieOptions: Options to pass to WebResponse::setCookie().
  */
 public function __construct($params = array())
 {
     parent::__construct();
     if (isset($params['sessionCookieName'])) {
         if (!is_string($params['sessionCookieName'])) {
             throw new \InvalidArgumentException('sessionCookieName must be a string');
         }
         $this->sessionCookieName = $params['sessionCookieName'];
     }
     if (isset($params['sessionCookieOptions'])) {
         if (!is_array($params['sessionCookieOptions'])) {
             throw new \InvalidArgumentException('sessionCookieOptions must be an array');
         }
         $this->sessionCookieOptions = $params['sessionCookieOptions'];
     }
 }