/** * @return ArrayObject */ public static function getFavorites() { $session = new sfSessionStorage(); if ($session->read('favorites') === null) { $session->initialize(array('session_cookie_lifetime' => 2592000)); $session->write('favorites', new ArrayObject(array())); } return $session->read('favorites'); }
public function initialize($options = null) { if (session_id() != '') { self::$sessionStarted = true; } parent::initialize($options); }
/** * 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), $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']; 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->options['auto_start'] && !self::$sessionStarted) { session_start(); self::$sessionStarted = true; } }
/** * 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) { //@todo: for photo upload make care about secure if ($sessionId = $options['session_id']) { session_id($sessionId); } parent::initialize($options); // print_r($_SESSION); }
public function initialize($options = null) { // http://trac.symfony-project.org/ticket/5683 if (!isset($options['session_cookie_path'])) { $options['session_cookie_path'] = sfContext::getInstance()->request->getRelativeUrlRoot(); if (1 > strlen($options['session_cookie_path'])) { $options['session_cookie_path'] = '/'; } } parent::initialize($options); }
/** * @return null */ public function initialize($options = null) { if (sfJpMobile::isMobile()) { ini_set("session.use_trans_sid", 1); ini_set("session.use_cookies", 0); ini_set("session.use_only_cookies", 0); } else { ini_set("session.use_trans_sid", 0); ini_set("session.use_cookies", 1); } parent::initialize($options); }
public function initialize($options = null) { $request = sfContext::getInstance()->getRequest(); // work-around for uploadify if ($request->getParameter('uploadify') == "onUpload") { $sessionName = $options["session_name"]; if ($value = $request->getParameter($sessionName)) { session_name($sessionName); session_id($value); } } parent::initialize($options); }
public function initialize($options = null) { $context = sfContext::getInstance(); $sessionName = $options["session_name"]; if ($value = $context->getRequest()->getParameter($sessionName)) { session_name($sessionName); session_id($value); } if (isset($options['session_cookie_domain']) && '.' == $options['session_cookie_domain']) { preg_match('/([^.]+\\.[^.]+)$/', $_SERVER['SERVER_NAME'], $matches); $options['session_cookie_domain'] = '.' . $matches[1]; } parent::initialize($options); }
public function initialize($options = null) { if ($this->transSidFor(sfContext::getInstance()->getRequest())) { $sessionName = isset($options['session_name']) ? $options['session_name'] : 'symfony'; if ($value = sfContext::getInstance()->getRequest()->getParameter($sessionName)) { if (sfConfig::get('sf_logging_enabled')) { sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent($this, 'application.log', array(sprintf('Changing session name "%s" to "%s"', $sessionName, $value)))); } session_name($sessionName); session_id($value); } } parent::initialize($options); }
public function initialize($parameters = null) { //Shitty work-around for swfuploader $context = sfContext::getInstance(); $request = sfContext::getInstance()->getRequest(); if ($request->getParameter('action') == "swfupload") { $sessionName = $parameters["session_name"]; if ($value = $context->getRequest()->getParameter($sessionName)) { session_name($sessionName); session_id($value); } } parent::initialize($parameters); }
/** * 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>InitializationException</b> If an error occurs while initializing this Storage */ public function initialize($context, $parameters = null) { // disable auto_start $parameters['auto_start'] = false; // initialize the parent parent::initialize($context, $parameters); if (!$this->getParameterHolder()->has('db_table')) { // missing required 'db_table' parameter $error = 'Factory configuration file is missing required "db_table" parameter for the Storage category'; throw new sfInitializationException($error); } // use this object as the session handler session_set_save_handler(array($this, 'sessionOpen'), array($this, 'sessionClose'), array($this, 'sessionRead'), array($this, 'sessionWrite'), array($this, 'sessionDestroy'), array($this, 'sessionGC')); // start our session session_start(); }
public function initialize($options = null) { $auto_start = !is_array($options) || !array_key_exists('auto_start', $options) || $options['auto_start'] != false; $session_name = is_array($options) && array_key_exists('session_name', $options) ? $options['session_name'] : 'symfony'; $delay_auto_start = false; if ($auto_start && empty($_COOKIE[$session_name])) { if (!is_array($options)) { $options = array(); } $options['auto_start'] = false; $delay_auto_start = true; } parent::initialize($options); if ($delay_auto_start) { $this->options['auto_start'] = true; } }
/** * Available options: * * * db_table: The database table in which session data will be stored * * database: The sfDatabase object to use * * db_id_col: The database column in which the session id will be stored (sess_id by default) * * db_data_col: The database column in which the session data will be stored (sess_data by default) * * db_time_col: The database column in which the session timestamp will be stored (sess_time by default) * * @param array $options An associative array of options * * @see sfSessionStorage */ public function initialize($options = array()) { $options = array_merge(array('db_id_col' => 'sess_id', 'db_data_col' => 'sess_data', 'db_time_col' => 'sess_time'), $options); // disable auto_start $options['auto_start'] = false; // initialize the parent parent::initialize($options); if (!isset($this->options['db_table'])) { throw new sfInitializationException('You must provide a "db_table" option to sfDatabaseSessionStorage.'); } if (!isset($this->options['database'])) { throw new sfInitializationException('You must provide a "database" option to sfDatabaseSessionStorage.'); } // use this object as the session handler session_set_save_handler(array($this, 'sessionOpen'), array($this, 'sessionClose'), array($this, 'sessionRead'), array($this, 'sessionWrite'), array($this, 'sessionDestroy'), array($this, 'sessionGC')); // start our session session_start(); }
public function initialize($context, $parameters = null) { parent::initialize($context, $parameters); // UserAgent取得 $agent = new Net_UserAgent_Mobile(); //$agent = $this->getContext()->getRequest()->getAttribute('userAgent'); if ($agent->isDoCoMo()) { ini_set("session.use_trans_sid", 1); ini_set("session.use_cookies", 0); } else { if ($agent->isSoftBank()) { ini_set("session.use_trans_sid", 0); ini_set("session.use_cookies", 1); } else { if ($agent->isEZweb()) { ini_set("session.use_trans_sid", 0); ini_set("session.use_cookies", 1); } } } }
public function regenerate($destroy = false) { if (self::$sessionIdRegenerated) { return; } session_regenerate_id($destroy); self::$sessionIdRegenerated = true; }
/** * Executes the shutdown procedure. * */ public function shutdown() { parent::shutdown(); }
*/ $app = 'frontend'; require_once dirname(__FILE__) . '/../../bootstrap/functional.php'; ob_start(); $_test_dir = realpath(dirname(__FILE__) . '/../../'); require_once $_test_dir . '/../lib/vendor/lime/lime.php'; sfConfig::set('sf_symfony_lib_dir', realpath($_test_dir . '/../lib')); $t = new lime_test(8, new lime_output_color()); // initialize the storage try { $storage = new sfSessionStorage(); $t->pass('->__construct() does not throw an exception when not provided with options'); } catch (InvalidArgumentException $e) { $t->fail('->__construct() Startup failure'); } $storage = new sfSessionStorage(); $t->ok($storage instanceof sfStorage, '->__construct() is an instance of sfStorage'); $storage->write('test', 123); $t->is($storage->read('test'), 123, '->read() can read data that has been written to storage'); // regenerate() $oldSessionData = 'foo:bar'; $key = md5($oldSessionData); $storage->write($key, $oldSessionData); $session_id = session_id(); $storage->regenerate(false); $t->is($storage->read($key), $oldSessionData, '->regenerate(false) regenerated the session with a different session id - this class by default doesn\'t regen the id'); $t->isnt(session_id(), $session_id, '->regenerate(false) regenerated the session with a different session id'); $storage->regenerate(true); $t->is($storage->read($key), $oldSessionData, '->regenerate(true) regenerated the session with a different session id and destroyed data'); $t->isnt(session_id(), $session_id, '->regenerate(true) regenerated the session with a different session id'); $storage->remove($key);
/** * Regenerates id that represents this storage. * * @param boolean $destroy Destroy session when regenerating? * * @return boolean True if session regenerated, false if error * */ public function regenerate($destroy = false) { if (self::$sessionIdRegenerated) { return; } // regenerate a new session id once per object session_regenerate_id($destroy); self::$sessionIdRegenerated = true; }
/** * Regenerates id that represents this storage. * * @param boolean $destroy Destroy session when regenerating? * * @return boolean True if session regenerated, false if error * */ public function regenerate($destroy = false) { if (self::$sessionIdRegenerated) { return; } $currentId = session_id(); parent::regenerate($destroy); $newId = session_id(); $this->sessionRead($newId); return $this->sessionWrite($newId, $this->sessionRead($currentId)); }
/** * Invoke an action given its name * * This function requests information necessary to operate on * VSES017 AIS application * * @param Trace $trace trace object * @param string $action action name * @param Request $request incoming request */ public function invokeAction(Trace $trace, $action, Request $request) { Preconditions::checkIsString($action); if (!$this->loginManager->isLoggedIn()) { throw new AuthenticationRequiredException(); } Preconditions::checkNotNull($request); // check access to application $apps = $this->session->read('ais/aisApps'); if (!is_array($apps)) { throw new Exception("Interná chyba - zoznam AIS aplikácii je nekorektný."); } if (!in_array(AIS2ApplicationEnum::ADMINISTRACIA_STUDIA, $apps)) { return $this->renderResponse('studium/notAvailable'); } $screenFactory = $this->factory; $adminStudia = $screenFactory->newAdministraciaStudiaScreen($trace); $this->administraciaStudiaScreen = $adminStudia; $this->studium = $request->getParameter('studium', '0'); $this->zoznamStudii = $adminStudia->getZoznamStudii($trace->addChild("Get Zoznam Studii:")); $this->zapisneListy = $adminStudia->getZapisneListy($trace->addChild('getZapisneListy'), $this->studium); $this->warnings->warnWrongTableStructure($trace, 'zoznam studii', regression\ZoznamStudiiRegression::get(), $this->zoznamStudii->getTableDefinition()); $this->warnings->warnWrongTableStructure($trace, 'zoznam zapisnych listov', regression\ZoznamZapisnychListovRegression::get(), $this->zapisneListy->getTableDefinition()); $zapisneListyData = $this->zapisneListy->getData(); if (count($zapisneListyData) == 0) { $this->zapisnyList = null; $this->terminyHodnoteniaScreen = null; $this->hodnoteniaScreen = null; $this->templateParams['zapisnyListObj'] = null; } else { $this->zapisnyList = $request->getParameter('list'); if ($this->zapisnyList === '') { // Ak nemame nastaveny zapisny list, zobreme aktualny // ak nenajdeme aktualny, zoberme posledny v zozname $aktualnyAkadRok = FajrUtils::getAcademicYear(); $this->zapisnyList = null; foreach ($zapisneListyData as $zapList) { if ($zapList['popisAkadRok'] == $aktualnyAkadRok) { $this->zapisnyList = $zapList['index']; } } // nenasli sme if ($this->zapisnyList === null) { $lastList = end($zapisneListyData); $this->zapisnyList = $lastList['index']; } } $this->zapisnyList = intval($this->zapisnyList); $this->zapisnyListObj = $zapisneListyData[$this->zapisnyList]; $this->templateParams['zapisnyListObj'] = $this->zapisnyListObj; try { $this->terminyHodnoteniaScreen = $screenFactory->newTerminyHodnoteniaScreen($trace, $adminStudia->getParamNameFromZapisnyListIndex($trace, $this->zapisnyList, VSES017\AdministraciaStudiaScreen::ACTION_TERMINY_HODNOTENIA)); } catch (ParseException $e) { $this->terminyHodnoteniaScreen = null; } // FIXME: chceme to nejak refaktorovat, aby sme nevytvarali zbytocne // objekty, ktore v konstruktore robia requesty $this->hodnoteniaScreen = $screenFactory->newHodnoteniaPriemeryScreen($trace, $adminStudia->getParamNameFromZapisnyListIndex($trace, $this->zapisnyList, VSES017\AdministraciaStudiaScreen::ACTION_HODNOTENIA_PRIEMERY)); } $this->templateParams['currentTab'] = ''; $this->templateParams['zoznamStudii'] = $this->zoznamStudii; $this->templateParams['studium'] = $this->studium; // TODO(anty): refactor $zoznamStudiiData = $this->zoznamStudii->getData(); $this->templateParams['studiumObj'] = $zoznamStudiiData[$this->studium]; $this->templateParams['zapisneListy'] = $this->zapisneListy; $this->templateParams['zapisnyList'] = $this->zapisnyList; // TODO(anty): refactor if (array_key_exists($action, $this->actionInfo)) { $info = $this->actionInfo[$action]; if ($info['requiresZapisnyList'] && $this->zapisnyList === null) { $this->templateParams['activeTab'] = $info['tabName']; return $this->renderResponse('studium/chybaZapisnyList', $this->templateParams); } } $result = parent::invokeAction($trace, $action, $request); if ($this->terminyHodnoteniaScreen) { $this->terminyHodnoteniaScreen->closeWindow(); } if ($this->hodnoteniaScreen) { $this->hodnoteniaScreen->closeWindow(); } if ($this->administraciaStudiaScreen) { $this->administraciaStudiaScreen->closeWindow(); } return $result; }