Changeset 7970
- Timestamp:
- 03/19/08 13:37:29 (1 year ago)
- Files:
-
- branches/1.1/lib/user/sfBasicSecurityUser.class.php (modified) (5 diffs)
- branches/1.1/lib/user/sfUser.class.php (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/user/sfBasicSecurityUser.class.php
r7792 r7970 63 63 if ($credential == $value) 64 64 { 65 if ($this-> getParameter('logging'))65 if ($this->options['logging']) 66 66 { 67 67 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Remove credential "%s"', $credential)))); … … 97 97 $credentials = (is_array(func_get_arg(0))) ? func_get_arg(0) : func_get_args(); 98 98 99 if ($this-> getParameter('logging'))99 if ($this->options['logging']) 100 100 { 101 101 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Add credential(s) "%s"', implode(', ', $credentials))))); … … 172 172 public function setAuthenticated($authenticated) 173 173 { 174 if ($this-> getParameter('logging'))174 if ($this->options['logging']) 175 175 { 176 176 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('User is %sauthenticated', $authenticated === true ? '' : 'not ')))); … … 209 209 210 210 /** 211 * Initializes this sfUser. 212 * 213 * @param sfEventDispatcher A sfEventDispatcher instance. 214 * @param sfStorage A sfStorage instance. 215 * @param array An associative array of initialization parameters. 216 * 217 * @return Boolean true, if initialization completes successfully, otherwise false. 218 * 219 * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfUser. 220 */ 221 public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $parameters = array()) 211 * Available options: 212 * 213 * * timeout: Timeout to automatically log out the user in seconds (1800 by default) 214 * Set to false to disable 215 * 216 * @see sfUser 217 */ 218 public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array()) 222 219 { 223 220 // initialize parent 224 parent::initialize($dispatcher, $storage, $parameters); 221 parent::initialize($dispatcher, $storage, $options); 222 223 if (!array_key_exists('timeout', $this->options)) 224 { 225 $this->options['timeout'] = 1800; 226 } 225 227 226 228 // read data from storage … … 237 239 { 238 240 // Automatic logout logged in user if no request within timeout parameter seconds 239 $timeout = $this-> getParameter('timeout', 1800);241 $timeout = $this->options['timeout']; 240 242 if (false !== $timeout && !is_null($this->lastRequest) && time() - $this->lastRequest >= $timeout) 241 243 { 242 if ($this-> getParameter('logging'))244 if ($this->options['logging']) 243 245 { 244 246 $this->dispatcher->notify(new sfEvent($this, 'application.log', array('Automatic user logout due to timeout'))); branches/1.1/lib/user/sfUser.class.php
r7792 r7970 33 33 34 34 protected 35 $ parameterHolder = null,35 $options = array(), 36 36 $attributeHolder = null, 37 37 $culture = null, … … 44 44 * @see initialize() 45 45 */ 46 public function __construct(sfEventDispatcher $dispatcher, sfStorage $storage, $ parameters = array())47 { 48 $this->initialize($dispatcher, $storage, $ parameters);49 50 if ($this-> getParameter('auto_shutdown', true))46 public function __construct(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array()) 47 { 48 $this->initialize($dispatcher, $storage, $options); 49 50 if ($this->options['auto_shutdown']) 51 51 { 52 52 register_shutdown_function(array($this, 'shutdown')); … … 57 57 * Initializes this sfUser. 58 58 * 59 * Available options: 60 * 61 * * auto_shutdown: Whether to automatically save the changes to the session (true by default) 62 * * culture: The user culture 63 * * default_culture: The default user culture (en by default) 64 * * use_flash: Whether to enable flash usage (false by default) 65 * * logging: Whether to enable logging (false by default) 66 * 59 67 * @param sfEventDispatcher A sfEventDispatcher instance. 60 * @param sfStorage A sfStorage instance. 61 * @param array An associative array of initialization parameters. 62 * 63 * @return Boolean true, if initialization completes successfully, otherwise false. 64 * 65 * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfUser. 66 */ 67 public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $parameters = array()) 68 * @param sfStorage A sfStorage instance. 69 * @param array An associative array of options. 70 * 71 * @return Boolean true, if initialization completes successfully, otherwise false. 72 */ 73 public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array()) 68 74 { 69 75 $this->dispatcher = $dispatcher; 70 76 $this->storage = $storage; 71 77 72 $this->parameterHolder = new sfParameterHolder(); 73 $this->parameterHolder->add($parameters); 78 $this->options = array_merge(array( 79 'auto_shutdown' => true, 80 'culture' => null, 81 'default_culture' => 'en', 82 'use_flash' => false, 83 'logging' => false, 84 ), $options); 74 85 75 86 $this->attributeHolder = new sfNamespacedParameterHolder(self::ATTRIBUTE_NAMESPACE); … … 90 101 // - use the default culture set in settings.yml 91 102 $currentCulture = $storage->read(self::CULTURE_NAMESPACE); 92 $this->setCulture( $this->getParameter('culture', !is_null($currentCulture) ? $currentCulture : $this->getParameter('default_culture', 'en')));103 $this->setCulture(!is_null($this->options['culture']) ? $this->options['culture'] : (!is_null($currentCulture) ? $currentCulture : $this->options['default_culture'])); 93 104 94 105 // flag current flash to be removed at shutdown 95 if ($this-> getParameter('use_flash', false)&& $names = $this->attributeHolder->getNames('symfony/user/sfUser/flash'))96 { 97 if ($this-> getParameter('logging'))106 if ($this->options['use_flash'] && $names = $this->attributeHolder->getNames('symfony/user/sfUser/flash')) 107 { 108 if ($this->options['logging']) 98 109 { 99 110 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Flag old flash messages ("%s")', implode('", "', $names))))); … … 131 142 public function setFlash($name, $value, $persist = true) 132 143 { 133 if (!$this-> getParameter('use_flash', false))144 if (!$this->options['use_flash']) 134 145 { 135 146 return; … … 158 169 public function getFlash($name, $default = null) 159 170 { 160 if (!$this-> getParameter('use_flash', false))171 if (!$this->options['use_flash']) 161 172 { 162 173 return $default; … … 175 186 public function hasFlash($name) 176 187 { 177 if (!$this-> getParameter('use_flash', false))188 if (!$this->options['use_flash']) 178 189 { 179 190 return false; … … 193 204 } 194 205 195 public function getParameterHolder()196 {197 return $this->parameterHolder;198 }199 200 206 public function getAttributeHolder() 201 207 { … … 218 224 } 219 225 220 public function getParameter($name, $default = null)221 {222 return $this->parameterHolder->get($name, $default);223 }224 225 public function hasParameter($name)226 {227 return $this->parameterHolder->has($name);228 }229 230 public function setParameter($name, $value)231 {232 return $this->parameterHolder->set($name, $value);233 }234 235 226 /** 236 227 * Executes the shutdown procedure. … … 241 232 { 242 233 // remove flash that are tagged to be removed 243 if ($this-> getParameter('use_flash', false)&& $names = $this->attributeHolder->getNames('symfony/user/sfUser/flash/remove'))244 { 245 if ($this-> getParameter('logging'))234 if ($this->options['use_flash'] && $names = $this->attributeHolder->getNames('symfony/user/sfUser/flash/remove')) 235 { 236 if ($this->options['logging']) 246 237 { 247 238 $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Remove old flash messages ("%s")', implode('", "', $names)))));

