Merging fixes and enhancements into trunk Added fix for Ticket #492.

Revision: [2299]
Added fix for Ticket #494.
Added fix for Ticket #489.

Revision: [2298]
Fixed regex that would match more than one <cake:nocache></cake:nocache> group and cause a  wrong replace of the tags

Revision: [2297]
Corrected error in the convertSlash() function

Revision: [2296]
Another bug found and corrected after last commit.
This is working as expected now, and will be refactored.

Revision: [2295]
Fixed undefined index in CacheHelper::__parseFile();
Fixed caching when method is cached without params being set in the key

Revision: [2294]
Corrected caching for index method when accessing www.example.com/controller this would not use default index method.
Removed auto setting of the data variable in Controller::render();
Added additional check for cached index view in bootstrap.php

Revision: [2293]
Refactoring caching code.
Fixed problem with files being cached for all methods.
Added code to cache files to create helpers. 
Moved duplicate code to basics.php as a function

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@2300 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2006-03-14 11:54:03 +00:00
parent a5a96c9268
commit 9f9c84de52
7 changed files with 101 additions and 59 deletions

View file

@ -6,4 +6,4 @@
// +---------------------------------------------------------------------------------------------------+ //
///////////////////////////////////////////////////////////////////////////////////////////////////////////
1.0.0.2292
1.0.0.2300

View file

@ -1072,7 +1072,7 @@ function LogError ($message)
*/
function fileExistsInPath ($file)
{
$paths = explode(PATH_SEPARATOR, get_include_path());
$paths = explode(PATH_SEPARATOR, ini_get('include_path'));
foreach ($paths as $path)
{
$fullPath = $path . DIRECTORY_SEPARATOR . $file;
@ -1088,4 +1088,28 @@ function fileExistsInPath ($file)
return false;
}
/**
* Convert forward slashes to underscores and removes first and last underscores in a string
*
* @param string
* @return string with underscore remove from start and end of string
*/
function convertSlash($string)
{
$string = preg_replace('/\/\//', '/', $string);
$string = str_replace('/', '_', $string);
$pos = strpos($string, '_');
$pos1 = strrpos($string, '_');
$char = strlen($string) -1;
if($pos1 == $char)
{
$string = substr($string, 0, $char);
}
if ($pos === 0)
{
$string = substr($string, 1);
}
return $string;
}
?>

View file

@ -115,9 +115,7 @@ if(defined('CACHE_CHECK') && CACHE_CHECK === true)
{
$uri = setUri();
}
$filename = CACHE.'views'.DS.str_replace('/', '_', $uri.'.php');
$filename = CACHE.'views'.DS.convertSlash($uri).'.php';
if (file_exists($filename))
{
uses(DS.'controller'.DS.'component', DS.'view'.DS.'view');
@ -125,6 +123,13 @@ if(defined('CACHE_CHECK') && CACHE_CHECK === true)
$view = new View($v);
$view->renderCache($filename, $TIME_START);
}
elseif (file_exists(CACHE.'views'.DS.convertSlash($uri).'_index.php'))
{
uses(DS.'controller'.DS.'component', DS.'view'.DS.'view');
$v = null;
$view = new View($v);
$view->renderCache(CACHE.'views'.DS.convertSlash($uri).'_index.php', $TIME_START);
}
}
require LIBS.'model'.DS.'connection_manager.php';

View file

@ -474,18 +474,6 @@ class Controller extends Object
$this->beforeRender();
if (!isset($this->_viewVars['data']))
{
if (isset($this->params['data']))
{
$this->set('data', $this->params['data']);
}
else
{
$this->set('data', array());
}
}
$this->_viewClass =& new $viewClass($this);
if(!empty($this->modelNames))
{
@ -852,7 +840,7 @@ class Controller extends Object
{
return null;
}
$conditions = array();
foreach ($data as $model => $fields)
{

View file

@ -51,32 +51,43 @@ class CacheHelper extends Helper
{
$check = str_replace('/', '_', $this->here);
$replace = str_replace('/', '_', $this->base);
$match = str_replace($this->base, '', $this->here);
$match = str_replace('//', '/', $match);
$match = str_replace('/'.$this->controllerName.'/', '', $match);
$check = str_replace($replace, '', $check);
$check = str_replace('_'.$this->controllerName.'_', '', $check);
$pos = strpos($check, '_');
$pos1 = strrpos($check, '_');
if($pos1 > 0)
{
$check = substr($check, 0, $pos1);
}
if ($pos !== false)
{
$check = substr($check, 1);
}
$check = convertSlash($check);
$keys = str_replace('/', '_', array_keys($this->cacheAction));
$key = preg_grep("/^$check/", array_values($keys));
if(isset($key['0']))
$found = array_keys($this->cacheAction);
$index = null;
$count = 0;
foreach ($keys as $key => $value)
{
$key = str_replace('_', '/', $key['0']);
if(strpos($check, $value) === 0)
{
$index = $found[$count];
break;
}
$count++;
}
else
if(isset($index))
{
$key = 'index';
$pos1 = strrpos($match, '/');
$char = strlen($match) -1;
if($pos1 == $char)
{
$match = substr($match, 0, $char);
}
$key = $match;
}
elseif ($this->action == 'index')
{
$index = 'index';
}
if(isset($this->cacheAction[$key]))
if(isset($this->cacheAction[$index]))
{
$cacheTime = $this->cacheAction[$key];
$cacheTime = $this->cacheAction[$index];
}
else
{
@ -116,16 +127,19 @@ class CacheHelper extends Helper
$file = file_get_contents($file);
}
preg_match_all('/(?P<found><cake:nocache>(?:.*|(?:[\\S\\s]*[^\\S]))<\/cake:nocache>)/i', $cache, $oresult, PREG_PATTERN_ORDER);
preg_match_all('/<cake:nocache>(?P<replace>(?:.*|(?:[\\S\\s]*[^\\S])))<\/cake:nocache>/i', $file, $result, PREG_PATTERN_ORDER);
preg_match_all('/(?P<found><cake:nocache>(?<=<cake:nocache>)[\\s\\S]*?(?=<\/cake:nocache>)<\/cake:nocache>)/i', $cache, $oresult, PREG_PATTERN_ORDER);
preg_match_all('/(?<=<cake:nocache>)(?P<replace>[\\s\\S]*?)(?=<\/cake:nocache>)/i', $file, $result, PREG_PATTERN_ORDER);
if(!empty($result['replace']))
{
$count = 0;
foreach($result['replace'] as $result)
{
$this->replace[] = $result;
$this->match[] = $oresult['found'][$count];
if(isset($oresult['found'][$count]))
{
$this->replace[] = $result;
$this->match[] = $oresult['found'][$count];
}
$count++;
}
}
@ -157,17 +171,33 @@ class CacheHelper extends Helper
{
$cacheTime = $now + strtotime($timestamp);
}
$result = preg_replace('/\/\//', '/', $this->here);
$cache = str_replace('/', '_', $result.'.php');
$cache = str_replace('favicon.ico', '', $cache);
$file = '<!--cachetime:'.$cacheTime.'-->'.
'<?php loadController(\''.$this->view->name.'\'); ?>'.
'<?php $this->controller = new '.$this->view->name.'Controller(); ?>'.
'<?php $this->helpers = unserialize(\''. serialize($this->view->helpers).'\'); ?>'.
'<?php $this->webroot = \''. $this->view->webroot.'\'; ?>'.
'<?php $this->data = unserialize(\''. serialize($this->view->data).'\'); ?>'.
'<?php $loaded = array(); ?>'.
'<?php $this->_loadHelpers($loaded, $this->helpers); ?>'.$file;
$cache = convertSlash($this->here).'.php';
$file = '<!--cachetime:'.$cacheTime.'-->
<?php
loadController(\''.$this->view->name.'\');
$this->controller = new '.$this->view->name.'Controller();
$this->helpers = unserialize(\''. serialize($this->view->helpers).'\');
$this->webroot = \''. $this->view->webroot.'\';
$this->data = unserialize(\''. serialize($this->view->data).'\');
$loadedHelpers = array();
$loadedHelpers = $this->_loadHelpers($loadedHelpers, $this->helpers);
foreach(array_keys($loadedHelpers) as $helper)
{
$replace = strtolower(substr($helper, 0, 1));
$camelBackedHelper = preg_replace(\'/\\w/\', $replace, $helper, 1);
${$camelBackedHelper} =& $loadedHelpers[$helper];
if(isset(${$camelBackedHelper}->helpers) && is_array(${$camelBackedHelper}->helpers))
{
foreach(${$camelBackedHelper}->helpers as $subHelper)
{
${$camelBackedHelper}->{$subHelper} =& $loadedHelpers[$subHelper];
}
}
$this->loaded[$camelBackedHelper] = (${$camelBackedHelper});
}
?>
'.$file;
return cache('views'.DS.$cache, $file, $timestamp);
}
}

View file

@ -1384,9 +1384,7 @@ class HtmlHelper extends Helper
'05'=>'5','06'=>'6','07'=>'7','08'=>'8','09'=>'9',
'10'=>'10','11'=>'11','12'=>'12');
}
$option = $this->selectTag($tagName.'_hour', $hours, $hourValue, $selectAttr,
$optionAttr);
$option = $this->selectTag($tagName.'_hour', $hours, $hourValue, $selectAttr, $optionAttr, $showEmpty);
return $option;
}
@ -1407,9 +1405,7 @@ class HtmlHelper extends Helper
{
$mins[$minCount] = sprintf('%02d', $minCount);
}
$option = $this->selectTag($tagName.'_min', $mins, $minValue, $selectAttr,
$optionAttr);
$option = $this->selectTag($tagName.'_hour', $hours, $hourValue, $selectAttr, $optionAttr, $showEmpty);
return $option;
}
@ -1427,9 +1423,7 @@ class HtmlHelper extends Helper
$value = isset($value)? $value : $this->tagValue($tagName."_meridian");
$merValue = empty($selected) ? date('a') : $selected ;
$meridians = array('am'=>'am','pm'=>'pm');
$option = $this->selectTag($tagName.'_meridian', $meridians, $merValue, $selectAttr,
$optionAttr);
$option = $this->selectTag($tagName.'_hour', $hours, $hourValue, $selectAttr, $optionAttr, $showEmpty);
return $option;
}

View file

@ -670,6 +670,7 @@ class View extends Object
}
$cache->base = $this->base;
$cache->here = $this->here;
$cache->action = $this->action;
$cache->controllerName = $this->params['controller'];
$cache->cacheAction = $this->controller->cacheAction;
$cache->cache($___viewFn, $out, $cached);