/**
  * Intercepts the parent url function to first look if the cache was already generated for the same params
  *
  * @param mixed $url url to generate using cakephp array syntax
  * @param boolean $full wheter to generate a full url or not (http scheme)
  * @return string
  * @see Helper::url()
  */
 function url($url = null, $full = false)
 {
     if (Configure::read('UrlCache.active')) {
         if ($cachedUrl = UrlCacheManager::get($url, $full)) {
             return $cachedUrl;
         }
     }
     $routerUrl = h(Router::url($url, $full));
     if (Configure::read('UrlCache.active')) {
         UrlCacheManager::set($routerUrl);
     }
     return $routerUrl;
 }
 /**
  * Intercepts the parent URL function to first look if the cache was already generated for the same params
  *
  * @param mixed $url URL to generate using CakePHP array syntax
  * @param boolean $full whether to generate a full url or not (http scheme)
  * @return string
  * @see Helper::url()
  */
 public function url($url = null, $full = false)
 {
     if (Configure::read('UrlCache.runtime.afterLayout')) {
         return parent::url($url, $full);
     }
     if (Configure::read('UrlCache.active')) {
         if ($cachedUrl = UrlCacheManager::get($url, $full)) {
             return $cachedUrl;
         }
     }
     $routerUrl = parent::url($url, $full);
     if (Configure::read('UrlCache.active')) {
         UrlCacheManager::set($routerUrl);
     }
     return $routerUrl;
 }
Exemple #3
0
 public function testUrlWithoutVerbosePrefixes()
 {
     $this->skipIf(true, 'doesnt work yet');
     Configure::delete('UrlCache');
     Configure::write('UrlCache.active', true);
     Configure::write('UrlCache.pageFiles', true);
     Configure::write('UrlCache.verbosePrefixes', false);
     UrlCacheManager::$paramFields = array('controller', 'plugin', 'action', 'prefix');
     $this->HtmlHelper->beforeRender('foo');
     $url = $this->HtmlHelper->url(array('plugin' => 'tools', 'controller' => 'posts', 'action' => 'view', 'prefix' => 'admin'));
     $this->assertEquals(array('41d5d7eb9442adbe76e6c7ebbb02ecc7'), array_keys(UrlCacheManager::$cache));
     $this->assertEquals('/admin/tools/posts/view', $url);
     $url = $this->HtmlHelper->url(array('plugin' => 'tools', 'controller' => 'posts', 'action' => 'view', 'prefix' => 'admin', 'some' => 'param'));
     $this->HtmlHelper->url(array('action' => 'view', 'controller' => 'posts', 'plugin' => 'tools', 'some' => 'param', 'prefix' => 'admin'));
     $this->assertEquals('/admin/tools/posts/view/some:param', $url);
     $this->assertEquals(array('6a7091b88c8132ebb5461851808d318a'), array_keys(UrlCacheManager::$cachePage));
     $this->HtmlHelper->afterLayout('foo');
 }
 /**
  * Returns the stored url if it was already generated, false otherwise
  *
  * @param string $key 
  * @return mixed
  */
 public static function get($url, $full)
 {
     $keyUrl = $url;
     if (is_array($keyUrl)) {
         $keyUrl += self::$extras;
         # prevent different hashs on different orders
         ksort($keyUrl, SORT_STRING);
         # prevent different hashs on different types (int/string/bool)
         foreach ($keyUrl as $key => $val) {
             $keyUrl[$key] = (string) $val;
         }
     }
     self::$key = md5(serialize($keyUrl) . $full);
     if (Configure::read('UrlCache.pageFiles')) {
         self::$type = 'cachePage';
         if (is_array($keyUrl)) {
             $res = array_diff_key($keyUrl, self::$extras);
             if (empty($res)) {
                 self::$type = 'cache';
             }
         }
         if (self::$type === 'cachePage') {
             return isset(self::$cachePage[self::$key]) ? self::$cachePage[self::$key] : false;
         }
     }
     return isset(self::$cache[self::$key]) ? self::$cache[self::$key] : false;
 }
Exemple #5
0
 /**
  * Intercepts the parent url function to first look if the cache was already generated for the same params
  *
  * @param mixed $url url to generate using cakephp array syntax
  * @param bool|array $full whether to generate a full url or not (http scheme). As array: full, escape.
  * @return string
  * @see Helper::url()
  */
 public function url($url = null, $full = false)
 {
     if (is_array($full)) {
         $escape = isset($full['ecape']) ? $full['escape'] : true;
         $full = isset($full['full']) ? $full['full'] : false;
     } else {
         $escape = true;
     }
     if (Configure::read('UrlCache.active')) {
         if ($cachedUrl = UrlCacheManager::get($url, $full)) {
             return $cachedUrl;
         }
     }
     if (!$escape) {
         $routerUrl = Router::url($url, $full);
     } else {
         $routerUrl = parent::url($url, $full);
     }
     if (Configure::read('UrlCache.active')) {
         UrlCacheManager::set($routerUrl);
     }
     return $routerUrl;
 }
 /**
  * Stores a ney key in memory cache
  *
  * @param string $key
  * @param mixed data to be stored
  * @return void
  */
 public static function set($data)
 {
     self::$modified = true;
     if (Configure::read('UrlCache.pageFiles') && self::$type === 'cachePage') {
         self::$cachePage[self::$key] = $data;
     } else {
         self::$cache[self::$key] = $data;
     }
 }