当前位置: 首页>>代码示例>>PHP>>正文


PHP sfStorage::initialize方法代码示例

本文整理汇总了PHP中sfStorage::initialize方法的典型用法代码示例。如果您正苦于以下问题:PHP sfStorage::initialize方法的具体用法?PHP sfStorage::initialize怎么用?PHP sfStorage::initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sfStorage的用法示例。


在下文中一共展示了sfStorage::initialize方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: initialize

 /**
  * Available options:
  *
  *  * session_name:            The cookie name (symfony by default)
  *  * session_id:              The session id (null by default)
  *  * auto_start:              Whether to start the session (true by default)
  *  * session_cookie_lifetime: Cookie lifetime
  *  * session_cookie_path:     Cookie path
  *  * session_cookie_domain:   Cookie domain
  *  * session_cookie_secure:   Cookie secure
  *  * session_cookie_httponly: Cookie http only (only for PHP >= 5.2)
  *
  * The default values for all 'session_cookie_*' options are those returned by the session_get_cookie_params() function
  *
  * @param array $options  An associative array of options
  *
  * @see sfStorage
  */
 public function initialize($options = null)
 {
     $cookieDefaults = session_get_cookie_params();
     $options = array_merge(array('session_name' => 'symfony', 'session_id' => null, 'auto_start' => true, 'session_cookie_lifetime' => $cookieDefaults['lifetime'], 'session_cookie_path' => $cookieDefaults['path'], 'session_cookie_domain' => $cookieDefaults['domain'], 'session_cookie_secure' => $cookieDefaults['secure'], 'session_cookie_httponly' => isset($cookieDefaults['httponly']) ? $cookieDefaults['httponly'] : false, 'session_cache_limiter' => 'none'), $options);
     // initialize parent
     parent::initialize($options);
     // set session name
     $sessionName = $this->options['session_name'];
     session_name($sessionName);
     if (!(bool) ini_get('session.use_cookies') && ($sessionId = $this->options['session_id'])) {
         session_id($sessionId);
     }
     $lifetime = $this->options['session_cookie_lifetime'];
     $path = $this->options['session_cookie_path'];
     $domain = $this->options['session_cookie_domain'];
     $secure = $this->options['session_cookie_secure'];
     $httpOnly = $this->options['session_cookie_httponly'];
     session_set_cookie_params($lifetime, $path, $domain, $secure, $httpOnly);
     if (!is_null($this->options['session_cache_limiter'])) {
         session_cache_limiter($this->options['session_cache_limiter']);
     }
     if ($this->options['auto_start'] && !self::$sessionStarted) {
         session_start();
         self::$sessionStarted = true;
     }
 }
开发者ID:JimmyVB,项目名称:Symfony-v1.2,代码行数:44,代码来源:sfSessionStorage.class.php

示例2: initialize

 /**
  * Initializes this Storage instance.
  *
  * @param sfContext A sfContext instance
  * @param array   An associative array of initialization parameters
  *
  * @return boolean true, if initialization completes successfully, otherwise false
  *
  * @throws <b>sfInitializationException</b> If an error occurs while initializing this Storage
  */
 public function initialize($context, $parameters = null)
 {
     // initialize parent
     parent::initialize($context, $parameters);
     // set session name
     $sessionName = $this->getParameterHolder()->get('session_name', 'symfony');
     session_name($sessionName);
     $use_cookies = (bool) ini_get('session.use_cookies');
     if (!$use_cookies) {
         $sessionId = $context->getRequest()->getParameter($sessionName, '');
         if ($sessionId != '') {
             session_id($sessionId);
         }
     }
     $cookieDefaults = session_get_cookie_params();
     $lifetime = $this->getParameter('session_cookie_lifetime', sfConfig::get('sf_timeout'));
     $path = $this->getParameter('session_cookie_path', $cookieDefaults['path']);
     $domain = $this->getParameter('session_cookie_domain', $cookieDefaults['domain']);
     $secure = $this->getParameter('session_cookie_secure', $cookieDefaults['secure']);
     $httpOnly = $this->getParameter('session_cookie_httponly', isset($cookieDefaults['httponly']) ? $cookieDefaults['httponly'] : false);
     if (version_compare(phpversion(), '5.2', '>=')) {
         session_set_cookie_params($lifetime, $path, $domain, $secure, $httpOnly);
     } else {
         session_set_cookie_params($lifetime, $path, $domain, $secure);
     }
     if ($this->getParameter('auto_start', true)) {
         // start our session
         session_start();
     }
 }
开发者ID:jonphipps,项目名称:Metadata-Registry,代码行数:40,代码来源:sfSessionStorage.class.php

示例3: initialize

 /**
  * Initializes this Storage instance.
  *
  * @param sfContext A sfContext instance
  * @param array   An associative array of initialization parameters
  *
  * @return boolean true, if initialization completes successfully, otherwise false
  *
  * @throws <b>sfInitializationException</b> If an error occurs while initializing this Storage
  */
 public function initialize($context, $parameters = null)
 {
     // initialize parent
     parent::initialize($context, $parameters);
     // maintain compatiblity with sfSessionStorage which always sent expiry headers
     header('Expires: Thu, 19 Nov 1981 08:52:00 GMT');
     header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
     header('Pragma: no-cache');
 }
开发者ID:DBezemer,项目名称:server,代码行数:19,代码来源:sfNoStorage.class.php

示例4: initialize

 /**
  * Initialize this Storage.
  *
  * @param array $options  An associative array of initialization parameters.
  *                        session_name [required] name of session to use
  *                        session_cookie_path [required] cookie path
  *                        session_cookie_domain [required] cookie domain
  *                        session_cookie_lifetime [required] liftime of cookie
  *                        session_cookie_secure [required] send only if secure connection
  *                        session_cookie_http_only [required] accessible only via http protocol
  *
  * @return bool true, when initialization completes successfully.
  *
  * @throws <b>sfInitializationException</b> If an error occurs while initializing this Storage.
  */
 public function initialize($options = array())
 {
     // initialize parent
     parent::initialize(array_merge(array('session_name' => 'sfproject', 'session_cookie_lifetime' => '+30 days', 'session_cookie_path' => '/', 'session_cookie_domain' => null, 'session_cookie_secure' => false, 'session_cookie_http_only' => true, 'session_cookie_secret' => 'sf$ecret'), $options));
     // create cache instance
     if (isset($this->options['cache']) && $this->options['cache']['class']) {
         $this->cache = new $this->options['cache']['class'](is_array($this->options['cache']['param']) ? $this->options['cache']['param'] : array());
     } else {
         throw new InvalidArgumentException('sfCacheSessionStorage requires cache option.');
     }
     $this->context = sfContext::getInstance();
     $this->dispatcher = $this->context->getEventDispatcher();
     $this->request = $this->context->getRequest();
     $this->response = $this->context->getResponse();
     $cookie = $this->request->getCookie($this->options['session_name']);
     if (strpos($cookie, ':') !== false) {
         // split cookie data id:signature(id+secret)
         list($id, $signature) = explode(':', $cookie, 2);
         if ($signature == sha1($id . ':' . $this->options['session_cookie_secret'])) {
             // cookie is valid
             $this->id = $id;
         } else {
             // cookie signature broken
             $this->id = null;
         }
     } else {
         // cookie format wrong
         $this->id = null;
     }
     if (empty($this->id)) {
         $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'localhost';
         $ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'ua';
         // generate new id based on random # / ip / user agent / secret
         $this->id = md5(rand(0, 999999) . $ip . $ua . $this->options['session_cookie_secret']);
         if (sfConfig::get('sf_logging_enabled')) {
             $this->dispatcher->notify(new sfEvent($this, 'application.log', array('New session created')));
         }
         // only send cookie when id is issued
         $this->response->setCookie($this->options['session_name'], $this->id . ':' . sha1($this->id . ':' . $this->options['session_cookie_secret']), $this->options['session_cookie_lifetime'], $this->options['session_cookie_path'], $this->options['session_cookie_domain'], $this->options['session_cookie_secure'], $this->options['session_cookie_http_only']);
         $this->data = array();
     } else {
         // load data from cache
         $this->data = $this->cache->get($this->id, array());
         if (sfConfig::get('sf_logging_enabled')) {
             $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Restored previous session')));
         }
     }
     session_id($this->id);
     $this->response->addCacheControlHttpHeader('private');
     return true;
 }
开发者ID:yuxw75,项目名称:Surrogate,代码行数:66,代码来源:sfCacheSessionStorage.class.php

示例5: initialize

 /**
  * Initializes this Storage instance.
  *
  * @param sfContext A sfContext instance
  * @param array   An associative array of initialization parameters
  *
  * @return boolean true, if initialization completes successfully, otherwise false
  *
  * @throws <b>sfInitializationException</b> If an error occurs while initializing this Storage
  */
 public function initialize($context, $parameters = null)
 {
     // initialize parent
     parent::initialize($context, $parameters);
     $this->sessionPath = sfConfig::get('sf_test_cache_dir') . DIRECTORY_SEPARATOR . 'sessions';
     if (array_key_exists('session_id', $_SERVER)) {
         $this->sessionId = $_SERVER['session_id'];
         // we read session data from temp file
         $file = $this->sessionPath . DIRECTORY_SEPARATOR . $this->sessionId . '.session';
         $this->sessionData = file_exists($file) ? unserialize(file_get_contents($file)) : array();
     } else {
         $this->sessionId = md5(uniqid(rand(), true));
         $this->sessionData = array();
     }
 }
开发者ID:jonphipps,项目名称:Metadata-Registry,代码行数:25,代码来源:sfSessionTestStorage.class.php

示例6: initialize

 /**
  * Available options:
  *
  *  * session_path: The path to store the session files (%SF_TEST_CACHE_DIR%/sessions by default)
  *  * session_id:   The session identifier
  *
  * @param array $options  An associative array of options
  *
  * @see sfStorage
  */
 public function initialize($options = null)
 {
     $options = array_merge(array('session_path' => sfConfig::get('sf_test_cache_dir') . '/sessions', 'session_id' => null), $options);
     // initialize parent
     parent::initialize($options);
     $this->sessionId = !is_null($this->options['session_id']) ? $this->options['session_id'] : (array_key_exists('session_id', $_SERVER) ? $_SERVER['session_id'] : null);
     if ($this->sessionId) {
         // we read session data from temp file
         $file = $this->options['session_path'] . DIRECTORY_SEPARATOR . $this->sessionId . '.session';
         $this->sessionData = file_exists($file) ? unserialize(file_get_contents($file)) : array();
     } else {
         $this->sessionId = md5(uniqid(rand(), true));
         $this->sessionData = array();
     }
 }
开发者ID:ajith24,项目名称:ajithworld,代码行数:25,代码来源:sfSessionTestStorage.class.php

示例7: initialize

 /**
  * Available options:
  *
  *  * session_path: The path to store the session files
  *  * session_id:   The session identifier
  *
  * @param array $options  An associative array of options
  *
  * @see sfStorage
  */
 public function initialize($options = null)
 {
     if (!isset($options['session_path'])) {
         throw new InvalidArgumentException('The "session_path" option is mandatory for the sfSessionTestStorage class.');
     }
     $options = array_merge(array('session_id' => null), $options);
     // initialize parent
     parent::initialize($options);
     $this->sessionId = null !== $this->options['session_id'] ? $this->options['session_id'] : (array_key_exists('session_id', $_SERVER) ? $_SERVER['session_id'] : null);
     if ($this->sessionId) {
         // we read session data from temp file
         $file = $this->options['session_path'] . DIRECTORY_SEPARATOR . $this->sessionId . '.session';
         $this->sessionData = file_exists($file) ? unserialize(file_get_contents($file)) : array();
     } else {
         $this->sessionId = md5(uniqid(rand(), true));
         $this->sessionData = array();
     }
 }
开发者ID:sensorsix,项目名称:app,代码行数:28,代码来源:sfSessionTestStorage.class.php

示例8: initialize

 /**
  * Initialize this Storage.
  *
  * @param array $options  An associative array of initialization parameters.
  *                        session_name [required] name of session to use
  *                        session_cookie_path [required] cookie path
  *                        session_cookie_domain [required] cookie domain
  *                        session_cookie_lifetime [required] liftime of cookie
  *                        session_cookie_secure [required] send only if secure connection
  *                        session_cookie_http_only [required] accessible only via http protocol
  *
  * @return bool true, when initialization completes successfully.
  *
  * @throws <b>sfInitializationException</b> If an error occurs while initializing this Storage.
  */
 public function initialize($options = array())
 {
     // initialize parent
     // bc with a slightly different name formerly used here, let's be
     // compatible with the base class name for it from here on out
     if (isset($options['session_cookie_http_only'])) {
         $options['session_cookie_httponly'] = $options['session_cookie_http_only'];
     }
     parent::initialize(array_merge(array('session_name' => 'sfproject', 'session_cookie_lifetime' => '+30 days', 'session_cookie_path' => '/', 'session_cookie_domain' => null, 'session_cookie_secure' => false, 'session_cookie_httponly' => true, 'session_cookie_secret' => 'sf$ecret'), $options));
     // create cache instance
     if (isset($this->options['cache']) && $this->options['cache']['class']) {
         $this->cache = new $this->options['cache']['class'](is_array($this->options['cache']['param']) ? $this->options['cache']['param'] : array());
     } else {
         throw new InvalidArgumentException('sfCacheSessionStorage requires cache option.');
     }
     $this->context = sfContext::getInstance();
     $this->dispatcher = $this->context->getEventDispatcher();
     $this->request = $this->context->getRequest();
     $this->response = $this->context->getResponse();
     $cookie = $this->request->getCookie($this->options['session_name']);
     if (strpos($cookie, ':') !== false) {
         // split cookie data id:signature(id+secret)
         list($id, $signature) = explode(':', $cookie, 2);
         if ($signature == sha1($id . ':' . $this->options['session_cookie_secret'])) {
             // cookie is valid
             $this->id = $id;
         } else {
             // cookie signature broken
             $this->id = null;
         }
     } else {
         // cookie format wrong
         $this->id = null;
     }
     if (empty($this->id)) {
         $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'localhost';
         $ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'ua';
         // generate new id based on random # / ip / user agent / secret
         $this->id = md5(rand(0, 999999) . $ip . $ua . $this->options['session_cookie_secret']);
         if (sfConfig::get('sf_logging_enabled')) {
             $this->dispatcher->notify(new sfEvent($this, 'application.log', array('New session created')));
         }
         // only send cookie when id is issued
         $this->response->setCookie($this->options['session_name'], $this->id . ':' . sha1($this->id . ':' . $this->options['session_cookie_secret']), $this->options['session_cookie_lifetime'], $this->options['session_cookie_path'], $this->options['session_cookie_domain'], $this->options['session_cookie_secure'], $this->options['session_cookie_httponly']);
         $this->data = array();
     } else {
         // load data from cache. Watch out for the default case. We could
         // serialize(array()) as the default to the call but that would be a performance hit
         $raw = $this->cache->get($this->id, null);
         if (is_null($raw)) {
             $this->data = array();
         } else {
             $data = @unserialize($raw);
             // We test 'b:0' special case, because such a string would result
             // in $data being === false, while raw is serialized
             // see http://stackoverflow.com/questions/1369936/check-to-see-if-a-string-is-serialized
             if ($raw === 'b:0;' || $data !== false) {
                 $this->data = $data;
             } else {
                 // Probably an old cached value (BC)
                 $this->data = $raw;
             }
         }
         if (sfConfig::get('sf_logging_enabled')) {
             $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Restored previous session')));
         }
     }
     session_id($this->id);
     $this->response->addCacheControlHttpHeader('private');
     return true;
 }
开发者ID:mmonguilod,项目名称:symfony1,代码行数:86,代码来源:sfCacheSessionStorage.class.php


注:本文中的sfStorage::initialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。