mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 09:06:17 +00:00
Merge branch '2.1' into 2.2
This commit is contained in:
commit
4c6453501e
11 changed files with 185 additions and 20 deletions
|
@ -267,6 +267,12 @@ class ExceptionRenderer {
|
||||||
$this->controller->render($template);
|
$this->controller->render($template);
|
||||||
$this->controller->afterFilter();
|
$this->controller->afterFilter();
|
||||||
$this->controller->response->send();
|
$this->controller->response->send();
|
||||||
|
} catch (MissingViewException $e) {
|
||||||
|
try {
|
||||||
|
$this->_outputMessage('error500');
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$this->_outputMessageSafe('error500');
|
||||||
|
}
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$this->controller->set(array(
|
$this->controller->set(array(
|
||||||
'error' => $e,
|
'error' => $e,
|
||||||
|
|
|
@ -53,9 +53,8 @@ class DboSource extends DataSource {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches result from query parsing operations. Cached results for both DboSource::name() and
|
* Caches result from query parsing operations. Cached results for both DboSource::name() and
|
||||||
* DboSource::conditions() will be stored here. Method caching uses `crc32()` which is
|
* DboSource::conditions() will be stored here. Method caching uses `md5()`. If you have
|
||||||
* fast but can collisions more easily than other hashing algorithms. If you have problems
|
* problems with collisions, set DboSource::$cacheMethods to false.
|
||||||
* with collisions, set DboSource::$cacheMethods to false.
|
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
|
@ -791,7 +790,7 @@ class DboSource extends DataSource {
|
||||||
* Strips fields out of SQL functions before quoting.
|
* Strips fields out of SQL functions before quoting.
|
||||||
*
|
*
|
||||||
* Results of this method are stored in a memory cache. This improves performance, but
|
* Results of this method are stored in a memory cache. This improves performance, but
|
||||||
* because the method uses a simple hashing algorithm it can infrequently have collisions.
|
* because the method uses a hashing algorithm it can have collisions.
|
||||||
* Setting DboSource::$cacheMethods to false will disable the memory cache.
|
* Setting DboSource::$cacheMethods to false will disable the memory cache.
|
||||||
*
|
*
|
||||||
* @param mixed $data Either a string with a column to quote. An array of columns to quote or an
|
* @param mixed $data Either a string with a column to quote. An array of columns to quote or an
|
||||||
|
@ -811,7 +810,7 @@ class DboSource extends DataSource {
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
$cacheKey = crc32($this->startQuote . $data . $this->endQuote);
|
$cacheKey = md5($this->startQuote . $data . $this->endQuote);
|
||||||
if ($return = $this->cacheMethod(__FUNCTION__, $cacheKey)) {
|
if ($return = $this->cacheMethod(__FUNCTION__, $cacheKey)) {
|
||||||
return $return;
|
return $return;
|
||||||
}
|
}
|
||||||
|
@ -2284,7 +2283,8 @@ class DboSource extends DataSource {
|
||||||
$model->alias,
|
$model->alias,
|
||||||
$virtualFields,
|
$virtualFields,
|
||||||
$fields,
|
$fields,
|
||||||
$quote
|
$quote,
|
||||||
|
ConnectionManager::getSourceName($this)
|
||||||
);
|
);
|
||||||
$cacheKey = md5(serialize($cacheKey));
|
$cacheKey = md5(serialize($cacheKey));
|
||||||
if ($return = $this->cacheMethod(__FUNCTION__, $cacheKey)) {
|
if ($return = $this->cacheMethod(__FUNCTION__, $cacheKey)) {
|
||||||
|
@ -2384,7 +2384,7 @@ class DboSource extends DataSource {
|
||||||
* is given it will be integer cast as condition. Null will return 1 = 1.
|
* is given it will be integer cast as condition. Null will return 1 = 1.
|
||||||
*
|
*
|
||||||
* Results of this method are stored in a memory cache. This improves performance, but
|
* Results of this method are stored in a memory cache. This improves performance, but
|
||||||
* because the method uses a simple hashing algorithm it can infrequently have collisions.
|
* because the method uses a hashing algorithm it can have collisions.
|
||||||
* Setting DboSource::$cacheMethods to false will disable the memory cache.
|
* Setting DboSource::$cacheMethods to false will disable the memory cache.
|
||||||
*
|
*
|
||||||
* @param mixed $conditions Array or string of conditions, or any value.
|
* @param mixed $conditions Array or string of conditions, or any value.
|
||||||
|
|
|
@ -1175,7 +1175,7 @@ class Model extends Object implements CakeEventListener {
|
||||||
*/
|
*/
|
||||||
protected function _setAliasData($data) {
|
protected function _setAliasData($data) {
|
||||||
$models = array_keys($this->getAssociated());
|
$models = array_keys($this->getAssociated());
|
||||||
$schema = array_keys($this->schema());
|
$schema = array_keys((array)$this->schema());
|
||||||
foreach ($data as $field => $value) {
|
foreach ($data as $field => $value) {
|
||||||
if (in_array($field, $schema) || !in_array($field, $models)) {
|
if (in_array($field, $schema) || !in_array($field, $models)) {
|
||||||
$data[$this->alias][$field] = $value;
|
$data[$this->alias][$field] = $value;
|
||||||
|
|
|
@ -690,7 +690,8 @@ class BasicsTest extends CakeTestCase {
|
||||||
'this-is-a-test'
|
'this-is-a-test'
|
||||||
###########################
|
###########################
|
||||||
EXPECTED;
|
EXPECTED;
|
||||||
$expected = sprintf($expectedText, substr(__FILE__, strlen(ROOT)), __LINE__ - 8);
|
$expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
|
||||||
|
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
@ -704,7 +705,7 @@ EXPECTED;
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
EXPECTED;
|
EXPECTED;
|
||||||
$expected = sprintf($expectedHtml, substr(__FILE__, strlen(ROOT)), __LINE__ - 10);
|
$expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
@ -718,7 +719,7 @@ EXPECTED;
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
EXPECTED;
|
EXPECTED;
|
||||||
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 10);
|
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
@ -732,7 +733,7 @@ EXPECTED;
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
EXPECTED;
|
EXPECTED;
|
||||||
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 10);
|
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 10);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
@ -753,9 +754,9 @@ EXPECTED;
|
||||||
###########################
|
###########################
|
||||||
EXPECTED;
|
EXPECTED;
|
||||||
if (php_sapi_name() == 'cli') {
|
if (php_sapi_name() == 'cli') {
|
||||||
$expected = sprintf($expectedText, substr(__FILE__, strlen(ROOT)), __LINE__ - 17);
|
$expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 17);
|
||||||
} else {
|
} else {
|
||||||
$expected = sprintf($expectedHtml, substr(__FILE__, strlen(ROOT)), __LINE__ - 19);
|
$expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);
|
||||||
}
|
}
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
@ -777,9 +778,9 @@ EXPECTED;
|
||||||
###########################
|
###########################
|
||||||
EXPECTED;
|
EXPECTED;
|
||||||
if (php_sapi_name() == 'cli') {
|
if (php_sapi_name() == 'cli') {
|
||||||
$expected = sprintf($expectedText, substr(__FILE__, strlen(ROOT)), __LINE__ - 17);
|
$expected = sprintf($expectedText, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 17);
|
||||||
} else {
|
} else {
|
||||||
$expected = sprintf($expectedHtml, substr(__FILE__, strlen(ROOT)), __LINE__ - 19);
|
$expected = sprintf($expectedHtml, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 19);
|
||||||
}
|
}
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
@ -792,7 +793,7 @@ EXPECTED;
|
||||||
'<div>this-is-a-test</div>'
|
'<div>this-is-a-test</div>'
|
||||||
###########################
|
###########################
|
||||||
EXPECTED;
|
EXPECTED;
|
||||||
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 8);
|
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
@ -804,7 +805,7 @@ EXPECTED;
|
||||||
'<div>this-is-a-test</div>'
|
'<div>this-is-a-test</div>'
|
||||||
###########################
|
###########################
|
||||||
EXPECTED;
|
EXPECTED;
|
||||||
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 8);
|
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
|
@ -816,7 +817,7 @@ EXPECTED;
|
||||||
'<div>this-is-a-test</div>'
|
'<div>this-is-a-test</div>'
|
||||||
###########################
|
###########################
|
||||||
EXPECTED;
|
EXPECTED;
|
||||||
$expected = sprintf($expected, substr(__FILE__, strlen(ROOT)), __LINE__ - 8);
|
$expected = sprintf($expected, str_replace(CAKE_CORE_INCLUDE_PATH, '', __FILE__), __LINE__ - 8);
|
||||||
$this->assertEquals($expected, $result);
|
$this->assertEquals($expected, $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -277,6 +277,49 @@ class ExceptionRendererTest extends CakeTestCase {
|
||||||
$this->assertEquals($exception, $ExceptionRenderer->error);
|
$this->assertEquals($exception, $ExceptionRenderer->error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that helpers in custom CakeErrorController are not lost
|
||||||
|
*/
|
||||||
|
public function testCakeErrorHelpersNotLost() {
|
||||||
|
$testApp = CAKE . 'Test' . DS . 'test_app' . DS;
|
||||||
|
App::build(array(
|
||||||
|
'Controller' => array(
|
||||||
|
$testApp . 'Controller' . DS
|
||||||
|
),
|
||||||
|
'View/Helper' => array(
|
||||||
|
$testApp . 'View' . DS . 'Helper' . DS
|
||||||
|
),
|
||||||
|
'View/Layouts' => array(
|
||||||
|
$testApp . 'View' . DS . 'Layouts' . DS
|
||||||
|
),
|
||||||
|
'Error' => array(
|
||||||
|
$testApp . 'Error' . DS
|
||||||
|
),
|
||||||
|
), App::RESET);
|
||||||
|
Configure::write('Error', array(
|
||||||
|
'handler' => 'TestAppsErrorHandler::handleError',
|
||||||
|
'level' => E_ALL & ~E_DEPRECATED,
|
||||||
|
'trace' => true
|
||||||
|
));
|
||||||
|
|
||||||
|
Configure::write('Exception', array(
|
||||||
|
'handler' => 'TestAppsErrorHandler::handleException',
|
||||||
|
'renderer' => 'TestAppsExceptionRenderer',
|
||||||
|
'log' => true
|
||||||
|
));
|
||||||
|
|
||||||
|
App::uses('TestAppsErrorController', 'Controller');
|
||||||
|
App::uses('TestAppsExceptionRenderer', 'Error');
|
||||||
|
|
||||||
|
$exception = new SocketException('socket exception');
|
||||||
|
$renderer = new TestAppsExceptionRenderer($exception);
|
||||||
|
|
||||||
|
ob_start();
|
||||||
|
$renderer->render();
|
||||||
|
$result = ob_get_clean();
|
||||||
|
$this->assertContains('<b>peeled</b>', $result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* test that unknown exception types with valid status codes are treated correctly.
|
* test that unknown exception types with valid status codes are treated correctly.
|
||||||
*
|
*
|
||||||
|
|
|
@ -59,6 +59,30 @@ class DboTestSource extends DboSource {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class DboSecondTestSource extends DboSource {
|
||||||
|
|
||||||
|
public $startQuote = '_';
|
||||||
|
|
||||||
|
public $endQuote = '_';
|
||||||
|
|
||||||
|
public function connect($config = array()) {
|
||||||
|
$this->connected = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function mergeAssociation(&$data, &$merge, $association, $type, $selfJoin = false) {
|
||||||
|
return parent::_mergeAssociation($data, $merge, $association, $type, $selfJoin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setConfig($config = array()) {
|
||||||
|
$this->config = $config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setConnection($conn) {
|
||||||
|
$this->_connection = $conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DboSourceTest class
|
* DboSourceTest class
|
||||||
*
|
*
|
||||||
|
@ -605,6 +629,21 @@ class DboSourceTest extends CakeTestCase {
|
||||||
$this->assertNull($result);
|
$this->assertNull($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that rare collisions do not happen with method caching
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testNameMethodCacheCollisions() {
|
||||||
|
$this->testDb->cacheMethods = true;
|
||||||
|
$this->testDb->flushMethodCache();
|
||||||
|
$this->testDb->name('Model.fieldlbqndkezcoapfgirmjsh');
|
||||||
|
$result = $this->testDb->name('Model.fieldkhdfjmelarbqnzsogcpi');
|
||||||
|
$expected = '`Model`.`fieldkhdfjmelarbqnzsogcpi`';
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testLog method
|
* testLog method
|
||||||
*
|
*
|
||||||
|
@ -837,6 +876,37 @@ class DboSourceTest extends CakeTestCase {
|
||||||
$this->assertTrue(empty(DboTestSource::$methodCache['fields']), 'Cache not empty');
|
$this->assertTrue(empty(DboTestSource::$methodCache['fields']), 'Cache not empty');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* test that fields() method cache detects datasource changes
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testFieldsCacheKeyWithDatasourceChange() {
|
||||||
|
ConnectionManager::create('firstschema', array(
|
||||||
|
'datasource' => 'DboTestSource'
|
||||||
|
));
|
||||||
|
ConnectionManager::create('secondschema', array(
|
||||||
|
'datasource' => 'DboSecondTestSource'
|
||||||
|
));
|
||||||
|
Cache::delete('method_cache', '_cake_core_');
|
||||||
|
DboTestSource::$methodCache = array();
|
||||||
|
$Article = ClassRegistry::init('Article');
|
||||||
|
|
||||||
|
$Article->setDataSource('firstschema');
|
||||||
|
$ds = $Article->getDataSource();
|
||||||
|
$ds->cacheMethods = true;
|
||||||
|
$first = $ds->fields($Article, null, array('title', 'body', 'published'));
|
||||||
|
|
||||||
|
$Article->setDataSource('secondschema');
|
||||||
|
$ds = $Article->getDataSource();
|
||||||
|
$ds->cacheMethods = true;
|
||||||
|
$second = $ds->fields($Article, null, array('title', 'body', 'published'));
|
||||||
|
|
||||||
|
$this->assertNotEquals($first, $second);
|
||||||
|
$this->assertEquals(2, count(DboTestSource::$methodCache['fields']));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that group works without a model
|
* Test that group works without a model
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
App::uses('CakeErrorController', 'Controller');
|
||||||
|
|
||||||
|
class TestAppsErrorController extends CakeErrorController {
|
||||||
|
|
||||||
|
public $helpers = array(
|
||||||
|
'Html',
|
||||||
|
'Session',
|
||||||
|
'Form',
|
||||||
|
'Banana',
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
21
lib/Cake/Test/test_app/Error/TestAppsExceptionRenderer.php
Normal file
21
lib/Cake/Test/test_app/Error/TestAppsExceptionRenderer.php
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class TestAppsExceptionRenderer extends ExceptionRenderer {
|
||||||
|
|
||||||
|
protected function _getController($exception) {
|
||||||
|
App::uses('TestAppsErrorController', 'Controller');
|
||||||
|
if (!$request = Router::getRequest(true)) {
|
||||||
|
$request = new CakeRequest();
|
||||||
|
}
|
||||||
|
$response = new CakeResponse(array('charset' => Configure::read('App.encoding')));
|
||||||
|
try {
|
||||||
|
$controller = new TestAppsErrorController($request, $response);
|
||||||
|
$controller->layout = 'banana';
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$controller = new Controller($request, $response);
|
||||||
|
$controller->viewPath = 'Errors';
|
||||||
|
}
|
||||||
|
return $controller;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -19,4 +19,9 @@
|
||||||
App::uses('Helper', 'View');
|
App::uses('Helper', 'View');
|
||||||
|
|
||||||
class BananaHelper extends Helper {
|
class BananaHelper extends Helper {
|
||||||
|
|
||||||
|
public function peel() {
|
||||||
|
return '<b>peeled</b>';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
5
lib/Cake/Test/test_app/View/Layouts/banana.ctp
Normal file
5
lib/Cake/Test/test_app/View/Layouts/banana.ctp
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<body>
|
||||||
|
<?php
|
||||||
|
echo $this->Banana->peel();
|
||||||
|
?>
|
||||||
|
</body>
|
|
@ -77,7 +77,7 @@ function debug($var = false, $showHtml = null, $showFrom = true) {
|
||||||
$lineInfo = '';
|
$lineInfo = '';
|
||||||
if ($showFrom) {
|
if ($showFrom) {
|
||||||
$trace = Debugger::trace(array('start' => 1, 'depth' => 2, 'format' => 'array'));
|
$trace = Debugger::trace(array('start' => 1, 'depth' => 2, 'format' => 'array'));
|
||||||
$file = substr($trace[0]['file'], strlen(ROOT));
|
$file = str_replace(array(CAKE_CORE_INCLUDE_PATH, ROOT), '', $trace[0]['file']);
|
||||||
$line = $trace[0]['line'];
|
$line = $trace[0]['line'];
|
||||||
}
|
}
|
||||||
$html = <<<HTML
|
$html = <<<HTML
|
||||||
|
|
Loading…
Add table
Reference in a new issue