Пример #1
0
 /**
  * Initializes this sfUser.
  *
  * Available options:
  *
  *  * auto_shutdown:   Whether to automatically save the changes to the session (true by default)
  *  * culture:         The user culture
  *  * default_culture: The default user culture (en by default)
  *  * use_flash:       Whether to enable flash usage (false by default)
  *  * logging:         Whether to enable logging (false by default)
  *
  * @param sfEventDispatcher $dispatcher  An sfEventDispatcher instance.
  * @param sfStorage         $storage     An sfStorage instance.
  * @param array             $options     An associative array of options.
  *
  * @return Boolean          true, if initialization completes successfully, otherwise false.
  */
 public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array())
 {
     $this->dispatcher = $dispatcher;
     $this->storage = $storage;
     $this->options = array_merge(array('auto_shutdown' => true, 'culture' => null, 'default_culture' => 'en', 'use_flash' => false, 'logging' => false), $options);
     $this->attributeHolder = new sfNamespacedParameterHolder(self::ATTRIBUTE_NAMESPACE);
     // read attributes from storage
     $attributes = $storage->read(self::ATTRIBUTE_NAMESPACE);
     if (is_array($attributes)) {
         foreach ($attributes as $namespace => $values) {
             $this->attributeHolder->add($values, $namespace);
         }
     }
     // set the user culture to sf_culture parameter if present in the request
     // otherwise
     //  - use the culture defined in the user session
     //  - use the default culture set in settings.yml
     $currentCulture = $storage->read(self::CULTURE_NAMESPACE);
     $this->setCulture(null !== $this->options['culture'] ? $this->options['culture'] : (null !== $currentCulture ? $currentCulture : $this->options['default_culture']));
     // flag current flash to be removed at shutdown
     if ($this->options['use_flash'] && ($names = $this->attributeHolder->getNames('symfony/user/sfUser/flash'))) {
         if ($this->options['logging']) {
             $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Flag old flash messages ("%s")', implode('", "', $names)))));
         }
         foreach ($names as $name) {
             $this->attributeHolder->set($name, true, 'symfony/user/sfUser/flash/remove');
         }
     }
 }
 public function initialize(sfEventDispatcher $dispatcher, sfStorage $storage, $options = array())
 {
     $this->dispatcher = $dispatcher;
     $this->storage = $storage;
     $this->options = array_merge(array('auto_shutdown' => true, 'culture' => null, 'default_culture' => 'en', 'use_flash' => false, 'logging' => false), $options);
     $this->attributeHolder = new sfNamespacedParameterHolder(self::ATTRIBUTE_NAMESPACE);
     $attributes = $storage->read(self::ATTRIBUTE_NAMESPACE);
     if (is_array($attributes)) {
         foreach ($attributes as $namespace => $values) {
             $this->attributeHolder->add($values, $namespace);
         }
     }
     $currentCulture = $storage->read(self::CULTURE_NAMESPACE);
     $this->setCulture(!is_null($this->options['culture']) ? $this->options['culture'] : (!is_null($currentCulture) ? $currentCulture : $this->options['default_culture']));
     if ($this->options['use_flash'] && ($names = $this->attributeHolder->getNames('symfony/user/sfUser/flash'))) {
         if ($this->options['logging']) {
             $this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Flag old flash messages ("%s")', implode('", "', $names)))));
         }
         foreach ($names as $name) {
             $this->attributeHolder->set($name, true, 'symfony/user/sfUser/flash/remove');
         }
     }
 }