Merge branch '2.1' into 2.2-validator

Conflicts:
	lib/Cake/Model/Model.php
	lib/Cake/Test/Case/Model/ModelValidationTest.php
	lib/Cake/Test/Case/Model/models.php
This commit is contained in:
Jose Lorenzo Rodriguez 2012-05-19 15:39:44 -04:30
commit b22c50d8b6
12 changed files with 188 additions and 108 deletions

View file

@ -105,6 +105,38 @@ class ExtractTask extends AppShell {
*/ */
protected $_validationDomain = 'default'; protected $_validationDomain = 'default';
/**
* Method to interact with the User and get path selections.
*
* @return void
*/
protected function _getPaths() {
$defaultPath = APP;
while (true) {
$currentPaths = count($this->_paths) > 0 ? $this->_paths : array('None');
$message = __d(
'cake_console',
"Current paths: %s\nWhat is the path you would like to extract?\n[Q]uit [D]one",
implode(', ', $currentPaths)
);
$response = $this->in($message, null, $defaultPath);
if (strtoupper($response) === 'Q') {
$this->out(__d('cake_console', 'Extract Aborted'));
return $this->_stop();
} elseif (strtoupper($response) === 'D' && count($this->_paths)) {
$this->out();
return;
} elseif (strtoupper($response) === 'D') {
$this->err(__d('cake_console', '<warning>No directories selected.</warning> Please choose a directory.'));
} elseif (is_dir($response)) {
$this->_paths[] = $response;
$defaultPath = 'D';
} else {
$this->err(__d('cake_console', 'The directory path you supplied was not found. Please try again.'));
}
$this->out();
}
}
/** /**
* Execution method always used for tasks * Execution method always used for tasks
* *
@ -127,24 +159,7 @@ class ExtractTask extends AppShell {
$this->_paths = array(CakePlugin::path($plugin)); $this->_paths = array(CakePlugin::path($plugin));
$this->params['plugin'] = $plugin; $this->params['plugin'] = $plugin;
} else { } else {
$defaultPath = APP; $this->_getPaths();
$message = __d('cake_console', "What is the path you would like to extract?\n[Q]uit [D]one");
while (true) {
$response = $this->in($message, null, $defaultPath);
if (strtoupper($response) === 'Q') {
$this->out(__d('cake_console', 'Extract Aborted'));
$this->_stop();
} elseif (strtoupper($response) === 'D') {
$this->out();
break;
} elseif (is_dir($response)) {
$this->_paths[] = $response;
$defaultPath = 'D';
} else {
$this->err(__d('cake_console', 'The directory path you supplied was not found. Please try again.'));
}
$this->out();
}
} }
if (!empty($this->params['exclude-plugins']) && $this->_isExtractingApp()) { if (!empty($this->params['exclude-plugins']) && $this->_isExtractingApp()) {

View file

@ -680,12 +680,14 @@ class Shell extends Object {
* @return boolean Success * @return boolean Success
*/ */
protected function _checkUnitTest() { protected function _checkUnitTest() {
if (App::import('Vendor', 'phpunit', array('file' => 'PHPUnit' . DS . 'Autoload.php'))) { if (class_exists('PHPUnit_Framework_TestCase')) {
return true; return true;
} } elseif (@include 'PHPUnit' . DS . 'Autoload.php') {
if (@include 'PHPUnit' . DS . 'Autoload.php') { return true;
} elseif (App::import('Vendor', 'phpunit', array('file' => 'PHPUnit' . DS . 'Autoload.php'))) {
return true; return true;
} }
$prompt = __d('cake_console', 'PHPUnit is not installed. Do you want to bake unit test files anyway?'); $prompt = __d('cake_console', 'PHPUnit is not installed. Do you want to bake unit test files anyway?');
$unitTest = $this->in($prompt, array('y', 'n'), 'y'); $unitTest = $this->in($prompt, array('y', 'n'), 'y');
$result = strtolower($unitTest) == 'y' || strtolower($unitTest) == 'yes'; $result = strtolower($unitTest) == 'y' || strtolower($unitTest) == 'yes';

View file

@ -1138,9 +1138,7 @@ class Model extends Object implements CakeEventListener {
if (is_array($one)) { if (is_array($one)) {
$data = $one; $data = $one;
if (empty($one[$this->alias])) { if (empty($one[$this->alias])) {
if ($this->getAssociated(key($one)) === null) { $data = $this->_setAliasData($one);
$data = array($this->alias => $one);
}
} }
} else { } else {
$data = array($this->alias => array($one => $two)); $data = array($this->alias => array($one => $two));
@ -1169,6 +1167,24 @@ class Model extends Object implements CakeEventListener {
return $data; return $data;
} }
/**
* Move values to alias
*
* @param array $data
* @return array
*/
protected function _setAliasData($data) {
$models = array_keys($this->getAssociated());
$schema = array_keys($this->schema());
foreach ($data as $field => $value) {
if (in_array($field, $schema) || !in_array($field, $models)) {
$data[$this->alias][$field] = $value;
unset($data[$field]);
}
}
return $data;
}
/** /**
* Normalize Xml::toArray() to use in Model::save() * Normalize Xml::toArray() to use in Model::save()
* *
@ -2177,6 +2193,7 @@ class Model extends Object implements CakeEventListener {
$db = $this->getDataSource(); $db = $this->getDataSource();
$transactionBegun = $db->begin(); $transactionBegun = $db->begin();
} }
$associations = $this->getAssociated(); $associations = $this->getAssociated();
$return = array(); $return = array();
$validates = true; $validates = true;

View file

@ -115,21 +115,14 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
$model = $this->getModel(); $model = $this->getModel();
$options = array_merge(array('atomic' => true, 'deep' => false), $options); $options = array_merge(array('atomic' => true, 'deep' => false), $options);
$model->validationErrors = $validationErrors = $return = array(); $model->validationErrors = $validationErrors = $return = array();
if (!($model->create($data) && $model->validates($options))) { $model->create(null);
if (!($model->set($data) && $model->validates($options))) {
$validationErrors[$model->alias] = $model->validationErrors; $validationErrors[$model->alias] = $model->validationErrors;
$return[$model->alias] = false; $return[$model->alias] = false;
} else { } else {
$return[$model->alias] = true; $return[$model->alias] = true;
} }
$data = $model->data;
if (empty($options['deep'])) {
$data = $model->data;
} else {
$modelData = $model->data;
$recordData = $modelData[$model->alias];
unset($modelData[$model->alias]);
$data = $modelData + array_merge($data, $recordData);
}
$associations = $model->getAssociated(); $associations = $model->getAssociated();
foreach ($data as $association => &$values) { foreach ($data as $association => &$values) {
@ -200,7 +193,8 @@ class ModelValidator implements ArrayAccess, IteratorAggregate, Countable {
if ($options['deep']) { if ($options['deep']) {
$validates = $model->validateAssociated($record, $options); $validates = $model->validateAssociated($record, $options);
} else { } else {
$validates = $model->create($record) && $model->validates($options); $model->create(null);
$validates = $model->set($record) && $model->validates($options);
$data[$key] = $model->data; $data[$key] = $model->data;
} }
if ($validates === false || (is_array($validates) && in_array(false, $validates, true))) { if ($validates === false || (is_array($validates) && in_array(false, $validates, true))) {

View file

@ -7868,7 +7868,7 @@ class ModelReadTest extends BaseModelTest {
$Article = new CustomArticle(); $Article = new CustomArticle();
$data = array('user_id' => 3, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N'); $data = array('user_id' => 3, 'title' => 'Fourth Article', 'body' => 'Article Body, unpublished', 'published' => 'N');
$Article->create($data); $Article->create($data);
$Article->save(); $Article->save(null, false);
$this->assertEquals(4, $Article->id); $this->assertEquals(4, $Article->id);
$result = $Article->find('published'); $result = $Article->find('published');

View file

@ -1925,21 +1925,32 @@ class ModelValidationTest extends BaseModelTest {
$result = $model->saveAll($data, array('validate' => 'first')); $result = $model->saveAll($data, array('validate' => 'first'));
$this->assertTrue($result); $this->assertTrue($result);
$title = $model->field('title', array('body' => 'foo0')); $this->assertFalse($model->findMethods['unPublished'], 'beforeValidate was run twice');
$model->findMethods['unPublished'] = true;
$data = array(
'CustomArticle' => array(
'body' => 'foo1'
)
);
$result = $model->saveAll($data, array('validate' => 'first', 'deep' => true));
$this->assertTrue($result);
$title = $model->field('title', array('body' => 'foo1'));
$this->assertEquals('foo', $title); $this->assertEquals('foo', $title);
$this->assertFalse($model->findMethods['unPublished'], 'beforeValidate was run twice');
$data = array( $data = array(
array('body' => 'foo1'),
array('body' => 'foo2'), array('body' => 'foo2'),
array('body' => 'foo3') array('body' => 'foo3'),
array('body' => 'foo4')
); );
$result = $model->saveAll($data, array('validate' => 'first')); $result = $model->saveAll($data, array('validate' => 'first', 'deep' => true));
$this->assertTrue($result); $this->assertTrue($result);
$this->assertEquals('foo', $model->field('title', array('body' => 'foo1')));
$this->assertEquals('foo', $model->field('title', array('body' => 'foo2'))); $this->assertEquals('foo', $model->field('title', array('body' => 'foo2')));
$this->assertEquals('foo', $model->field('title', array('body' => 'foo3'))); $this->assertEquals('foo', $model->field('title', array('body' => 'foo3')));
$this->assertEquals('foo', $model->field('title', array('body' => 'foo4')));
} }
/** /**
@ -1948,7 +1959,7 @@ class ModelValidationTest extends BaseModelTest {
* *
* @return void * @return void
*/ */
public function testValidateAssociatedWithBeforeValidate() { public function testValidateFirstAssociatedWithBeforeValidate() {
$this->loadFixtures('Article', 'User'); $this->loadFixtures('Article', 'User');
$model = new CustomArticle(); $model = new CustomArticle();
$model->validate = array( $model->validate = array(
@ -1978,5 +1989,49 @@ class ModelValidationTest extends BaseModelTest {
$this->assertEquals('foo', $model->field('title', array('body' => 'foo3'))); $this->assertEquals('foo', $model->field('title', array('body' => 'foo3')));
} }
/**
* testValidateFirstWithDefaults method
*
* return @void
*/
public function testFirstWithDefaults() {
$this->loadFixtures('Article', 'Tag', 'Comment', 'User', 'ArticlesTag');
$TestModel = new Article();
$result = $TestModel->find('first', array(
'conditions' => array('Article.id' => 1)
));
$expected = array(
'Article' => array(
'id' => 1,
'user_id' => 1,
'title' => 'First Article',
'body' => 'First Article Body',
'published' => 'Y',
'created' => '2007-03-18 10:39:23'
),
);
unset($result['Article']['updated']);
$this->assertEquals($expected['Article'], $result['Article']);
$data = array(
'Article' => array(
'id' => 1,
'title' => 'First Article (modified)'
),
'Comment' => array(
array('comment' => 'Article comment', 'user_id' => 1)
)
);
$result = $TestModel->saveAll($data, array('validate' => 'first'));
$this->assertTrue($result);
$result = $TestModel->find('first', array(
'conditions' => array('Article.id' => 1)
));
$expected['Article']['title'] = 'First Article (modified)';
unset($result['Article']['updated']);
$this->assertEquals($expected['Article'], $result['Article']);
}
} }

View file

@ -4267,7 +4267,7 @@ class ModelWriteTest extends BaseModelTest {
'author_id' => '3', 'author_id' => '3',
'title' => 'Just update the title', 'title' => 'Just update the title',
'body' => 'Second Post Body', 'body' => 'Second Post Body',
'published' => 'N', 'published' => 'Y',
'created' => '2007-03-18 10:41:23' 'created' => '2007-03-18 10:41:23'
)), )),
array( array(
@ -4356,7 +4356,7 @@ class ModelWriteTest extends BaseModelTest {
'author_id' => '3', 'author_id' => '3',
'title' => 'Just update the title', 'title' => 'Just update the title',
'body' => 'Second Post Body', 'body' => 'Second Post Body',
'published' => 'N', 'published' => 'Y',
'created' => '2007-03-18 10:41:23' 'created' => '2007-03-18 10:41:23'
) )
), ),
@ -4725,7 +4725,7 @@ class ModelWriteTest extends BaseModelTest {
'password' => '5f4dcc3b5aa765d61d8327deb882cf90' 'password' => '5f4dcc3b5aa765d61d8327deb882cf90'
))); )));
$result = $TestModel->find('all'); $result = $TestModel->find('all', array('order' => array('Post.id ' => 'ASC')));
$expected = array( $expected = array(
'Post' => array( 'Post' => array(
'id' => '4', 'id' => '4',
@ -5623,7 +5623,7 @@ class ModelWriteTest extends BaseModelTest {
'author_id' => '3', 'author_id' => '3',
'title' => 'Just update the title', 'title' => 'Just update the title',
'body' => 'Second Post Body', 'body' => 'Second Post Body',
'published' => 'N', 'published' => 'Y',
'created' => '2007-03-18 10:41:23' 'created' => '2007-03-18 10:41:23'
) )
), ),
@ -5719,7 +5719,7 @@ class ModelWriteTest extends BaseModelTest {
'author_id' => '3', 'author_id' => '3',
'title' => 'Just update the title', 'title' => 'Just update the title',
'body' => 'Second Post Body', 'body' => 'Second Post Body',
'published' => 'N', 'published' => 'Y',
)), )),
array( array(
'Post' => array( 'Post' => array(

View file

@ -3119,7 +3119,7 @@ class TranslatedItem2 extends CakeTestModel {
/** /**
* translateModel property * translateModel property
* *
* @var string * @var string
*/ */
public $translateModel = 'TranslateWithPrefix'; public $translateModel = 'TranslateWithPrefix';
@ -4975,6 +4975,11 @@ class CustomArticle extends AppModel {
**/ **/
public function beforeValidate($options = array()) { public function beforeValidate($options = array()) {
$this->data[$this->alias]['title'] = 'foo'; $this->data[$this->alias]['title'] = 'foo';
if ($this->findMethods['unPublished'] === true) {
$this->findMethods['unPublished'] = false;
} else {
$this->findMethods['unPublished'] = 'true again';
}
} }
} }

View file

@ -140,8 +140,8 @@ class DebuggerTest extends CakeTestCase {
'a' => array( 'a' => array(
'href' => "javascript:void(0);", 'href' => "javascript:void(0);",
'onclick' => "preg:/document\.getElementById\('cakeErr[a-z0-9]+\-trace'\)\.style\.display = " . 'onclick' => "preg:/document\.getElementById\('cakeErr[a-z0-9]+\-trace'\)\.style\.display = " .
"\(document\.getElementById\('cakeErr[a-z0-9]+\-trace'\)\.style\.display == 'none'" . "\(document\.getElementById\('cakeErr[a-z0-9]+\-trace'\)\.style\.display == 'none'" .
" \? '' \: 'none'\);/" " \? '' \: 'none'\);/"
), ),
'b' => array(), 'Notice', '/b', ' (8)', 'b' => array(), 'Notice', '/b', ' (8)',
)); ));
@ -149,6 +149,7 @@ class DebuggerTest extends CakeTestCase {
$this->assertRegExp('/Undefined variable:\s+buzz/', $result[1]); $this->assertRegExp('/Undefined variable:\s+buzz/', $result[1]);
$this->assertRegExp('/<a[^>]+>Code/', $result[1]); $this->assertRegExp('/<a[^>]+>Code/', $result[1]);
$this->assertRegExp('/<a[^>]+>Context/', $result[2]); $this->assertRegExp('/<a[^>]+>Context/', $result[2]);
$this->assertContains('$wrong = &#039;&#039;', $result[3], 'Context should be HTML escaped.');
} }
/** /**
@ -162,14 +163,14 @@ class DebuggerTest extends CakeTestCase {
Debugger::output('js', array( Debugger::output('js', array(
'traceLine' => '{:reference} - <a href="txmt://open?url=file://{:file}' . 'traceLine' => '{:reference} - <a href="txmt://open?url=file://{:file}' .
'&line={:line}">{:path}</a>, line {:line}' '&line={:line}">{:path}</a>, line {:line}'
)); ));
$result = Debugger::trace(); $result = Debugger::trace();
$this->assertRegExp('/' . preg_quote('txmt://open?url=file://', '/') . '(\/|[A-Z]:\\\\)' . '/', $result); $this->assertRegExp('/' . preg_quote('txmt://open?url=file://', '/') . '(\/|[A-Z]:\\\\)' . '/', $result);
Debugger::output('xml', array( Debugger::output('xml', array(
'error' => '<error><code>{:code}</code><file>{:file}</file><line>{:line}</line>' . 'error' => '<error><code>{:code}</code><file>{:file}</file><line>{:line}</line>' .
'{:description}</error>', '{:description}</error>',
'context' => "<context>{:context}</context>", 'context' => "<context>{:context}</context>",
'trace' => "<stack>{:trace}</stack>", 'trace' => "<stack>{:trace}</stack>",
)); ));
@ -361,10 +362,10 @@ TEXT;
$this->assertRegExp('/DebuggerTest\:\:testLog/i', $result); $this->assertRegExp('/DebuggerTest\:\:testLog/i', $result);
$this->assertRegExp("/'cool'/", $result); $this->assertRegExp("/'cool'/", $result);
unlink(TMP . 'logs' . DS . 'debug.log'); unlink(LOGS . 'debug.log');
Debugger::log(array('whatever', 'here')); Debugger::log(array('whatever', 'here'));
$result = file_get_contents(TMP . 'logs' . DS . 'debug.log'); $result = file_get_contents(LOGS . 'debug.log');
$this->assertRegExp('/DebuggerTest\:\:testLog/i', $result); $this->assertRegExp('/DebuggerTest\:\:testLog/i', $result);
$this->assertRegExp('/\[main\]/', $result); $this->assertRegExp('/\[main\]/', $result);
$this->assertRegExp('/array/', $result); $this->assertRegExp('/array/', $result);

View file

@ -291,15 +291,14 @@ class CacheHelperTest extends CakeTestCase {
*/ */
public function testCacheViewVars() { public function testCacheViewVars() {
$this->Controller->cache_parsing(); $this->Controller->cache_parsing();
$this->Controller->params = array( $this->Controller->request->addParams(array(
'controller' => 'cache_test', 'controller' => 'cache_test',
'action' => 'cache_parsing', 'action' => 'cache_parsing',
'pass' => array(), 'pass' => array(),
'named' => array() 'named' => array()
); ));
$this->Controller->request->here = '/cacheTest/cache_parsing';
$this->Controller->cacheAction = 21600; $this->Controller->cacheAction = 21600;
$this->Controller->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller); $View = new View($this->Controller);
$result = $View->render('index'); $result = $View->render('index');
@ -323,21 +322,20 @@ class CacheHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testCacheCallbacks() { public function testCacheCallbacks() {
$this->Controller->cache_parsing(); $this->Controller->request->addParams(array(
$this->Controller->params = array(
'controller' => 'cache_test', 'controller' => 'cache_test',
'action' => 'cache_parsing', 'action' => 'cache_parsing',
'pass' => array(), 'pass' => array(),
'named' => array() 'named' => array()
); ));
$this->Controller->cacheAction = array( $this->Controller->cacheAction = array(
'cache_parsing' => array( 'cache_parsing' => array(
'duration' => 21600, 'duration' => 21600,
'callbacks' => true 'callbacks' => true
) )
); );
$this->Controller->here = '/cacheTest/cache_parsing'; $this->Controller->request->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing'; $this->Controller->cache_parsing();
$View = new View($this->Controller); $View = new View($this->Controller);
$result = $View->render('index'); $result = $View->render('index');
@ -358,18 +356,18 @@ class CacheHelperTest extends CakeTestCase {
* @return void * @return void
*/ */
public function testCacheActionArray() { public function testCacheActionArray() {
$this->Controller->cache_parsing();
$this->Controller->request->addParams(array( $this->Controller->request->addParams(array(
'controller' => 'cache_test', 'controller' => 'cache_test',
'action' => 'cache_parsing', 'action' => 'cache_parsing',
'pass' => array(), 'pass' => array(),
'named' => array() 'named' => array()
)); ));
$this->Controller->request->here = '/cache_test/cache_parsing';
$this->Controller->cacheAction = array( $this->Controller->cacheAction = array(
'cache_parsing' => 21600 'cache_parsing' => 21600
); );
$this->Controller->request->here = '/cache_test/cache_parsing';
$this->Controller->action = 'cache_parsing'; $this->Controller->cache_parsing();
$View = new View($this->Controller); $View = new View($this->Controller);
$result = $View->render('index'); $result = $View->render('index');
@ -380,13 +378,25 @@ class CacheHelperTest extends CakeTestCase {
$filename = CACHE . 'views' . DS . 'cache_test_cache_parsing.php'; $filename = CACHE . 'views' . DS . 'cache_test_cache_parsing.php';
$this->assertTrue(file_exists($filename)); $this->assertTrue(file_exists($filename));
@unlink($filename); @unlink($filename);
}
$this->Controller->cache_parsing(); /**
* Test that cacheAction works with camelcased controller names.
*
* @return void
*/
public function testCacheActionArrayCamelCase() {
$this->Controller->request->addParams(array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'pass' => array(),
'named' => array()
));
$this->Controller->cacheAction = array( $this->Controller->cacheAction = array(
'cache_parsing' => 21600 'cache_parsing' => 21600
); );
$this->Controller->request->here = '/cacheTest/cache_parsing'; $this->Controller->request->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing'; $this->Controller->cache_parsing();
$View = new View($this->Controller); $View = new View($this->Controller);
$result = $View->render('index'); $result = $View->render('index');
@ -397,28 +407,6 @@ class CacheHelperTest extends CakeTestCase {
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php'; $filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
$this->assertTrue(file_exists($filename)); $this->assertTrue(file_exists($filename));
@unlink($filename); @unlink($filename);
$this->Controller->cache_parsing();
$this->Controller->request->addParams(array(
'controller' => 'cache_test',
'action' => 'cache_parsing',
'pass' => array(),
'named' => array()
));
$this->Controller->cacheAction = array(
'some_other_action' => 21600
);
$this->Controller->request->here = '/cacheTest/cache_parsing';
$this->Controller->action = 'cache_parsing';
$View = new View($this->Controller);
$result = $View->render('index');
$this->assertNotRegExp('/cake:nocache/', $result);
$this->assertNotRegExp('/php echo/', $result);
$filename = CACHE . 'views' . DS . 'cachetest_cache_parsing.php';
$this->assertFalse(file_exists($filename));
} }
/** /**

View file

@ -63,11 +63,13 @@ class Debugger {
'trace' => '<pre class="stack-trace">{:trace}</pre>', 'trace' => '<pre class="stack-trace">{:trace}</pre>',
'code' => '', 'code' => '',
'context' => '', 'context' => '',
'links' => array() 'links' => array(),
'escapeContext' => true,
), ),
'html' => array( 'html' => array(
'trace' => '<pre class="cake-error trace"><b>Trace</b> <p>{:trace}</p></pre>', 'trace' => '<pre class="cake-error trace"><b>Trace</b> <p>{:trace}</p></pre>',
'context' => '<pre class="cake-error context"><b>Context</b> <p>{:context}</p></pre>' 'context' => '<pre class="cake-error context"><b>Context</b> <p>{:context}</p></pre>',
'escapeContext' => true,
), ),
'txt' => array( 'txt' => array(
'error' => "{:error}: {:code} :: {:description} on line {:line} of {:path}\n{:info}", 'error' => "{:error}: {:code} :: {:description} on line {:line} of {:path}\n{:info}",
@ -716,7 +718,7 @@ class Debugger {
$info = ''; $info = '';
foreach ((array)$data['context'] as $var => $value) { foreach ((array)$data['context'] as $var => $value) {
$context[] = "\${$var}\t=\t" . $this->exportVar($value, 1); $context[] = "\${$var} = " . $this->exportVar($value, 1);
} }
switch ($this->_outputFormat) { switch ($this->_outputFormat) {
@ -731,30 +733,29 @@ class Debugger {
$data['trace'] = $trace; $data['trace'] = $trace;
$data['id'] = 'cakeErr' . uniqid(); $data['id'] = 'cakeErr' . uniqid();
$tpl = array_merge($this->_templates['base'], $this->_templates[$this->_outputFormat]); $tpl = array_merge($this->_templates['base'], $this->_templates[$this->_outputFormat]);
$insert = array('context' => join("\n", $context)) + $data;
$detect = array('context');
if (isset($tpl['links'])) { if (isset($tpl['links'])) {
foreach ($tpl['links'] as $key => $val) { foreach ($tpl['links'] as $key => $val) {
if (in_array($key, $detect) && empty($insert[$key])) { $links[$key] = String::insert($val, $data, $insertOpts);
continue;
}
$links[$key] = String::insert($val, $insert, $insertOpts);
} }
} }
foreach (array('code', 'context', 'trace') as $key) { if (!empty($tpl['escapeContext'])) {
if (empty($$key) || !isset($tpl[$key])) { $context = h($context);
}
$infoData = compact('code', 'context', 'trace');
foreach ($infoData as $key => $value) {
if (empty($value) || !isset($tpl[$key])) {
continue; continue;
} }
if (is_array($$key)) { if (is_array($value)) {
$$key = join("\n", $$key); $value = join("\n", $value);
} }
$info .= String::insert($tpl[$key], compact($key) + $insert, $insertOpts); $info .= String::insert($tpl[$key], array($key => $value) + $data, $insertOpts);
} }
$links = join(' ', $links); $links = join(' ', $links);
unset($data['context']);
if (isset($tpl['callback']) && is_callable($tpl['callback'])) { if (isset($tpl['callback']) && is_callable($tpl['callback'])) {
return call_user_func($tpl['callback'], $data, compact('links', 'info')); return call_user_func($tpl['callback'], $data, compact('links', 'info'));
} }

View file

@ -332,8 +332,10 @@ class View extends Object {
* @return CakeEventManager * @return CakeEventManager
*/ */
public function getEventManager() { public function getEventManager() {
if (empty($this->_eventManager) || !$this->_eventManagerConfigured) { if (empty($this->_eventManager)) {
$this->_eventManager = new CakeEventManager(); $this->_eventManager = new CakeEventManager();
}
if (!$this->_eventManagerConfigured) {
$this->_eventManager->attach($this->Helpers); $this->_eventManager->attach($this->Helpers);
$this->_eventManagerConfigured = true; $this->_eventManagerConfigured = true;
} }