Development

Changeset 7970

You must first sign up to be able to contribute.

Changeset 7970

Show
Ignore:
Timestamp:
03/19/08 13:37:29 (1 year ago)
Author:
fabien
Message:

moved internal storage of user parameters to an array + added php doc for all available options

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/user/sfBasicSecurityUser.class.php

    r7792 r7970  
    6363        if ($credential == $value) 
    6464        { 
    65           if ($this->getParameter('logging')
     65          if ($this->options['logging']
    6666          { 
    6767            $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Remove credential "%s"', $credential)))); 
     
    9797    $credentials = (is_array(func_get_arg(0))) ? func_get_arg(0) : func_get_args(); 
    9898 
    99     if ($this->getParameter('logging')
     99    if ($this->options['logging']
    100100    { 
    101101      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Add credential(s) "%s"', implode(', ', $credentials))))); 
     
    172172  public function setAuthenticated($authenticated) 
    173173  { 
    174     if ($this->getParameter('logging')
     174    if ($this->options['logging']
    175175    { 
    176176      $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('User is %sauthenticated', $authenticated === true ? '' : 'not ')))); 
     
    209209 
    210210  /** 
    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()) 
    222219  { 
    223220    // 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    } 
    225227 
    226228    // read data from storage 
     
    237239    { 
    238240      // Automatic logout logged in user if no request within timeout parameter seconds 
    239       $timeout = $this->getParameter('timeout', 1800)
     241      $timeout = $this->options['timeout']
    240242      if (false !== $timeout && !is_null($this->lastRequest) && time() - $this->lastRequest >= $timeout) 
    241243      { 
    242         if ($this->getParameter('logging')
     244        if ($this->options['logging']
    243245        { 
    244246          $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  
    3333 
    3434  protected 
    35     $parameterHolder = null
     35    $options         = array()
    3636    $attributeHolder = null, 
    3737    $culture         = null, 
     
    4444   * @see initialize() 
    4545   */ 
    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']
    5151    { 
    5252      register_shutdown_function(array($this, 'shutdown')); 
     
    5757   * Initializes this sfUser. 
    5858   * 
     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   * 
    5967   * @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()) 
    6874  { 
    6975    $this->dispatcher = $dispatcher; 
    7076    $this->storage    = $storage; 
    7177 
    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); 
    7485 
    7586    $this->attributeHolder = new sfNamespacedParameterHolder(self::ATTRIBUTE_NAMESPACE); 
     
    90101    //  - use the default culture set in settings.yml 
    91102    $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'])); 
    93104 
    94105    // 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']
    98109      { 
    99110        $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Flag old flash messages ("%s")', implode('", "', $names))))); 
     
    131142  public function setFlash($name, $value, $persist = true) 
    132143  { 
    133     if (!$this->getParameter('use_flash', false)
     144    if (!$this->options['use_flash']
    134145    { 
    135146      return; 
     
    158169  public function getFlash($name, $default = null) 
    159170  { 
    160     if (!$this->getParameter('use_flash', false)
     171    if (!$this->options['use_flash']
    161172    { 
    162173      return $default; 
     
    175186  public function hasFlash($name) 
    176187  { 
    177     if (!$this->getParameter('use_flash', false)
     188    if (!$this->options['use_flash']
    178189    { 
    179190      return false; 
     
    193204  } 
    194205 
    195   public function getParameterHolder() 
    196   { 
    197     return $this->parameterHolder; 
    198   } 
    199  
    200206  public function getAttributeHolder() 
    201207  { 
     
    218224  } 
    219225 
    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  
    235226  /** 
    236227   * Executes the shutdown procedure. 
     
    241232  { 
    242233    // 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']
    246237      { 
    247238        $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Remove old flash messages ("%s")', implode('", "', $names))))); 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting, and supporting several large Open-Source projects.