Changeset 32698
- Timestamp:
- 07/01/11 08:55:58 (2 years ago)
- Files:
-
- branches/1.4/CHANGELOG (modified) (1 diff)
- branches/1.4/lib/view/sfViewCacheManager.class.php (modified) (6 diffs)
- branches/1.4/test/unit/validator/sfValidatorDecoratorTest.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.4/CHANGELOG
r32407 r32698 1 07/01/11: Version 1.4.12 2 ------------------------ 3 4 1 5 03/30/11: Version 1.4.11 2 6 ------------------------ branches/1.4/lib/view/sfViewCacheManager.class.php
r30031 r32698 130 130 } 131 131 132 if (strpos($internalUri, '@') === 0 && strpos($internalUri, '@sf_cache_partial') === false) 132 // note the special rules @sf_cache_partial and @sf_cache_fragment 133 if (strpos($internalUri, '@') === 0 && strpos($internalUri, '@sf_cache_partial') === false && strpos($internalUri, '@sf_cache_fragment') === false ) 133 134 { 134 135 throw new sfException('A cache key cannot be generated for an internal URI using the @rule syntax'); … … 166 167 { 167 168 $cacheKey = 'sf_cache_partial/'; 169 $cacheKey .= $this->convertParametersToKey($params); 168 170 } 169 170 $cacheKey .= $this->convertParametersToKey($params); 171 elseif( $route_name == 'sf_cache_fragment' ) 172 { 173 $cacheKey = 'sf_cache_fragment/'; 174 $cacheKey .= $this->convertParametersToFragmentKey($params); 175 } 176 else 177 { 178 $cacheKey .= $this->convertParametersToKey($params); 179 } 171 180 } 172 181 … … 295 304 296 305 /** 306 * Transforms an associative array of parameters from an URI into a unique key 307 * This method is only used for fragment 308 * 309 * @param array $params Associative array of parameters from the URI (including, at least, module and action) 310 * 311 * @return string Unique key 312 */ 313 protected function convertParametersToFragmentKey($params) 314 { 315 // module should be __sf_cache_fragment and action should be the 316 // fragment name, also used as sf_cache_key parameter 317 // these parameters can be removed from the generated kay 318 unset($params['module'] , $params['action']); 319 320 ksort($params); 321 foreach ($params as $key => $value) 322 { 323 $cacheKey .= sprintf('%s/%s/', $key, $value); 324 } 325 326 return rtrim( $cacheKey , '/' ); 327 } 328 329 /** 297 330 * Adds a cache to the manager. 298 331 * … … 675 708 public function start($name, $lifeTime, $clientLifeTime = null, $vary = array()) 676 709 { 677 $internalUri = $this->routing->getCurrentInternalUri();678 679 710 if (!$clientLifeTime) 680 711 { 681 712 $clientLifeTime = $lifeTime; 682 713 } 714 715 // fetch fragment uri 716 $internalUri = $this->getFragmentUri( $name ); 683 717 684 718 // add cache config to cache manager 685 719 list($route_name, $params) = $this->controller->convertUrlStringToParameters($internalUri); 720 // module should be __sf_cache_fragment and action should be the name of the fragment 686 721 $this->addCache($params['module'], $params['action'], array('withLayout' => false, 'lifeTime' => $lifeTime, 'clientLifeTime' => $clientLifeTime, 'vary' => $vary)); 687 722 688 723 // get data from cache if available 689 $data = $this->get($internalUri.(strpos($internalUri, '?') ? '&' : '?').'_sf_cache_key='.$name); 724 // note that sf_cache_key is automatically add on getFragmentUri() 725 $data = $this->get( $internalUri ); 690 726 if ($data !== null) 691 727 { … … 708 744 * @return bool true, if success otherwise false 709 745 */ 710 public function stop( $name)746 public function stop( $name ) 711 747 { 712 748 $data = ob_get_clean(); 713 749 714 // save content to cache715 $internalUri = $this->routing->getCurrentInternalUri();716 750 try 717 751 { 718 $this->set( $data, $internalUri.(strpos($internalUri, '?') ? '&' : '?').'_sf_cache_key='.$name);752 $this->set( $data, $this->getFragmentUri( $name ) ); 719 753 } 720 754 catch (Exception $e) … … 723 757 724 758 return $data; 759 } 760 761 /** 762 * Computes a fragment internal URI. 763 * 764 * @param string $name The fragement name 765 * 766 * @return string The internal URI 767 */ 768 public function getFragmentUri( $name ) 769 { 770 // in fragement case, module is __sf_cache_fragment and action is the fragment name 771 // module and action are required to the set() procedure and isCacheable() method 772 return sprintf('@sf_cache_fragment?module=%s&action=%s&sf_cache_key=%s', '__sf_cache_fragment' , $name , $name ); 725 773 } 726 774 branches/1.4/test/unit/validator/sfValidatorDecoratorTest.php
r19531 r32698 63 63 $t->is($v->getMessages(), array('required' => 'This string is required.', 'invalid' => 'This string is invalid.', 'max_length' => '"%value%" is too long (%max_length% characters max).', 'min_length' => '"%value%" is too short (%min_length% characters min).'), '->getMessages() returns messages from the embedded validator'); 64 64 $v->setMessages(array('required' => 'Required...')); 65 $t->is($v->getMessages(), array('required' => 'Required...' ), '->setMessages() sets all messages for the embedded validator');65 $t->is($v->getMessages(), array('required' => 'Required...', 'invalid' => 'Invalid.'), '->setMessages() sets all messages for the embedded validator'); 66 66 67 67 // ->getOption() ->getOptions() ->hasOption() ->getOptions() ->setOptions() … … 72 72 $t->is($v->hasOption('min_length'), true, '->hasOption() returns true if the embedded validator has a given option'); 73 73 $v->setOptions(array('min_length' => 10)); 74 $t->is($v->getOptions(), array(' min_length' => 10), '->setOptions() sets all options for the embedded validator');74 $t->is($v->getOptions(), array('required' => true, 'trim' => false, 'empty_value' => null, 'min_length' => 10), '->setOptions() sets all options for the embedded validator'); 75 75 76 76 $v = new MyValidator();