mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +00:00
added option to modify element cache name, #2327, see tests. Adding auth key for flash message, #2996
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5497 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
b91b501314
commit
889e62881b
3 changed files with 63 additions and 9 deletions
|
@ -296,7 +296,7 @@ class AuthComponent extends Object {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
$this->Session->setFlash($this->loginError, 'default', array(), 'Auth.login');
|
$this->Session->setFlash($this->loginError, 'default', array(), 'auth');
|
||||||
unset($controller->data[$this->userModel][$this->fields['password']]);
|
unset($controller->data[$this->userModel][$this->fields['password']]);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -347,7 +347,7 @@ class AuthComponent extends Object {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->Session->setFlash($this->authError);
|
$this->Session->setFlash($this->authError, 'default', array(), 'auth');
|
||||||
$controller->redirect($controller->referer(), null, true);
|
$controller->redirect($controller->referer(), null, true);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -467,6 +467,7 @@ class AuthComponent extends Object {
|
||||||
$object = $auth[$type];
|
$object = $auth[$type];
|
||||||
} else {
|
} else {
|
||||||
$type = $auth;
|
$type = $auth;
|
||||||
|
return compact('type');
|
||||||
}
|
}
|
||||||
return compact('type', 'object');
|
return compact('type', 'object');
|
||||||
}
|
}
|
||||||
|
|
|
@ -420,24 +420,29 @@ class View extends Object {
|
||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function element($name, $params = array()) {
|
function element($name, $params = array()) {
|
||||||
if (in_array('cache', array_keys($params))) {
|
if (isset($params['cache'])) {
|
||||||
$expires = '+1 day';
|
$expires = '+1 day';
|
||||||
if ($params['cache'] !== true) {
|
$key = null;
|
||||||
|
if (is_array($params['cache'])) {
|
||||||
|
$expires = $params['cache']['time'];
|
||||||
|
$key = convertSlash($params['cache']['key']);
|
||||||
|
} elseif ($params['cache'] !== true) {
|
||||||
$expires = $params['cache'];
|
$expires = $params['cache'];
|
||||||
|
$key = implode('_', array_keys($params));
|
||||||
}
|
}
|
||||||
if ($expires) {
|
if ($expires) {
|
||||||
$plugin = null;
|
$plugin = null;
|
||||||
if (isset($params['plugin'])) {
|
if (isset($params['plugin'])) {
|
||||||
$plugin = $params['plugin'];
|
$plugin = $params['plugin'].'_';
|
||||||
}
|
}
|
||||||
$cacheFile = 'element_' . $plugin .'_' . convertSlash($name);
|
$cacheFile = 'element_' . $key .'_'. $plugin . convertSlash($name);
|
||||||
$cache = cache('views' . DS . $cacheFile, null, $expires);
|
$cache = cache('views' . DS . $cacheFile, null, $expires);
|
||||||
if ($cache) {
|
if (is_string($cache)) {
|
||||||
return $cache;
|
return $cache;
|
||||||
} else {
|
} else {
|
||||||
$element = $this->renderElement($name, $params);
|
$element = $this->renderElement($name, $params);
|
||||||
cache('views' . DS . $cacheFile, $element, $expires);
|
cache('views' . DS . $cacheFile, $element, $expires);
|
||||||
return $element;
|
return $element;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,13 @@ class PostsController extends Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TestView extends View {
|
||||||
|
|
||||||
|
function renderElement($name, $params = array()) {
|
||||||
|
return $name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Short description for class.
|
* Short description for class.
|
||||||
*
|
*
|
||||||
|
@ -75,6 +82,47 @@ class ViewTest extends UnitTestCase {
|
||||||
$this->assertEqual($this->view->__scripts, array('prototype.js', 'mainEvent' => 'Event.observe(window, "load", function() { doSomething(); }, true);'));
|
$this->assertEqual($this->view->__scripts, array('prototype.js', 'mainEvent' => 'Event.observe(window, "load", function() { doSomething(); }, true);'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testElementCache() {
|
||||||
|
$View = new TestView($this->PostsController);
|
||||||
|
$element = 'element_name';
|
||||||
|
$result = $View->element($element);
|
||||||
|
$this->assertEqual($result, $element);
|
||||||
|
|
||||||
|
$cached = false;
|
||||||
|
$result = $View->element($element, array('cache'=>'+1 second'));
|
||||||
|
if(file_exists(CACHE . 'views' . DS . 'element_cache_'.$element)) {
|
||||||
|
$cached = true;
|
||||||
|
unlink(CACHE . 'views' . DS . 'element_cache_'.$element);
|
||||||
|
}
|
||||||
|
$this->assertTrue($cached);
|
||||||
|
|
||||||
|
$cached = false;
|
||||||
|
$result = $View->element($element, array('cache'=>'+1 second', 'other_param'=> true, 'anotherParam'=> true));
|
||||||
|
if(file_exists(CACHE . 'views' . DS . 'element_cache_other_param_anotherParam_'.$element)) {
|
||||||
|
$cached = true;
|
||||||
|
unlink(CACHE . 'views' . DS . 'element_cache_other_param_anotherParam_'.$element);
|
||||||
|
}
|
||||||
|
$this->assertTrue($cached);
|
||||||
|
|
||||||
|
$cached = false;
|
||||||
|
$result = $View->element($element, array('cache'=>array('time'=>'+1 second', 'key'=>'/whatever/here')));
|
||||||
|
if(file_exists(CACHE . 'views' . DS . 'element_'.convertSlash('/whatever/here').'_'.$element)) {
|
||||||
|
$cached = true;
|
||||||
|
unlink(CACHE . 'views' . DS . 'element_'.convertSlash('/whatever/here').'_'.$element);
|
||||||
|
}
|
||||||
|
$this->assertTrue($cached);
|
||||||
|
|
||||||
|
$cached = false;
|
||||||
|
$result = $View->element($element, array('cache'=>array('time'=>'+1 second', 'key'=>'whatever_here')));
|
||||||
|
if(file_exists(CACHE . 'views' . DS . 'element_whatever_here_'.$element)) {
|
||||||
|
$cached = true;
|
||||||
|
unlink(CACHE . 'views' . DS . 'element_whatever_here_'.$element);
|
||||||
|
}
|
||||||
|
$this->assertTrue($cached);
|
||||||
|
$this->assertEqual($result, $element);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function tearDown() {
|
function tearDown() {
|
||||||
unset($this->view);
|
unset($this->view);
|
||||||
unset($this->PostsController);
|
unset($this->PostsController);
|
||||||
|
|
Loading…
Add table
Reference in a new issue