Permalink
Browse files

merging 1.3-misc into master

  • Loading branch information...
1 parent 1f7eb18 commit 15518b8c9ac6e022eda29cd907b8f1fe3537a188 gwoo committed May 1, 2009
View
1 .gitignore
@@ -1,2 +1,3 @@
+app/config
app/tmp
vendors
View
15 app/config/database.php.default
@@ -1,28 +1,23 @@
<?php
-/* SVN FILE: $Id$ */
/**
* This is core configuration file.
*
* Use it to configure core behaviour ofCake.
*
* PHP versions 4 and 5
*
- * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
- * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
- * @filesource
- * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
- * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org
* @package cake
* @subpackage cake.app.config
* @since CakePHP(tm) v 0.2.9
- * @version $Revision$
- * @modifiedby $LastChangedBy$
- * @lastmodified $Date$
- * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* In this file you set up your database connection details.
View
19 app/webroot/index.php
@@ -1,27 +1,22 @@
<?php
-/* SVN FILE: $Id$ */
/**
- * Short description for file.
+ * Index
*
- * Long description for file
+ * The Front Controller for handling every request
*
* PHP versions 4 and 5
*
- * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
- * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
- * @filesource
- * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
- * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org
* @package cake
* @subpackage cake.app.webroot
* @since CakePHP(tm) v 0.2.9
- * @version $Revision$
- * @modifiedby $LastChangedBy$
- * @lastmodified $Date$
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*/
/**
@@ -85,7 +80,7 @@
return;
} else {
$Dispatcher = new Dispatcher();
- $Dispatcher->dispatch($url);
+ $Dispatcher->dispatch();
}
if (Configure::read() > 0) {
echo "<!-- " . round(getMicrotime() - $TIME_START, 4) . "s -->";
View
45 cake/bootstrap.php
@@ -1,48 +1,35 @@
<?php
-/* SVN FILE: $Id$ */
/**
* Basic Cake functionality.
*
- * Core functions for including other source files, loading models and so forth.
+ * Handles loading of core files needed on every request
*
* PHP versions 4 and 5
*
- * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
- * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
- * @filesource
- * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
- * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org
* @package cake
* @subpackage cake.cake
* @since CakePHP(tm) v 0.2.9
- * @version $Revision$
- * @modifiedby $LastChangedBy$
- * @lastmodified $Date$
- * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
if (!defined('PHP5')) {
define('PHP5', (PHP_VERSION >= 5));
}
-/**
- * Configuration, directory layout and standard libraries
- */
- if (!isset($bootstrap)) {
- require CORE_PATH . 'cake' . DS . 'basics.php';
- $TIME_START = getMicrotime();
- require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php';
- require LIBS . 'object.php';
- require LIBS . 'inflector.php';
- require LIBS . 'configure.php';
- }
- require LIBS . 'cache.php';
-
- Configure::getInstance();
-
- $url = null;
-
- App::import('Core', array('Dispatcher'));
+require CORE_PATH . 'cake' . DS . 'basics.php';
+$TIME_START = getMicrotime();
+require CORE_PATH . 'cake' . DS . 'config' . DS . 'paths.php';
+require LIBS . 'object.php';
+require LIBS . 'inflector.php';
+require LIBS . 'configure.php';
+require LIBS . 'set.php';
+require LIBS . 'cache.php';
+Configure::getInstance();
+require CAKE . 'dispatcher.php';
?>
View
2 cake/console/libs/tasks/controller.php
@@ -375,7 +375,7 @@ function bakeActions($controllerName, $admin = null, $wannaUseSession = true) {
$actions .= "\t\t\t\$this->flash(__('Invalid {$singularHumanName}', true), array('action'=>'index'));\n";
}
$actions .= "\t\t}\n";
- $actions .= "\t\tif (\$this->{$currentModelName}->del(\$id)) {\n";
+ $actions .= "\t\tif (\$this->{$currentModelName}->delete(\$id)) {\n";
if ($wannaUseSession) {
$actions .= "\t\t\t\$this->Session->setFlash(__('{$singularHumanName} deleted', true));\n";
$actions .= "\t\t\t\$this->redirect(array('action'=>'index'));\n";
View
96 cake/libs/controller/controller.php
@@ -1,26 +1,21 @@
<?php
-/* SVN FILE: $Id$ */
/**
* Base controller class.
*
* PHP versions 4 and 5
*
- * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
- * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
- * @filesource
- * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
- * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org
* @package cake
* @subpackage cake.cake.libs.controller
* @since CakePHP(tm) v 0.2.9
- * @version $Revision$
- * @modifiedby $LastChangedBy$
- * @lastmodified $Date$
- * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Include files
@@ -55,7 +50,7 @@ class Controller extends Object {
*/
var $here = null;
/**
- * The webroot of the application. Helpful if your application is placed in a folder under the current domain name.
+ * The webroot of the application.
*
* @var string
* @access public
@@ -292,7 +287,7 @@ class Controller extends Object {
*/
var $methods = array();
/**
- * This controller's primary model class name, the Inflector::classify()'ed version of
+ * This controller's primary model class name, the Inflector::classify()'ed version of
* the controller's $name property.
*
* Example: For a controller named 'Comments', the modelClass would be 'Comment'
@@ -325,7 +320,8 @@ function __construct() {
if ($this->name === null) {
$r = null;
if (!preg_match('/(.*)Controller/i', get_class($this), $r)) {
- die (__("Controller::__construct() : Can not get or parse my own class name, exiting."));
+ __("Controller::__construct() : Can not get or parse my own class name, exiting.");
+ $this->_stop();
}
$this->name = $r[1];
}
@@ -395,7 +391,9 @@ function __mergeVars() {
$app = Set::normalize($appVars[$var]);
$this->{$var} = Set::merge($app, $normal);
} else {
- $this->{$var} = Set::merge($this->{$var}, array_diff($appVars[$var], $this->{$var}));
+ $this->{$var} = Set::merge(
+ $this->{$var}, array_diff($appVars[$var], $this->{$var})
+ );
}
}
}
@@ -417,7 +415,9 @@ function __mergeVars() {
$app = Set::normalize($appVars[$var]);
$this->{$var} = Set::merge($normal, array_diff_assoc($app, $normal));
} else {
- $this->{$var} = Set::merge($this->{$var}, array_diff($appVars[$var], $this->{$var}));
+ $this->{$var} = Set::merge(
+ $this->{$var}, array_diff($appVars[$var], $this->{$var})
+ );
}
}
}
@@ -462,7 +462,7 @@ function constructClasses() {
}
/**
* Loads and instantiates models required by this controller.
- * If Controller::persistModel; is true, controller will create cached model instances on first request,
+ * If Controller::persistModel; is true, controller will cache model instances on first request,
* additional request will used cached models.
* If the model is non existent, it will throw a missing database table error, as Cake generates
* dynamic models for the time being.
@@ -498,13 +498,19 @@ function loadModel($modelClass = null, $id = null) {
$this->modelNames[] = $modelClass;
if (!PHP5) {
- $this->{$modelClass} =& ClassRegistry::init(array('class' => $plugin . $modelClass, 'alias' => $modelClass, 'id' => $id));
+ $this->{$modelClass} =& ClassRegistry::init(array(
+ 'class' => $plugin . $modelClass, 'alias' => $modelClass, 'id' => $id
+ ));
} else {
- $this->{$modelClass} = ClassRegistry::init(array('class' => $plugin . $modelClass, 'alias' => $modelClass, 'id' => $id));
+ $this->{$modelClass} = ClassRegistry::init(array(
+ 'class' => $plugin . $modelClass, 'alias' => $modelClass, 'id' => $id
+ ));
}
if (!$this->{$modelClass}) {
- return $this->cakeError('missingModel', array(array('className' => $modelClass, 'webroot' => '', 'base' => $this->base)));
+ return $this->cakeError('missingModel', array(array(
+ 'className' => $modelClass, 'webroot' => '', 'base' => $this->base
+ )));
}
if ($this->persistModel === true) {
@@ -522,7 +528,8 @@ function loadModel($modelClass = null, $id = null) {
* Redirects to given $url, after turning off $this->autoRender.
* Script execution is halted after the redirect.
*
- * @param mixed $url A string or array-based URL pointing to another location within the app, or an absolute URL
+ * @param mixed $url A string or array-based URL pointing to another location within the app,
+ * or an absolute URL
* @param integer $status Optional HTTP status code (eg: 404)
* @param boolean $exit If true, exit() will be called after the redirect
* @return mixed void if $exit = false. Terminates script if $exit = true
@@ -689,14 +696,17 @@ function setAction($action) {
return call_user_func_array(array(&$this, $action), $args);
}
/**
- * Controller callback to tie into Auth component. Only called when AuthComponent::authorize is set to 'controller'.
+ * Controller callback to tie into Auth component.
+ * Only called when AuthComponent::authorize is set to 'controller'.
*
* @return bool true if authorized, false otherwise
* @access public
* @link http://book.cakephp.org/view/396/authorize
*/
function isAuthorized() {
- trigger_error(sprintf(__('%s::isAuthorized() is not defined.', true), $this->name), E_USER_WARNING);
+ trigger_error(sprintf(
+ __('%s::isAuthorized() is not defined.', true), $this->name
+ ), E_USER_WARNING);
return false;
}
/**
@@ -776,16 +786,22 @@ function render($action = null, $layout = null, $file = null) {
if (isset($this->$currentModel) && is_a($this->$currentModel, 'Model')) {
$models[] = Inflector::underscore($currentModel);
}
- if (isset($this->$currentModel) && is_a($this->$currentModel, 'Model') && !empty($this->$currentModel->validationErrors)) {
- $View->validationErrors[Inflector::camelize($currentModel)] =& $this->$currentModel->validationErrors;
+ $isValidModel = (
+ isset($this->$currentModel) && is_a($this->$currentModel, 'Model') &&
+ !empty($this->$currentModel->validationErrors)
+ );
+ if ($isValidModel) {
+ $View->validationErrors[Inflector::camelize($currentModel)] =&
+ $this->$currentModel->validationErrors;
}
}
$models = array_diff(ClassRegistry::keys(), $models);
foreach ($models as $currentModel) {
if (ClassRegistry::isKeySet($currentModel)) {
$currentObject =& ClassRegistry::getObject($currentModel);
if (is_a($currentObject, 'Model') && !empty($currentObject->validationErrors)) {
- $View->validationErrors[Inflector::camelize($currentModel)] =& $currentObject->validationErrors;
+ $View->validationErrors[Inflector::camelize($currentModel)] =&
+ $currentObject->validationErrors;
}
}
}
@@ -821,7 +837,8 @@ function referer($default = null, $local = false) {
}
if ($default != null) {
- return $default;
+ $url = Router::url($default, true);
+ return $url;
}
return '/';
}
@@ -863,9 +880,11 @@ function flash($message, $url, $pause = 1) {
* Converts POST'ed form data to a model conditions array, suitable for use in a Model::find() call.
*
* @param array $data POST'ed data organized by model and field
- * @param mixed $op A string containing an SQL comparison operator, or an array matching operators to fields
+ * @param mixed $op A string containing an SQL comparison operator, or an array matching operators
+ * to fields
* @param string $bool SQL boolean operator: AND, OR, XOR, etc.
- * @param boolean $exclusive If true, and $op is an array, fields not included in $op will not be included in the returned conditions
+ * @param boolean $exclusive If true, and $op is an array, fields not included in $op will not be
+ * included in the returned conditions
* @return array An array of model conditions
* @access public
* @link http://book.cakephp.org/view/432/postConditions
@@ -940,11 +959,16 @@ function paginate($object = null, $scope = array(), $whitelist = array()) {
if ($assoc && isset($this->{$object}->{$assoc})) {
$object = $this->{$object}->{$assoc};
- } elseif ($assoc && isset($this->{$this->modelClass}) && isset($this->{$this->modelClass}->{$assoc})) {
+ } elseif (
+ $assoc && isset($this->{$this->modelClass}) &&
+ isset($this->{$this->modelClass}->{$assoc}
+ )) {
$object = $this->{$this->modelClass}->{$assoc};
} elseif (isset($this->{$object})) {
$object = $this->{$object};
- } elseif (isset($this->{$this->modelClass}) && isset($this->{$this->modelClass}->{$object})) {
+ } elseif (
+ isset($this->{$this->modelClass}) && isset($this->{$this->modelClass}->{$object}
+ )) {
$object = $this->{$this->modelClass}->{$object};
}
} elseif (empty($object) || $object === null) {
@@ -965,7 +989,11 @@ function paginate($object = null, $scope = array(), $whitelist = array()) {
}
if (!is_object($object)) {
- trigger_error(sprintf(__('Controller::paginate() - can\'t find model %1$s in controller %2$sController', true), $object, $this->name), E_USER_WARNING);
+ trigger_error(sprintf(
+ __('Controller::paginate() - can\'t find model %1$s in controller %2$sController',
+ true
+ ), $object, $this->name
+ ), E_USER_WARNING);
return array();
}
$options = array_merge($this->params, $this->params['url'], $this->passedArgs);
@@ -1071,7 +1099,9 @@ function paginate($object = null, $scope = array(), $whitelist = array()) {
$page = $options['page'] = (integer)$page;
if (method_exists($object, 'paginate')) {
- $results = $object->paginate($conditions, $fields, $order, $limit, $page, $recursive, $extra);
+ $results = $object->paginate(
+ $conditions, $fields, $order, $limit, $page, $recursive, $extra
+ );
} else {
$parameters = compact('conditions', 'fields', 'order', 'limit', 'page');
if ($recursive != $object->recursive) {
@@ -1167,4 +1197,4 @@ function _scaffoldError($method) {
return false;
}
}
-?>
+?>
View
176 cake/libs/controller/scaffold.php
@@ -1,31 +1,26 @@
<?php
-/* SVN FILE: $Id$ */
/**
* Scaffold.
*
* Automatic forms and actions generation for rapid web application development.
*
* PHP versions 4 and 5
*
- * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
- * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
- * @filesource
- * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
- * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org
* @package cake
* @subpackage cake.cake.libs.controller
* @since Cake v 0.10.0.1076
- * @version $Revision$
- * @modifiedby $LastChangedBy$
- * @lastmodified $Date$
- * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
- * Scaffolding is a set of automatic views, forms and controllers for starting web development work faster.
+ * Scaffolding is a set of automatic actions for starting web development work faster.
*
* Scaffold inspects your database tables, and making educated guesses, sets up a
* number of pages for each of your Models. These pages have data forms that work,
@@ -114,12 +109,22 @@ class Scaffold extends Object {
*/
var $plugin = null;
/**
+ * valid session.
+ *
+ * @var boolean
+ * @access public
+ */
+ var $_validSession = null;
+/**
* List of variables to collect from the associated controller
*
* @var array
* @access private
*/
- var $__passedVars = array('action', 'base', 'webroot', 'layout', 'name', 'viewPath', 'ext', 'params', 'data', 'plugin', 'cacheAction');
+ var $__passedVars = array(
+ 'action', 'base', 'webroot', 'layout', 'name',
+ 'viewPath', 'ext', 'params', 'data', 'plugin', 'cacheAction'
+ );
/**
* Title HTML element for current scaffolded view
*
@@ -148,14 +153,16 @@ function __construct(&$controller, $params) {
$this->modelKey = $controller->modelKey;
if (!is_object($this->controller->{$this->modelClass})) {
- return $this->cakeError('missingModel', array(array('className' => $this->modelClass, 'webroot' => '', 'base' => $controller->base)));
+ return $this->cakeError('missingModel', array(array(
+ 'className' => $this->modelClass, 'webroot' => '', 'base' => $controller->base
+ )));
}
$this->ScaffoldModel =& $this->controller->{$this->modelClass};
$this->scaffoldTitle = Inflector::humanize($this->viewPath);
$this->scaffoldActions = $controller->scaffold;
- $this->controller->pageTitle = __('Scaffold :: ', true) . Inflector::humanize($this->action) . ' :: ' . $this->scaffoldTitle;
-
+ $this->controller->pageTitle = __('Scaffold :: ', true)
+ . Inflector::humanize($this->action) . ' :: ' . $this->scaffoldTitle;
$modelClass = $this->controller->modelClass;
$primaryKey = $this->ScaffoldModel->primaryKey;
$displayField = $this->ScaffoldModel->displayField;
@@ -166,13 +173,18 @@ function __construct(&$controller, $params) {
$scaffoldFields = array_keys($this->ScaffoldModel->schema());
$associations = $this->__associations();
- $this->controller->set(compact('modelClass', 'primaryKey', 'displayField', 'singularVar', 'pluralVar',
- 'singularHumanName', 'pluralHumanName', 'scaffoldFields', 'associations'));
+ $this->controller->set(compact(
+ 'modelClass', 'primaryKey', 'displayField', 'singularVar', 'pluralVar',
+ 'singularHumanName', 'pluralHumanName', 'scaffoldFields', 'associations'
+ ));
if ($this->controller->view && $this->controller->view !== 'Theme') {
$this->controller->view = 'scaffold';
}
$this->__scaffold($params);
+ $this->_validSession = (
+ isset($this->controller->Session) && $this->controller->Session->valid() != false
+ );
}
/**
* Outputs the content of a scaffold method passing it through the Controller::afterFilter()
@@ -196,16 +208,23 @@ function __scaffoldView($params) {
if (isset($params['pass'][0])) {
$this->ScaffoldModel->id = $params['pass'][0];
- } elseif (isset($this->controller->Session) && $this->controller->Session->valid() != false) {
- $this->controller->Session->setFlash(sprintf(__("No id set for %s::view()", true), Inflector::humanize($this->modelKey)));
+ } elseif ($this->_validSession) {
+ $this->controller->Session->setFlash(sprintf(
+ __("No id set for %s::view()", true),
+ Inflector::humanize($this->modelKey
+ )));
$this->controller->redirect($this->redirect);
} else {
- return $this->controller->flash(sprintf(__("No id set for %s::view()", true), Inflector::humanize($this->modelKey)),
- '/' . Inflector::underscore($this->controller->viewPath));
+ return $this->controller->flash(sprintf(
+ __("No id set for %s::view()", true), Inflector::humanize($this->modelKey)),
+ '/' . Inflector::underscore($this->controller->viewPath
+ ));
}
$this->ScaffoldModel->recursive = 1;
$this->controller->data = $this->ScaffoldModel->read();
- $this->controller->set(Inflector::variable($this->controller->modelClass), $this->controller->data);
+ $this->controller->set(
+ Inflector::variable($this->controller->modelClass), $this->controller->data
+ );
$this->controller->render($this->action, $this->layout);
$this->_output();
} elseif ($this->controller->_scaffoldError('view') === false) {
@@ -222,7 +241,9 @@ function __scaffoldView($params) {
function __scaffoldIndex($params) {
if ($this->controller->_beforeScaffold('index')) {
$this->ScaffoldModel->recursive = 0;
- $this->controller->set(Inflector::variable($this->controller->name), $this->controller->paginate());
+ $this->controller->set(
+ Inflector::variable($this->controller->name), $this->controller->paginate()
+ );
$this->controller->render($this->action, $this->layout);
$this->_output();
} elseif ($this->controller->_scaffoldError('index') === false) {
@@ -263,11 +284,17 @@ function __scaffoldSave($params = array(), $action = 'edit') {
}
if (!$this->ScaffoldModel->exists()) {
- if (isset($this->controller->Session) && $this->controller->Session->valid() != false) {
- $this->controller->Session->setFlash(sprintf(__("Invalid id for %s::edit()", true), Inflector::humanize($this->modelKey)));
+ if ($this->_validSession) {
+ $this->controller->Session->setFlash(sprintf(
+ __("Invalid id for %s::edit()", true),
+ Inflector::humanize($this->modelKey)
+ ));
$this->controller->redirect($this->redirect);
} else {
- return $this->controller->flash(sprintf(__("Invalid id for %s::edit()", true), Inflector::humanize($this->modelKey)), $this->redirect);
+ return $this->controller->flash(sprintf(
+ __("Invalid id for %s::edit()", true),
+ Inflector::humanize($this->modelKey)
+ ), $this->redirect);
}
}
}
@@ -279,18 +306,26 @@ function __scaffoldSave($params = array(), $action = 'edit') {
if ($this->ScaffoldModel->save($this->controller->data)) {
if ($this->controller->_afterScaffoldSave($action)) {
- if (isset($this->controller->Session) && $this->controller->Session->valid() != false) {
- $this->controller->Session->setFlash(sprintf(__('The %1$s has been %2$s', true), Inflector::humanize($this->modelClass), $success));
+ if ($this->_validSession) {
+ $this->controller->Session->setFlash(sprintf(
+ __('The %1$s has been %2$s', true),
+ Inflector::humanize($this->modelClass), $success
+ ));
$this->controller->redirect($this->redirect);
} else {
- return $this->controller->flash(sprintf(__('The %1$s has been %2$s', true), Inflector::humanize($this->modelClass), $success), $this->redirect);
+ return $this->controller->flash(sprintf(
+ __('The %1$s has been %2$s', true),
+ Inflector::humanize($this->modelClass), $success
+ ), $this->redirect);
}
} else {
return $this->controller->_afterScaffoldSaveError($action);
}
} else {
- if (isset($this->controller->Session) && $this->controller->Session->valid() != false) {
- $this->controller->Session->setFlash(__('Please correct errors below.', true));
+ if ($this->_validSession) {
+ $this->controller->Session->setFlash(
+ __('Please correct errors below.', true
+ ));
}
}
}
@@ -304,7 +339,9 @@ function __scaffoldSave($params = array(), $action = 'edit') {
}
foreach ($this->ScaffoldModel->belongsTo as $assocName => $assocData) {
- $varName = Inflector::variable(Inflector::pluralize(preg_replace('/(?:_id)$/', '', $assocData['foreignKey'])));
+ $varName = Inflector::variable(Inflector::pluralize(
+ preg_replace('/(?:_id)$/', '', $assocData['foreignKey'])
+ ));
$this->controller->set($varName, $this->ScaffoldModel->{$assocName}->find('list'));
}
foreach ($this->ScaffoldModel->hasAndBelongsToMany as $assocName => $assocData) {
@@ -328,27 +365,42 @@ function __scaffoldDelete($params = array()) {
if ($this->controller->_beforeScaffold('delete')) {
if (isset($params['pass'][0])) {
$id = $params['pass'][0];
- } elseif (isset($this->controller->Session) && $this->controller->Session->valid() != false) {
- $this->controller->Session->setFlash(sprintf(__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey)));
+ } elseif ($this->_validSession) {
+ $this->controller->Session->setFlash(sprintf(
+ __("No id set for %s::delete()", true), Inflector::humanize($this->modelKey)
+ ));
$this->controller->redirect($this->redirect);
} else {
- return $this->controller->flash(sprintf(__("No id set for %s::delete()", true), Inflector::humanize($this->modelKey)),
- '/' . Inflector::underscore($this->controller->viewPath));
+ return $this->controller->flash(sprintf(
+ __("No id set for %s::delete()", true), Inflector::humanize($this->modelKey)
+ ), '/' . Inflector::underscore($this->controller->viewPath));
}
- if ($this->ScaffoldModel->del($id)) {
- if (isset($this->controller->Session) && $this->controller->Session->valid() != false) {
- $this->controller->Session->setFlash(sprintf(__('The %1$s with id: %2$d has been deleted.', true), Inflector::humanize($this->modelClass), $id));
+ if ($this->ScaffoldModel->delete($id)) {
+ if ($this->_validSession) {
+ $this->controller->Session->setFlash(sprintf(
+ __('The %1$s with id: %2$d has been deleted.', true),
+ Inflector::humanize($this->modelClass), $id
+ ));
$this->controller->redirect($this->redirect);
} else {
- return $this->controller->flash(sprintf(__('The %1$s with id: %2$d has been deleted.', true), Inflector::humanize($this->modelClass), $id), '/' . $this->viewPath);
+ return $this->controller->flash(sprintf(
+ __('The %1$s with id: %2$d has been deleted.', true),
+ Inflector::humanize($this->modelClass), $id
+ ), '/' . $this->viewPath);
}
} else {
- if (isset($this->controller->Session) && $this->controller->Session->valid() != false) {
- $this->controller->Session->setFlash(sprintf(__('There was an error deleting the %1$s with id: %2$d', true), Inflector::humanize($this->modelClass), $id));
+ if ($this->_validSession) {
+ $this->controller->Session->setFlash(sprintf(
+ __('There was an error deleting the %1$s with id: %2$d', true),
+ Inflector::humanize($this->modelClass), $id
+ ));
$this->controller->redirect($this->redirect);
} else {
- return $this->controller->flash(sprintf(__('There was an error deleting the %1$s with id: %2$d', true), Inflector::humanize($this->modelClass), $id), '/' . $this->viewPath);
+ return $this->controller->flash(sprintf(
+ __('There was an error deleting the %1$s with id: %2$d', true),
+ Inflector::humanize($this->modelClass), $id
+ ), '/' . $this->viewPath);
}
}
} elseif ($this->controller->_scaffoldError('delete') === false) {
@@ -383,9 +435,14 @@ function __scaffold($params) {
if (isset($db)) {
if (empty($this->scaffoldActions)) {
- $this->scaffoldActions = array('index', 'list', 'view', 'add', 'create', 'edit', 'update', 'delete');
+ $this->scaffoldActions = array(
+ 'index', 'list', 'view', 'add', 'create', 'edit', 'update', 'delete'
+ );
} elseif (!empty($admin) && $this->scaffoldActions === $admin) {
- $this->scaffoldActions = array($admin .'_index', $admin .'_list', $admin .'_view', $admin .'_add', $admin .'_create', $admin .'_edit', $admin .'_update', $admin .'_delete');
+ $this->scaffoldActions = array(
+ $admin .'_index', $admin .'_list', $admin .'_view', $admin .'_add',
+ $admin .'_create', $admin .'_edit', $admin .'_update', $admin .'_delete'
+ );
}
if (in_array($params['action'], $this->scaffoldActions)) {
@@ -419,13 +476,17 @@ function __scaffold($params) {
break;
}
} else {
- return $this->cakeError('missingAction', array(array('className' => $this->controller->name . "Controller",
- 'base' => $this->controller->base,
- 'action' => $this->action,
- 'webroot' => $this->controller->webroot)));
+ return $this->cakeError('missingAction', array(array(
+ 'className' => $this->controller->name . "Controller",
+ 'base' => $this->controller->base,
+ 'action' => $this->action,
+ 'webroot' => $this->controller->webroot
+ )));
}
} else {
- return $this->cakeError('missingDatabase', array(array('webroot' => $this->controller->webroot)));
+ return $this->cakeError('missingDatabase', array(array(
+ 'webroot' => $this->controller->webroot
+ )));
}
}
/**
@@ -440,10 +501,17 @@ function __associations() {
foreach ($keys as $key => $type) {
foreach ($this->ScaffoldModel->{$type} as $assocKey => $assocData) {
- $associations[$type][$assocKey]['primaryKey'] = $this->ScaffoldModel->{$assocKey}->primaryKey;
- $associations[$type][$assocKey]['displayField'] = $this->ScaffoldModel->{$assocKey}->displayField;
- $associations[$type][$assocKey]['foreignKey'] = $assocData['foreignKey'];
- $associations[$type][$assocKey]['controller'] = Inflector::pluralize(Inflector::underscore($assocData['className']));
+ $associations[$type][$assocKey]['primaryKey'] =
+ $this->ScaffoldModel->{$assocKey}->primaryKey;
+
+ $associations[$type][$assocKey]['displayField'] =
+ $this->ScaffoldModel->{$assocKey}->displayField;
+
+ $associations[$type][$assocKey]['foreignKey'] =
+ $assocData['foreignKey'];
+
+ $associations[$type][$assocKey]['controller'] =
+ Inflector::pluralize(Inflector::underscore($assocData['className']));
}
}
return $associations;
View
368 cake/libs/debugger.php
@@ -1,39 +1,39 @@
<?php
-/* SVN FILE: $Id$ */
/**
* Framework debugging and PHP error-handling class
*
* Provides enhanced logging, stack traces, and rendering debug views
*
* PHP versions 4 and 5
*
- * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
- * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
- * @filesource
- * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
- * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org
* @package cake
* @subpackage cake.cake.libs
* @since CakePHP(tm) v 1.2.4560
- * @version $Revision$
- * @modifiedby $LastChangedBy$
- * @lastmodified $Date$
- * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
+
/**
* Included libraries.
*
*/
- if (!class_exists('Object')) {
- uses('object');
- }
- if (!class_exists('CakeLog')) {
- uses('cake_log');
- }
+if (!class_exists('Object')) {
+ require_once LIBS . 'object.php';
+}
+if (!class_exists('CakeLog')) {
+ require_once LIBS . 'cake_log.php';
+}
+if (!class_exists('String')) {
+ require_once LIBS . 'string.php';
+}
+
/**
* Provide custom logging and error handling.
*
@@ -44,47 +44,134 @@
* @link http://book.cakephp.org/view/460/Using-the-Debugger-Class
*/
class Debugger extends Object {
+
/**
* A list of errors generated by the application.
*
* @var array
* @access public
*/
var $errors = array();
+
/**
* Contains the base URL for error code documentation.
*
* @var string
* @access public
*/
var $helpPath = null;
+
/**
* The current output format.
*
* @var string
* @access protected
*/
var $_outputFormat = 'js';
+
+/**
+ * Templates used when generating trace or error strings. Can be global or indexed by the format
+ * value used in $_outputFormat.
+ *
+ * @var string
+ * @access protected
+ */
+ var $_templates = array(
+ 'log' => array(
+ 'trace' => '{:reference} - {:path}, line {:line}',
+ 'error' => "{:error} ({:code}): {:description} in [{:file}, line {:line}]"
+ ),
+ 'js' => array(
+ 'error' => '',
+ 'info' => '',
+ 'trace' => '<pre class="stack-trace">{:trace}</pre>',
+ 'code' => '',
+ 'context' => '',
+ 'links' => array()
+ ),
+ 'html' => array(
+ 'trace' => '<pre class="cake-debug trace"><b>Trace</b> <p>{:trace}</p></pre>',
+ 'context' => '<pre class="cake-debug context"><b>Context</b> <p>{:context}</p></pre>'
+ ),
+ 'txt' => array(
+ 'error' => "{:error}: {:code} :: {:description} on line {:line} of {:path}\n{:info}",
+ 'context' => "Context:\n{:context}\n",
+ 'trace' => "Trace:\n{:trace}\n",
+ 'code' => '',
+ 'info' => ''
+ ),
+ 'base' => array(
+ 'traceLine' => '{:reference} - {:path}, line {:line}'
+ )
+ );
+
/**
* Holds current output data when outputFormat is false.
*
* @var string
* @access private
*/
- var $__data = array();
+ var $_data = array();
+
/**
* Constructor.
*
*/
function __construct() {
$docRef = ini_get('docref_root');
+
if (empty($docRef)) {
ini_set('docref_root', 'http://php.net/');
}
if (!defined('E_RECOVERABLE_ERROR')) {
define('E_RECOVERABLE_ERROR', 4096);
}
+ if (!defined('E_DEPRECATED')) {
+ define('E_DEPRECATED', 8192);
+ }
+
+ $e = '<a href="javascript:void(0);" onclick="document.getElementById(\'{:id}-trace\')';
+ $e .= '.style.display = (document.getElementById(\'{:id}-trace\').style.display == ';
+ $e .= '\'none\' ? \'\' : \'none\');"><b>{:error}</b> ({:code})</a>: {:description} ';
+ $e .= '[<b>{:path}</b>, line <b>{:line}</b>]';
+
+ $e .= '<div id="{:id}-trace" class="cake-stack-trace" style="display: none;">';
+ $e .= '{:links}{:info}</div>';
+ $this->_templates['js']['error'] = $e;
+
+ $t = '<div id="{:id}-trace" class="cake-stack-trace" style="display: none;">';
+ $t .= '{:context}{:code}{:trace}</div>';
+ $this->_templates['js']['info'] = $t;
+
+ $links = array();
+ $link = '<a href="javascript:void(0);" onclick="document.getElementById(\'{:id}-code\')';
+ $link .= '.style.display = (document.getElementById(\'{:id}-code\').style.display == ';
+ $link .= '\'none\' ? \'\' : \'none\')">Code</a>';
+ $links['code'] = $link;
+
+ $link = '<a href="javascript:void(0);" onclick="document.getElementById(\'{:id}-context\')';
+ $link .= '.style.display = (document.getElementById(\'{:id}-context\').style.display == ';
+ $link .= '\'none\' ? \'\' : \'none\')">Context</a>';
+ $links['context'] = $link;
+
+ $links['help'] = '<a href="{:helpPath}{:code}" target="_blank">Help</a>';
+ $this->_templates['js']['links'] = $links;
+
+ $this->_templates['js']['context'] = '<pre id="{:id}-context" class="cake-context" ';
+ $this->_templates['js']['context'] .= 'style="display: none;">{:context}</pre>';
+
+ $this->_templates['js']['code'] = '<div id="{:id}-code" class="cake-code-dump" ';
+ $this->_templates['js']['code'] .= 'style="display: none;"><pre>{:code}</pre></div>';
+
+
+ $e = '<pre class="cake-debug"><b>{:error}</b> ({:code}) : {:description} ';
+ $e .= '[<b>{:path}</b>, line <b>{:line}]</b></pre>';
+ $this->_templates['html']['error'] = $e;
+
+ $this->_templates['html']['context'] = '<pre class="cake-debug context"><b>Context</b> ';
+ $this->_templates['html']['context'] .= '<p>{:context}</p></pre>';
}
+
/**
* Returns a reference to the Debugger singleton object instance.
*
@@ -113,6 +200,7 @@ function &getInstance($class = null) {
}
return $instance[0];
}
+
/**
* Formats and outputs the contents of the supplied variable.
*
@@ -127,6 +215,7 @@ function dump($var) {
$_this = Debugger::getInstance();
pr($_this->exportVar($var));
}
+
/**
* Creates a detailed stack trace log at the time of invocation, much like dump()
* but to debug.log.
@@ -175,7 +264,7 @@ function handleError($code, $description, $file = null, $line = null, $context =
if (empty($line)) {
$line = '??';
}
- $file = $_this->trimPath($file);
+ $path = $_this->trimPath($file);
$info = compact('code', 'description', 'file', 'line');
if (!in_array($info, $_this->errors)) {
@@ -214,22 +303,28 @@ function handleError($code, $description, $file = null, $line = null, $context =
$helpCode = null;
if (!empty($_this->helpPath) && preg_match('/.*\[([0-9]+)\]$/', $description, $codes)) {
if (isset($codes[1])) {
- $helpCode = $codes[1];
+ $helpID = $codes[1];
$description = trim(preg_replace('/\[[0-9]+\]$/', '', $description));
}
}
- echo $_this->_output($level, $error, $code, $helpCode, $description, $file, $line, $context);
+ $data = compact(
+ 'level', 'error', 'code', 'helpID', 'description', 'file', 'path', 'line', 'context'
+ );
+ echo $_this->_output($data);
if (Configure::read('log')) {
- CakeLog::write($level, "{$error} ({$code}): {$description} in [{$file}, line {$line}]");
+ $tpl = $_this->_templates['log']['error'];
+ $options = array('before' => '{:', 'after' => '}');
+ CakeLog::write($level, String::insert($tpl, $data, $options));
}
if ($error == 'Fatal Error') {
die();
}
return true;
}
+
/**
* Outputs a stack trace based on the supplied options.
*
@@ -240,65 +335,66 @@ function handleError($code, $description, $file = null, $line = null, $context =
* @link http://book.cakephp.org/view/460/Using-the-Debugger-Class
*/
function trace($options = array()) {
- $options = array_merge(array(
- 'depth' => 999,
- 'format' => '',
- 'args' => false,
- 'start' => 0,
- 'scope' => null,
- 'exclude' => null
- ),
- $options
+ $_this = Debugger::getInstance();
+ $defaults = array(
+ 'depth' => 999,
+ 'format' => $_this->_outputFormat,
+ 'args' => false,
+ 'start' => 0,
+ 'scope' => null,
+ 'exclude' => null
);
+ $options += $defaults;
$backtrace = debug_backtrace();
- $back = array();
$count = count($backtrace);
+ $back = array();
+
+ $_trace = array(
+ 'line' => '??',
+ 'file' => '[internal]',
+ 'class' => null,
+ 'function' => '[main]'
+ );
for ($i = $options['start']; $i < $count && $i < $options['depth']; $i++) {
- $trace = array_merge(
- array(
- 'file' => '[internal]',
- 'line' => '??'
- ),
- $backtrace[$i]
- );
+ $trace = array_merge(array('file' => '[internal]', 'line' => '??'), $backtrace[$i]);
if (isset($backtrace[$i + 1])) {
- $next = array_merge(
- array(
- 'line' => '??',
- 'file' => '[internal]',
- 'class' => null,
- 'function' => '[main]'
- ),
- $backtrace[$i + 1]
- );
- $function = $next['function'];
+ $next = array_merge($_trace, $backtrace[$i + 1]);
+ $reference = $next['function'];
if (!empty($next['class'])) {
- $function = $next['class'] . '::' . $function . '(';
+ $reference = $next['class'] . '::' . $reference . '(';
if ($options['args'] && isset($next['args'])) {
$args = array();
foreach ($next['args'] as $arg) {
$args[] = Debugger::exportVar($arg);
}
- $function .= join(', ', $args);
+ $reference .= join(', ', $args);
}
- $function .= ')';
+ $reference .= ')';
}
} else {
- $function = '[main]';
+ $reference = '[main]';
}
- if (in_array($function, array('call_user_func_array', 'trigger_error'))) {
+ if (in_array($reference, array('call_user_func_array', 'trigger_error'))) {
continue;
}
if ($options['format'] == 'points' && $trace['file'] != '[internal]') {
$back[] = array('file' => $trace['file'], 'line' => $trace['line']);
- } elseif (empty($options['format'])) {
- $back[] = $function . ' - ' . Debugger::trimPath($trace['file']) . ', line ' . $trace['line'];
- } else {
+ } elseif ($options['format'] == 'array') {
$back[] = $trace;
+ } else {
+ if (isset($_this->_templates[$options['format']]['traceLine'])) {
+ $tpl = $_this->_templates[$options['format']]['traceLine'];
+ } else {
+ $tpl = $_this->_templates['base']['traceLine'];
+ }
+ $trace['path'] = Debugger::trimPath($trace['file']);
+ $trace['reference'] = $reference;
+ unset($trace['object'], $trace['args']);
+ $back[] = String::insert($tpl, $trace, array('before' => '{:', 'after' => '}'));
}
}
@@ -307,6 +403,7 @@ function trace($options = array()) {
}
return join("\n", $back);
}
+
/**
* Shortens file paths by replacing the application base path with 'APP', and the CakePHP core
* path with 'CORE'.
@@ -336,6 +433,7 @@ function trimPath($path) {
}
return $path;
}
+
/**
* Grabs an excerpt from a file and highlights a given line of code
*
@@ -370,6 +468,7 @@ function excerpt($file, $line, $context = 2) {
}
return $lines;
}
+
/**
* Converts a variable to a string for debug output.
*
@@ -424,6 +523,7 @@ function exportVar($var, $recursion = 0) {
break;
}
}
+
/**
* Handles object to string conversion.
*
@@ -454,98 +554,122 @@ function __object($var) {
}
return join("\n", $out);
}
+
/**
- * Handles object conversion to debug string.
+ * Switches output format, updates format strings
*
- * @param string $var Object to convert
+ * @param string $format Format to use, including 'js' for JavaScript-enhanced HTML, 'html' for
+ * straight HTML output, or 'text' for unformatted text.
* @access protected
*/
- function output($format = 'js') {
+ function output($format = null, $strings = array()) {
$_this = Debugger::getInstance();
$data = null;
- if ($format === true && !empty($_this->__data)) {
- $data = $_this->__data;
- $_this->__data = array();
+ if (is_null($format)) {
+ return $_this->_outputFormat;
+ }
+
+ if (!empty($strings)) {
+ if (isset($_this->_templates[$format])) {
+ if (isset($strings['links'])) {
+ $_this->_templates[$format]['links'] = array_merge(
+ $_this->_templates[$format]['links'],
+ $strings['links']
+ );
+ unset($strings['links']);
+ }
+ $_this->_templates[$format] = array_merge($_this->_templates[$format], $strings);
+ } else {
+ $_this->_templates[$format] = $strings;
+ }
+ return $_this->_templates[$format];
+ }
+
+ if ($format === true && !empty($_this->_data)) {
+ $data = $_this->_data;
+ $_this->_data = array();
$format = false;
}
$_this->_outputFormat = $format;
return $data;
}
+
/**
- * Handles object conversion to debug string.
+ * Renders error messages
*
- * @param string $var Object to convert
+ * @param array $data Data about the current error
* @access private
*/
- function _output($level, $error, $code, $helpCode, $description, $file, $line, $kontext) {
+ function _output($data = array()) {
+ $defaults = array(
+ 'level' => 0,
+ 'error' => 0,
+ 'code' => 0,
+ 'helpID' => null,
+ 'description' => '',
+ 'file' => '',
+ 'line' => 0,
+ 'context' => array()
+ );
+ $data += $defaults;
+
$files = $this->trace(array('start' => 2, 'format' => 'points'));
- $listing = $this->excerpt($files[0]['file'], $files[0]['line'] - 1, 1);
+ $code = $this->excerpt($files[0]['file'], $files[0]['line'] - 1, 1);
$trace = $this->trace(array('start' => 2, 'depth' => '20'));
+ $insertOpts = array('before' => '{:', 'after' => '}');
$context = array();
+ $links = array();
+ $info = '';
- foreach ((array)$kontext as $var => $value) {
+ foreach ((array)$data['context'] as $var => $value) {
$context[] = "\${$var}\t=\t" . $this->exportVar($value, 1);
}
switch ($this->_outputFormat) {
- default:
- case 'js':
- $link = "document.getElementById(\"CakeStackTrace" . count($this->errors) . "\").style.display = (document.getElementById(\"CakeStackTrace" . count($this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")";
- $out = "<a href='javascript:void(0);' onclick='{$link}'><b>{$error}</b> ({$code})</a>: {$description} [<b>{$file}</b>, line <b>{$line}</b>]";
- if (Configure::read() > 0) {
- debug($out, false, false);
- echo '<div id="CakeStackTrace' . count($this->errors) . '" class="cake-stack-trace" style="display: none;">';
- $link = "document.getElementById(\"CakeErrorCode" . count($this->errors) . "\").style.display = (document.getElementById(\"CakeErrorCode" . count($this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")";
- echo "<a href='javascript:void(0);' onclick='{$link}'>Code</a>";
-
- if (!empty($context)) {
- $link = "document.getElementById(\"CakeErrorContext" . count($this->errors) . "\").style.display = (document.getElementById(\"CakeErrorContext" . count($this->errors) . "\").style.display == \"none\" ? \"\" : \"none\")";
- echo " | <a href='javascript:void(0);' onclick='{$link}'>Context</a>";
-
- if (!empty($helpCode)) {
- echo " | <a href='{$this->helpPath}{$helpCode}' target='_blank'>Help</a>";
- }
-
- echo "<pre id=\"CakeErrorContext" . count($this->errors) . "\" class=\"cake-context\" style=\"display: none;\">";
- echo implode("\n", $context);
- echo "</pre>";
- }
+ case false:
+ $this->_data[] = compact('context', 'trace') + $data;
+ return;
+ case 'log':
+ $this->log(compact('context', 'trace') + $data);
+ return;
+ }
- if (!empty($listing)) {
- echo "<div id=\"CakeErrorCode" . count($this->errors) . "\" class=\"cake-code-dump\" style=\"display: none;\">";
- pr(implode("\n", $listing) . "\n", false);
- echo '</div>';
- }
- pr($trace, false);
- echo '</div>';
- }
- break;
- case 'html':
- echo "<pre class=\"cake-debug\"><b>{$error}</b> ({$code}) : {$description} [<b>{$file}</b>, line <b>{$line}]</b></pre>";
- if (!empty($context)) {
- echo "Context:\n" .implode("\n", $context) . "\n";
- }
- echo "<pre class=\"cake-debug context\"><b>Context</b> <p>" . implode("\n", $context) . "</p></pre>";
- echo "<pre class=\"cake-debug trace\"><b>Trace</b> <p>" . $trace. "</p></pre>";
- break;
- case 'text':
- case 'txt':
- echo "{$error}: {$code} :: {$description} on line {$line} of {$file}\n";
- if (!empty($context)) {
- echo "Context:\n" .implode("\n", $context) . "\n";
+ if (empty($this->_outputFormat) || !isset($this->_templates[$this->_outputFormat])) {
+ $this->_outputFormat = 'js';
+ }
+
+ $data['id'] = 'cakeErr' . count($this->errors);
+ $tpl = array_merge($this->_templates['base'], $this->_templates[$this->_outputFormat]);
+ $insert = array('context' => join("\n", $context), 'helpPath' => $this->helpPath) + $data;
+
+ $detect = array('help' => 'helpID', 'context' => 'context');
+
+ if (isset($tpl['links'])) {
+ foreach ($tpl['links'] as $key => $val) {
+ if (isset($detect[$key]) && empty($insert[$detect[$key]])) {
+ continue;
}
- echo "Trace:\n" . $trace;
- break;
- case 'log':
- $this->log(compact('error', 'code', 'description', 'line', 'file', 'context', 'trace'));
- break;
- case false:
- $this->__data[] = compact('error', 'code', 'description', 'line', 'file', 'context', 'trace');
- break;
+ $links[$key] = String::insert($val, $insert, $insertOpts);
+ }
}
+
+ foreach (array('code', 'context', 'trace') as $key) {
+ if (empty($$key) || !isset($tpl[$key])) {
+ continue;
+ }
+ if (is_array($$key)) {
+ $$key = join("\n", $$key);
+ }
+ $info .= String::insert($tpl[$key], compact($key) + $insert, $insertOpts);
+ }
+ $links = join(' | ', $links);
+ unset($data['context']);
+
+ echo String::insert($tpl['error'], compact('links', 'info') + $data, $insertOpts);
}
+
/**
* Verifies that the application's salt value has been changed from the default value.
*
@@ -557,9 +681,10 @@ function checkSessionKey() {
trigger_error(__('Please change the value of \'Security.salt\' in app/config/core.php to a salt value specific to your application', true), E_USER_NOTICE);
}
}
+
/**
- * Invokes the given debugger object as the current error handler, taking over control from the previous handler
- * in a stack-like hierarchy.
+ * Invokes the given debugger object as the current error handler, taking over control from the
+ * previous handler in a stack-like hierarchy.
*
* @param object $debugger A reference to the Debugger object
* @access public
@@ -574,4 +699,5 @@ function invoke(&$debugger) {
if (!defined('DISABLE_DEFAULT_ERROR_HANDLING')) {
Debugger::invoke(Debugger::getInstance());
}
+
?>
View
137 cake/libs/model/model.php
@@ -1,33 +1,30 @@
<?php
-/* SVN FILE: $Id$ */
/**
* Object-relational mapper.
*
* DBO-backed object data model, for mapping database tables to Cake objects.
*
* PHP versions 5
*
- * CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
- * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
+ * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
+ * Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
- * @filesource
- * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
- * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP(tm) Project
+ * @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
+ * @link http://cakephp.org
* @package cake
* @subpackage cake.cake.libs.model
* @since CakePHP(tm) v 0.10.0.0
- * @version $Revision$
- * @modifiedby $LastChangedBy$
- * @lastmodified $Date$
- * @license http://www.opensource.org/licenses/mit-license.php The MIT License
+ * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
/**
* Included libs
*/
-App::import('Core', array('ClassRegistry', 'Overloadable', 'Validation', 'Behavior', 'ConnectionManager', 'Set', 'String'));
+App::import('Core', array(
+ 'ClassRegistry', 'Overloadable', 'Validation', 'Behavior', 'ConnectionManager', 'Set', 'String'
+));
/**
* Object-relational mapper.
*
@@ -1377,7 +1374,7 @@ function updateCounterCache($keys = array(), $created = false) {
if ($keys['old'][$foreignKey] != $keys[$foreignKey]) {
$conditions[$fkQuoted] = $keys['old'][$foreignKey];
$count = intval($this->find('count', compact('conditions', 'recursive')));
-
+
$this->{$parent}->updateAll(
array($assoc['counterCache'] => $count),
array($this->{$parent}->escapeField() => $keys['old'][$foreignKey])
@@ -1645,17 +1642,11 @@ function updateAll($fields, $conditions = true) {
return $db->update($this, $fields, null, $conditions);
}
/**
- * Alias for del().
- *
- * @param mixed $id ID of record to delete
- * @param boolean $cascade Set to true to delete records that depend on this record
- * @return boolean True on success
- * @access public
- * @see Model::del()
+ * @deprecated
* @link http://book.cakephp.org/view/691/remove
*/
function remove($id = null, $cascade = true) {
- return $this->del($id, $cascade);
+ return $this->delete($id, $cascade);
}
/**
* Removes record for given ID. If no ID is given, the current ID is used. Returns true on success.
@@ -1666,15 +1657,18 @@ function remove($id = null, $cascade = true) {
* @access public
* @link http://book.cakephp.org/view/690/del
*/
- function del($id = null, $cascade = true) {
+ function delete($id = null, $cascade = true) {
if (!empty($id)) {
$this->id = $id;
}
$id = $this->id;
if ($this->exists() && $this->beforeDelete($cascade)) {
$db =& ConnectionManager::getDataSource($this->useDbConfig);
- if (!$this->Behaviors->trigger($this, 'beforeDelete', array($cascade), array('break' => true, 'breakOn' => false))) {
+ $filters = $this->Behaviors->trigger($this, 'beforeDelete', array($cascade), array(
+ 'break' => true, 'breakOn' => false
+ ));
+ if (!$filters) {
return false;
}
$this->_deleteDependent($id, $cascade);
@@ -1700,16 +1694,10 @@ function del($id = null, $cascade = true) {
return false;
}
/**
- * Alias for del().
- *
- * @param mixed $id ID of record to delete
- * @param boolean $cascade Set to true to delete records that depend on this record
- * @return boolean True on success
- * @access public
- * @see Model::del()
+ * @deprecated
*/
- function delete($id = null, $cascade = true) {
- return $this->del($id, $cascade);
+ function del($id = null, $cascade = true) {
+ return $this->delete($id, $cascade);
}
/**
* Cascades model deletes through associated hasMany and hasOne child records.
@@ -1737,7 +1725,9 @@ function _deleteDependent($id, $cascade) {
if (isset($data['exclusive']) && $data['exclusive']) {
$model->deleteAll($conditions);
} else {
- $records = $model->find('all', array('conditions' => $conditions, 'fields' => $model->primaryKey));
+ $records = $model->find('all', array(
+ 'conditions' => $conditions, 'fields' => $model->primaryKey
+ ));
if (!empty($records)) {
foreach ($records as $record) {
@@ -1762,14 +1752,18 @@ function _deleteLinks($id) {
$db =& ConnectionManager::getDataSource($this->useDbConfig);
foreach ($this->hasAndBelongsToMany as $assoc => $data) {
+ $with = $data['with'];
$records = $this->{$data['with']}->find('all', array(
- 'conditions' => array_merge(array($this->{$data['with']}->escapeField($data['foreignKey']) => $id)),
- 'fields' => $this->{$data['with']}->primaryKey,
+ 'conditions' => array_merge(array(
+ $this->{$with}->escapeField($data['foreignKey']) => $id
+ )),
+ 'fields' => $this->{$with}->primaryKey,
'recursive' => -1
));
if (!empty($records)) {
foreach ($records as $record) {
- $this->{$data['with']}->delete($record[$this->{$data['with']}->alias][$this->{$data['with']}->primaryKey]);
+ $id = $record[$this->{$with}->alias][$this->{$with}->primaryKey];
+ $this->{$with}->delete($id);
}
}
}
@@ -1794,7 +1788,10 @@ function deleteAll($conditions, $cascade = true, $callbacks = false) {
return $db->delete($this, $conditions);
} else {
$ids = Set::extract(
- $this->find('all', array_merge(array('fields' => "{$this->alias}.{$this->primaryKey}", 'recursive' => 0), compact('conditions'))),
+ $this->find('all', array_merge(array(
+ 'fields' => "{$this->alias}.{$this->primaryKey}",
+ 'recursive' => 0), compact('conditions'))
+ ),
"{n}.{$this->alias}.{$this->primaryKey}"
);
@@ -1821,6 +1818,7 @@ function deleteAll($conditions, $cascade = true, $callbacks = false) {
}
}
}
+
/**
* Collects foreign keys from associations.
*
@@ -1837,6 +1835,7 @@ function __collectForeignKeys($type = 'belongsTo') {
}
return $result;
}
+
/**
* Returns true if a record with the currently set ID exists.
*
@@ -1863,6 +1862,7 @@ function exists($reset = false) {
}
return $this->__exists = ($this->find('count', $query) > 0);
}
+
/**
* Returns true if a record that meets given conditions exists.
*
@@ -1873,6 +1873,7 @@ function exists($reset = false) {
function hasAny($conditions = null) {
return ($this->find('count', array('conditions' => $conditions, 'recursive' => -1)) != false);
}
+
/**
* Returns a result set array.
*
@@ -1894,8 +1895,10 @@ function hasAny($conditions = null) {
* - If three fields are specified, they are used (in order) for key, value and group.
* - Otherwise, first and second fields are used for key and value.
*
- * @param array $conditions SQL conditions array, or type of find operation (all / first / count / neighbors / list / threaded)
- * @param mixed $fields Either a single string of a field name, or an array of field names, or options for matching
+ * @param array $conditions SQL conditions array, or type of find operation (all / first / count /
+ * neighbors / list / threaded)
+ * @param mixed $fields Either a single string of a field name, or an array of field names, or
+ * options for matching
* @param string $order SQL ORDER BY conditions (e.g. "price DESC" or "name ASC")
* @param integer $recursive The number of levels deep to fetch associated records
* @return array Array of records
@@ -1973,6 +1976,7 @@ function find($conditions = null, $fields = array(), $order = null, $recursive =
}
}
}
+
/**
* Handles the before/after filter logic for find('first') operations. Only called by Model::find().
*
@@ -1997,6 +2001,7 @@ function _findFirst($state, $query, $results = array()) {
return $results[0];
}
}
+
/**
* Handles the before/after filter logic for find('count') operations. Only called by Model::find().
*
@@ -2028,6 +2033,7 @@ function _findCount($state, $query, $results = array()) {
return false;
}
}
+
/**
* Handles the before/after filter logic for find('list') operations. Only called by Model::find().
*
@@ -2086,6 +2092,7 @@ function _findList($state, $query, $results = array()) {
return Set::combine($results, $lst['keyPath'], $lst['valuePath'], $lst['groupPath']);
}
}
+
/**
* Detects the previous field's value, then uses logic to find the 'wrapping'
* rows and return them.
@@ -2144,6 +2151,7 @@ function _findNeighbors($state, $query, $results = array()) {
return $return;
}
}
+
/**
* In the event of ambiguous results returned (multiple top level results, with different parent_ids)
* top level results with different parent_ids to the first result will be dropped
@@ -2190,6 +2198,7 @@ function _findThreaded($state, $query, $results = array()) {
return $return;
}
}
+
/**
* Passes query results through model and behavior afterFilter() methods.
*
@@ -2205,6 +2214,7 @@ function __filterResults($results, $primary = true) {
}
return $this->afterFind($results, $primary);
}
+
/**
* Called only when bindTo<ModelName>() is used.
* This resets the association arrays for the model back
@@ -2233,6 +2243,7 @@ function resetAssociations() {
$this->__backAssociation = array();
return true;
}
+
/**
* Returns false if any fields passed match any (by default, all if $or = false) of their matching values.
*
@@ -2275,6 +2286,7 @@ function isUnique($fields, $or = true) {
}
return ($this->find('count', array('conditions' => $fields, 'recursive' => -1)) == 0);
}
+
/**
* Returns a resultset for a given SQL statement. Custom SQL queries should be performed with this method.
*
@@ -2288,6 +2300,7 @@ function query() {
$db =& ConnectionManager::getDataSource($this->useDbConfig);
return call_user_func_array(array(&$db, 'query'), $params);
}
+
/**
* Returns true if all fields pass validation.
*
@@ -2303,6 +2316,7 @@ function validates($options = array()) {
}
return $errors;
}
+
/**
* Returns an array of fields that have failed validation.
*
@@ -2453,6 +2467,7 @@ function invalidFields($options = array()) {
$this->validate = $_validate;
return $this->validationErrors;
}
+
/**
* Marks a field as invalid, optionally setting the name of validation
* rule (in case of multiple validation for field) that was broken.
@@ -2468,6 +2483,7 @@ function invalidate($field, $value = true) {
}
$this->validationErrors[$field] = $value;
}
+
/**
* Returns true if given field name is a foreign key in this model.
*
@@ -2484,6 +2500,7 @@ function isForeignKey($field) {
}
return in_array($field, $foreignKeys);
}
+
/**
* Returns the display field for this model.
*
@@ -2494,6 +2511,7 @@ function isForeignKey($field) {
function getDisplayField() {
return $this->displayField;
}
+
/**
* Escapes the field name and prepends the model name. Escaping is done according to the current database driver's rules.
*
@@ -2515,6 +2533,7 @@ function escapeField($field = null, $alias = null) {
}
return $db->name($alias . '.' . $field);
}
+
/**
* Returns the current record's ID
*
@@ -2547,6 +2566,7 @@ function getID($list = 0) {
return false;
}
+
/**
* Returns the ID of the last record this model inserted.
*
@@ -2556,6 +2576,7 @@ function getID($list = 0) {
function getLastInsertID() {
return $this->getInsertID();
}
+
/**
* Returns the ID of the last record this model inserted.
*
@@ -2565,6 +2586,7 @@ function getLastInsertID() {
function getInsertID() {
return $this->__insertID;
}
+
/**
* Sets the ID of the last record this model inserted
*
@@ -2658,7 +2680,12 @@ function getAssociated($type = null) {
}
return array_keys($this->{$type});
} else {
- $assoc = array_merge($this->hasOne, $this->hasMany, $this->belongsTo, $this->hasAndBelongsToMany);
+ $assoc = array_merge(
+ $this->hasOne,
+ $this->hasMany,
+ $this->belongsTo,
+ $this->hasAndBelongsToMany
+ );
if (array_key_exists($type, $assoc)) {
foreach ($this->__associations as $a) {
if (isset($this->{$a}[$type])) {
@@ -2672,7 +2699,8 @@ function getAssociated($type = null) {
}
}
/**
- * Gets the name and fields to be used by a join model. This allows specifying join fields in the association definition.
+ * Gets the name and fields to be used by a join model. This allows specifying join fields
+ * in the association definition.
*
* @param object $model The model to be joined
* @param mixed $with The 'with' key of the model association
@@ -2686,16 +2714,19 @@ function joinModel($assoc, $keys = array()) {
} elseif (is_array($assoc)) {
$with = key($assoc);
return array($with, array_unique(array_merge($assoc[$with], $keys)));
- } else {
- trigger_error(sprintf(__('Invalid join model settings in %s', true), $model->alias), E_USER_WARNING);
}
+ trigger_error(
+ sprintf(__('Invalid join model settings in %s', true), $model->alias),
+ E_USER_WARNING
+ );
}
/**
* Called before each find operation. Return false if you want to halt the find
* call, otherwise return the (modified) query data.
*
* @param array $queryData Data used to execute this query, i.e. conditions, order, etc.
- * @return mixed true if the operation should continue, false if it should abort; or, modified $queryData to continue with new $queryData
+ * @return mixed true if the operation should continue, false if it should abort; or, modified
+ * $queryData to continue with new $queryData
* @access public
* @link http://book.cakephp.org/view/680/beforeFind
*/
@@ -2827,31 +2858,43 @@ function __wakeup() {
* @see Model::find('all')
*/
function findAll($conditions = null, $fields = null, $order = null, $limit = null, $page = 1, $recursive = null) {
- //trigger_error(__('(Model::findAll) Deprecated, use Model::find("all")', true), E_USER_WARNING);
+ trigger_error(
+ __('(Model::findAll) Deprecated, use Model::find("all")', true),
+ E_USER_WARNING
+ );
return $this->find('all', compact('conditions', 'fields', 'order', 'limit', 'page', 'recursive'));
}
/**
* @deprecated
* @see Model::find('count')
*/