Changeset 4934
- Timestamp:
- 08/30/07 10:24:10 (2 years ago)
- Files:
-
- trunk/data/config/filters.yml (modified) (1 diff)
- trunk/data/generator/sfPropelAdmin/default/template/actions/actions.class.php (modified) (1 diff)
- trunk/data/generator/sfPropelAdmin/default/template/templates/_edit_messages.php (modified) (1 diff)
- trunk/data/skeleton/app/app/config/filters.yml (modified) (1 diff)
- trunk/lib/action/sfComponent.class.php (modified) (1 diff)
- trunk/lib/config/sfFactoryConfigHandler.class.php (modified) (1 diff)
- trunk/lib/filter/sfFlashFilter.class.php (deleted)
- trunk/lib/user/sfUser.class.php (modified) (4 diffs)
- trunk/lib/view/sfViewParameterHolder.class.php (modified) (2 diffs)
- trunk/test/functional/fixtures/project/apps/backend/config/filters.yml (modified) (1 diff)
- trunk/test/functional/fixtures/project/apps/cache/config/filters.yml (modified) (1 diff)
- trunk/test/functional/fixtures/project/apps/crud/config/filters.yml (modified) (1 diff)
- trunk/test/functional/fixtures/project/apps/frontend/config/filters.yml (modified) (1 diff)
- trunk/test/functional/fixtures/project/apps/frontend/modules/configFiltersSimpleFilter/config/filters.yml (modified) (1 diff)
- trunk/test/functional/fixtures/project/apps/i18n/config/filters.yml (modified) (1 diff)
- trunk/test/functional/fixtures/project/config/filters.yml (modified) (1 diff)
- trunk/test/functional/fixtures/project/plugins/sfConfigPlugin/config/filters.yml (modified) (1 diff)
- trunk/test/unit/filter/sfFlashFilterTest.php (deleted)
- trunk/test/unit/user/sfUserTest.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/data/config/filters.yml
r2661 r4934 27 27 class: sfCommonFilter 28 28 29 flash:30 class: sfFlashFilter31 param:32 condition: %SF_USE_FLASH%33 34 29 # execution filter must be the last registered filter 35 30 execution: trunk/data/generator/sfPropelAdmin/default/template/actions/actions.class.php
r4334 r4934 63 63 $this->save<?php echo $this->getClassName() ?>($this-><?php echo $this->getSingularName() ?>); 64 64 65 $this-> setFlash('notice', 'Your modifications have been saved');65 $this->getUser()->setFlash('notice', 'Your modifications have been saved'); 66 66 67 67 if ($this->getRequestParameter('save_and_add')) trunk/data/generator/sfPropelAdmin/default/template/templates/_edit_messages.php
r4895 r4934 9 9 </dl> 10 10 </div> 11 [?php elseif ($sf_ flash->has('notice')): ?]11 [?php elseif ($sf_user->hasFlash('notice')): ?] 12 12 <div class="save-ok"> 13 <h2>[?php echo __($sf_ flash->get('notice')) ?]</h2>13 <h2>[?php echo __($sf_user->getFlash('notice')) ?]</h2> 14 14 </div> 15 15 [?php endif; ?] trunk/data/skeleton/app/app/config/filters.yml
r4406 r4934 13 13 cache: ~ 14 14 common: ~ 15 flash: ~16 15 execution: ~ trunk/lib/action/sfComponent.class.php
r4850 r4934 318 318 319 319 /** 320 * Sets a flash variable that will be passed to the very next action.321 *322 * @param string The name of the flash variable323 * @param string The value of the flash variable324 * @param boolean true if the flash have to persist for the following request (true by default)325 */326 public function setFlash($name, $value, $persist = true)327 {328 $this->getUser()->setAttribute($name, $value, 'symfony/flash');329 330 if ($persist)331 {332 // clear removal flag333 $this->getUser()->getAttributeHolder()->remove($name, 'symfony/flash/remove');334 }335 else336 {337 $this->getUser()->setAttribute($name, true, 'symfony/flash/remove');338 }339 }340 341 /**342 * Gets a flash variable.343 *344 * @param string The name of the flash variable345 *346 * @return mixed The value of the flash variable347 */348 public function getFlash($name)349 {350 return $this->getUser()->getAttribute($name, null, 'symfony/flash');351 }352 353 /**354 * Returns true if a flash variable of the specified name exists.355 *356 * @param string The name of the flash variable357 *358 * @return boolean true if the variable exists, false otherwise359 */360 public function hasFlash($name)361 {362 return $this->getUser()->hasAttribute($name, 'symfony/flash');363 }364 365 /**366 320 * Sends and email from the current action. 367 321 * trunk/lib/config/sfFactoryConfigHandler.class.php
r4895 r4934 142 142 143 143 // append instance initialization 144 $inits[] = sprintf(" \$this->factories['user']->initialize(\$this, sfConfig::get('sf_factory_user_parameters', %s));", var_export($parameters, true));144 $inits[] = sprintf(" \$this->factories['user']->initialize(\$this, array_merge(array('use_flash' => sfConfig::get('sf_use_flash')), sfConfig::get('sf_factory_user_parameters', %s)));", var_export(is_array($parameters) ? $parameters : array(), true)); 145 145 break; 146 146 trunk/lib/user/sfUser.class.php
r4892 r4934 51 51 * Initialize this User. 52 52 * 53 * @param Context A Context instance. 54 * @param array An associative array of initialization parameters. 55 * 56 * @return bool true, if initialization completes successfully, otherwise 57 * false. 58 * 59 * @throws <b>sfInitializationException</b> If an error occurs while initializing this User. 53 * @param sfContext A sfContext instance. 54 * @param array An associative array of initialization parameters. 55 * 56 * @return Boolean true, if initialization completes successfully, otherwise false. 57 * 58 * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfUser. 60 59 */ 61 60 public function initialize($context, $parameters = array()) … … 91 90 92 91 $this->setCulture($culture); 92 93 // flag current flash to be removed at shutdown 94 if ($this->parameterHolder->get('use_flash', false) && $names = $this->attributeHolder->getNames('symfony/user/sfUser/flash')) 95 { 96 if (sfConfig::get('sf_logging_enabled')) 97 { 98 $this->context->getLogger()->info(sprintf('{sfUser} flag old flash messages ("%s")', implode('", "', $names))); 99 } 100 101 foreach ($names as $name) 102 { 103 $this->attributeHolder->set($name, true, 'symfony/user/sfUser/flash/remove'); 104 } 105 } 93 106 } 94 107 … … 137 150 138 151 /** 152 * Sets a flash variable that will be passed to the very next action. 153 * 154 * @param string The name of the flash variable 155 * @param string The value of the flash variable 156 * @param Boolean true if the flash have to persist for the following request (true by default) 157 */ 158 public function setFlash($name, $value, $persist = true) 159 { 160 if (!$this->parameterHolder->get('use_flash', false)) 161 { 162 return; 163 } 164 165 $this->setAttribute($name, $value, 'symfony/user/sfUser/flash'); 166 167 if ($persist) 168 { 169 // clear removal flag 170 $this->attributeHolder->remove($name, 'symfony/user/sfUser/flash/remove'); 171 } 172 else 173 { 174 $this->setAttribute($name, true, 'symfony/user/sfUser/flash/remove'); 175 } 176 } 177 178 /** 179 * Gets a flash variable. 180 * 181 * @param string The name of the flash variable 182 * 183 * @return mixed The value of the flash variable 184 */ 185 public function getFlash($name, $default = null) 186 { 187 if (!$this->parameterHolder->get('use_flash', false)) 188 { 189 return $default; 190 } 191 192 return $this->getAttribute($name, $default, 'symfony/user/sfUser/flash'); 193 } 194 195 /** 196 * Returns true if a flash variable of the specified name exists. 197 * 198 * @param string The name of the flash variable 199 * 200 * @return Boolean true if the variable exists, false otherwise 201 */ 202 public function hasFlash($name) 203 { 204 if (!$this->parameterHolder->get('use_flash', false)) 205 { 206 return false; 207 } 208 209 return $this->hasAttribute($name, 'symfony/user/sfUser/flash'); 210 } 211 212 /** 139 213 * Gets culture. 140 214 * … … 193 267 public function shutdown() 194 268 { 269 // remove flash that are tagged to be removed 270 if ($this->parameterHolder->get('use_flash', false) && $names = $this->attributeHolder->getNames('symfony/user/sfUser/flash/remove')) 271 { 272 if (sfConfig::get('sf_logging_enabled')) 273 { 274 $this->context->getLogger()->info(sprintf('{sfUser} remove old flash messages ("%s")', implode('", "', $names))); 275 } 276 277 foreach ($names as $name) 278 { 279 $this->attributeHolder->remove($name, 'symfony/user/sfUser/flash'); 280 $this->attributeHolder->remove($name, 'symfony/user/sfUser/flash/remove'); 281 } 282 } 283 195 284 $storage = $this->context->getStorage(); 196 285 trunk/lib/view/sfViewParameterHolder.class.php
r4898 r4934 58 58 protected function getGlobalAttributes() 59 59 { 60 $flash = new sfParameterHolder();61 $flash->add($this->context->getUser()->getAttributeHolder()->getAll('symfony/flash'));62 63 60 $attributes = array( 64 61 'sf_context' => $this->context, … … 67 64 'sf_response' => $this->context->getResponse(), 68 65 'sf_user' => $this->context->getUser(), 69 'sf_flash' => $flash,70 66 ); 71 67 trunk/test/functional/fixtures/project/apps/backend/config/filters.yml
r2661 r4934 8 8 cache: ~ 9 9 common: ~ 10 flash: ~11 10 execution: ~ trunk/test/functional/fixtures/project/apps/cache/config/filters.yml
r2661 r4934 8 8 cache: ~ 9 9 common: ~ 10 flash: ~11 10 execution: ~ trunk/test/functional/fixtures/project/apps/crud/config/filters.yml
r2661 r4934 8 8 cache: ~ 9 9 common: ~ 10 flash: ~11 10 execution: ~ trunk/test/functional/fixtures/project/apps/frontend/config/filters.yml
r2661 r4934 10 10 cache: ~ 11 11 common: ~ 12 flash: ~13 12 execution: ~ trunk/test/functional/fixtures/project/apps/frontend/modules/configFiltersSimpleFilter/config/filters.yml
r2661 r4934 13 13 cache: ~ 14 14 common: ~ 15 flash: ~16 15 execution: ~ trunk/test/functional/fixtures/project/apps/i18n/config/filters.yml
r2740 r4934 7 7 cache: ~ 8 8 common: ~ 9 flash: ~10 9 execution: ~ trunk/test/functional/fixtures/project/config/filters.yml
r2958 r4934 7 7 cache: ~ 8 8 common: ~ 9 flash: ~10 9 execution: ~ trunk/test/functional/fixtures/project/plugins/sfConfigPlugin/config/filters.yml
r3178 r4934 7 7 cache: ~ 8 8 common: ~ 9 flash: ~10 9 execution: ~ trunk/test/unit/user/sfUserTest.php
r4890 r4934 12 12 require_once($_test_dir.'/unit/sfContextMock.class.php'); 13 13 14 $t = new lime_test(3 3, new lime_output_color());14 $t = new lime_test(39, new lime_output_color()); 15 15 16 16 $_SERVER['session_id'] = 'test'; … … 41 41 $userBis = new sfUser(); 42 42 $userBis->initialize($context); 43 $t->is($userBis->getCulture(), 'de', '->in tialize() serializes the culture to the session data');43 $t->is($userBis->getCulture(), 'de', '->initialize() serializes the culture to the session data'); 44 44 45 45 // ->setCulture() ->getCulture() … … 47 47 $user->setCulture('fr'); 48 48 $t->is($user->getCulture(), 'fr', '->setCulture() changes the current user culture'); 49 50 // ->setFlash() ->getFlash() ->hasFlash() 51 $t->diag('->setFlash() ->getFlash() ->hasFlash()'); 52 $user->initialize($context, array('use_flash' => true)); 53 $user->setFlash('foo', 'bar'); 54 $t->is($user->getFlash('foo'), 'bar', '->setFlash() sets a flash variable'); 55 $t->is($user->hasFlash('foo'), true, '->hasFlash() returns true if the flash variable exists'); 56 user_flush($context, array('use_flash' => true)); 57 58 $userBis = new sfUser(); 59 $userBis->initialize($context, array('use_flash' => true)); 60 $t->is($userBis->getFlash('foo'), 'bar', '->getFlash() returns a flash previously set'); 61 $t->is($userBis->hasFlash('foo'), true, '->hasFlash() returns true if the flash variable exists'); 62 user_flush($context, array('use_flash' => true)); 63 64 $userBis = new sfUser(); 65 $userBis->initialize($context, array('use_flash' => true)); 66 $t->is($userBis->getFlash('foo'), null, 'Flashes are automatically removed after the next request'); 67 $t->is($userBis->hasFlash('foo'), false, '->hasFlash() returns true if the flash variable exists'); 49 68 50 69 // parameter holder proxy … … 65 84 $storage->clear(); 66 85 67 function user_flush($context )86 function user_flush($context, $parameters = array()) 68 87 { 69 88 $context->getUser()->shutdown(); 70 $context->getUser()->initialize($context );89 $context->getUser()->initialize($context, $parameters); 71 90 $parameters = $context->getStorage()->getParameterHolder()->getAll(); 72 91 $context->getStorage()->shutdown();

