Changeset 4898
- Timestamp:
- 08/25/07 16:03:57 (2 years ago)
- Files:
-
- trunk/lib/util/sfParameterHolder.class.php (modified) (2 diffs)
- trunk/lib/view/sfEscapedViewParameterHolder.class.php (modified) (4 diffs)
- trunk/lib/view/sfView.class.php (modified) (1 diff)
- trunk/lib/view/sfViewParameterHolder.class.php (modified) (4 diffs)
- trunk/test/unit/view/sfEscapedViewParameterHolderTest.php (added)
- trunk/test/unit/view/sfViewParameterHolderTest.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/util/sfParameterHolder.class.php
r4645 r4898 247 247 * @return string A parameter value, if the parameter was removed, otherwise null. 248 248 */ 249 public function &remove($name, $ns = null)249 public function remove($name, $ns = null) 250 250 { 251 251 if (!$ns) … … 256 256 $retval = null; 257 257 258 if (isset($this->parameters[$ns]) && isset($this->parameters[$ns][$name]))259 { 260 $retval = &$this->parameters[$ns][$name];258 if (isset($this->parameters[$ns]) && array_key_exists($name, $this->parameters[$ns])) 259 { 260 $retval = $this->parameters[$ns][$name]; 261 261 unset($this->parameters[$ns][$name]); 262 262 } trunk/lib/view/sfEscapedViewParameterHolder.class.php
r4562 r4898 10 10 11 11 /** 12 * AsfEscapedViewParameterHolder stores all variables that will be available to the template.12 * sfEscapedViewParameterHolder stores all variables that will be available to the template. 13 13 * 14 * It also escape allvariables with an escaping method.14 * It also escapes variables with an escaping method. 15 15 * 16 16 * @package symfony … … 28 28 * Initializes this view parameter holder. 29 29 * 30 * @param sfContext A sfContext instance. 31 * @param array An associative array of initialization parameters. 30 * @param sfContext A sfContext instance. 31 * @param array An associative array of initialization parameters. 32 * @param array An associative array of options. 32 33 * 33 * @return bool true, if initialization completes successfully, otherwise false. 34 * <b>Options:</b> 35 * 36 * # <b>escaping_strategy</b> - [bc] - The escaping strategy (bc, both, on or off) 37 * # <b>escaping_method</b> - [ESC_ENTITIES] - The escaping method (ESC_RAW, ESC_ENTITIES, ESC_JS or ESC_JS_NO_ENTITIES) 38 * 39 * @return Boolean true, if initialization completes successfully, otherwise false. 34 40 * 35 41 * @throws <b>sfInitializationException</b> If an error occurs while initializing this view parameter holder. 36 42 */ 37 public function initialize($context, $parameters = array() )43 public function initialize($context, $parameters = array(), $options = array()) 38 44 { 39 parent::initialize($context, $parameters );45 parent::initialize($context, $parameters, $options); 40 46 41 $this->setEscaping( sfConfig::get('sf_escaping_strategy'));42 $this->setEscapingMethod( sfConfig::get('sf_escaping_method'));47 $this->setEscaping(isset($options['escaping_strategy']) ? $options['escaping_strategy'] : 'bc'); 48 $this->setEscapingMethod(isset($options['escaping_method']) ? $options['escaping_method'] : 'ESC_ENTITIES'); 43 49 } 44 50 51 /** 52 * Returns an array representation of the view parameters. 53 * 54 * @return array An array of view parameters 55 */ 45 56 public function toArray() 46 57 { … … 110 121 if (!defined($this->escapingMethod)) 111 122 { 112 throw new sfConfigurationException(sprintf(' Escaping method "%s" is not available; perhaps another helper needs to be loaded in?', $this->escapingMethod));123 throw new sfConfigurationException(sprintf('The escaping method "%s" is not available.', $this->escapingMethod)); 113 124 } 114 125 … … 125 136 $this->escapingMethod = $method; 126 137 } 138 139 /** 140 * Serializes the current instance. 141 * 142 * @return array Objects instance 143 */ 144 public function serialize() 145 { 146 $this->set('_sf_escaping_method', $this->escapingMethod); 147 $this->set('_sf_escaping', $this->escaping); 148 149 $serialized = parent::serialize(); 150 151 $this->remove('_sf_escaping_method'); 152 $this->remove('_sf_escaping'); 153 154 return $serialized; 155 } 156 157 /** 158 * Unserializes a sfViewParameterHolder instance. 159 */ 160 public function unserialize($serialized) 161 { 162 parent::unserialize($serialized); 163 164 $this->setEscapingMethod($this->remove('_sf_escaping_method')); 165 $this->setEscaping($this->remove('_sf_escaping')); 166 } 127 167 } trunk/lib/view/sfView.class.php
r4597 r4898 177 177 178 178 $this->attributeHolder = false === sfConfig::get('sf_escaping_method') ? new sfViewParameterHolder() : new sfEscapedViewParameterHolder(); 179 $this->attributeHolder->initialize($context );179 $this->attributeHolder->initialize($context, array('escaping_method' => sfConfig::get('sf_escaping_method'), 'escaping_strategy' => sfConfig::get('sf_escaping_strategy'))); 180 180 181 181 $this->parameterHolder = new sfParameterHolder(); trunk/lib/view/sfViewParameterHolder.class.php
r4562 r4898 27 27 * @param sfContext A sfContext instance. 28 28 * @param array An associative array of initialization parameters. 29 * @param array An associative array of options. 29 30 * 30 * @return booltrue, if initialization completes successfully, otherwise false.31 * @return Boolean true, if initialization completes successfully, otherwise false. 31 32 * 32 33 * @throws <b>sfInitializationException</b> If an error occurs while initializing this view parameter holder. 33 34 */ 34 public function initialize($context, $parameters = array() )35 public function initialize($context, $parameters = array(), $options = array()) 35 36 { 36 37 $this->context = $context; … … 40 41 } 41 42 43 /** 44 * Returns an array representation of the view parameters. 45 * 46 * @return array An array of view parameters 47 */ 42 48 public function toArray() 43 49 { … … 52 58 protected function getGlobalAttributes() 53 59 { 60 $flash = new sfParameterHolder(); 61 $flash->add($this->context->getUser()->getAttributeHolder()->getAll('symfony/flash')); 62 54 63 $attributes = array( 55 64 'sf_context' => $this->context, … … 58 67 'sf_response' => $this->context->getResponse(), 59 68 'sf_user' => $this->context->getUser(), 69 'sf_flash' => $flash, 60 70 ); 61 62 if (sfConfig::get('sf_use_flash'))63 {64 $sf_flash = new sfParameterHolder();65 $sf_flash->add($this->context->getUser()->getAttributeHolder()->getAll('symfony/flash'));66 $attributes['sf_flash'] = $sf_flash;67 }68 71 69 72 return $attributes;

