merging 1.3-misc into master

This commit is contained in:
gwoo 2009-05-01 14:05:46 -07:00
parent 1f7eb18107
commit 15518b8c9a
17 changed files with 782 additions and 458 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
app/config
app/tmp
vendors

View file

@ -1,5 +1,4 @@
<?php
/* SVN FILE: $Id$ */
/**
* This is core configuration file.
*
@ -7,22 +6,18 @@
*
* 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 file

@ -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 file

@ -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 file

@ -375,7 +375,7 @@ class ControllerTask extends Shell {
$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 file

@ -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 @@ class Controller extends Object {
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 @@ class Controller extends Object {
$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 @@ class Controller extends Object {
$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 @@ class Controller extends Object {
}
/**
* 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 @@ class Controller extends Object {
$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 @@ class Controller extends Object {
* 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 @@ class Controller extends Object {
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,8 +786,13 @@ class Controller extends Object {
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);
@ -785,7 +800,8 @@ class Controller extends Object {
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 @@ class Controller extends Object {
}
if ($default != null) {
return $default;
$url = Router::url($default, true);
return $url;
}
return '/';
}
@ -863,9 +880,11 @@ class Controller extends Object {
* 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 @@ class Controller extends Object {
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 @@ class Controller extends Object {
}
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 @@ class Controller extends Object {
$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 @@ class Controller extends Object {
return false;
}
}
?>
?>

View file

@ -1,5 +1,4 @@
<?php
/* SVN FILE: $Id$ */
/**
* Scaffold.
*
@ -7,25 +6,21 @@
*
* 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,
@ -113,13 +108,23 @@ class Scaffold extends Object {
* @access public
*/
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 @@ class Scaffold extends Object {
$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 @@ class Scaffold extends Object {
$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 @@ class Scaffold extends Object {
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 @@ class Scaffold extends Object {
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 @@ class Scaffold extends Object {
}
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 @@ class Scaffold extends Object {
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 @@ class Scaffold extends Object {
}
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 @@ class Scaffold extends Object {
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 @@ class Scaffold extends Object {
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 @@ class Scaffold extends Object {
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 @@ class Scaffold extends Object {
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 file

@ -1,5 +1,4 @@
<?php
/* SVN FILE: $Id$ */
/**
* Framework debugging and PHP error-handling class
*
@ -7,33 +6,34 @@
*
* 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,6 +44,7 @@
* @link http://book.cakephp.org/view/460/Using-the-Debugger-Class
*/
class Debugger extends Object {
/**
* A list of errors generated by the application.
*
@ -51,6 +52,7 @@ class Debugger extends Object {
* @access public
*/
var $errors = array();
/**
* Contains the base URL for error code documentation.
*
@ -58,6 +60,7 @@ class Debugger extends Object {
* @access public
*/
var $helpPath = null;
/**
* The current output format.
*
@ -65,26 +68,110 @@ class Debugger extends Object {
* @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 @@ class Debugger extends Object {
}
return $instance[0];
}
/**
* Formats and outputs the contents of the supplied variable.
*
@ -127,6 +215,7 @@ class Debugger extends Object {
$_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 @@ class Debugger extends Object {
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,15 +303,20 @@ class Debugger extends Object {
$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') {
@ -230,6 +324,7 @@ class Debugger extends Object {
}
return true;
}
/**
* Outputs a stack trace based on the supplied options.
*
@ -240,65 +335,66 @@ class Debugger extends Object {
* @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 @@ class Debugger extends Object {
}
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 @@ class Debugger extends Object {
}
return $path;
}
/**
* Grabs an excerpt from a file and highlights a given line of code
*
@ -370,6 +468,7 @@ class Debugger extends Object {
}
return $lines;
}
/**
* Converts a variable to a string for debug output.
*
@ -424,6 +523,7 @@ class Debugger extends Object {
break;
}
}
/**
* Handles object to string conversion.
*
@ -454,98 +554,122 @@ class Debugger extends Object {
}
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) {
$files = $this->trace(array('start' => 2, 'format' => 'points'));
$listing = $this->excerpt($files[0]['file'], $files[0]['line'] - 1, 1);
$trace = $this->trace(array('start' => 2, 'depth' => '20'));
$context = array();
function _output($data = array()) {
$defaults = array(
'level' => 0,
'error' => 0,
'code' => 0,
'helpID' => null,
'description' => '',
'file' => '',
'line' => 0,
'context' => array()
);
$data += $defaults;
foreach ((array)$kontext as $var => $value) {
$files = $this->trace(array('start' => 2, 'format' => 'points'));
$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)$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>";
}
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";
}
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;
$this->_data[] = compact('context', 'trace') + $data;
return;
case 'log':
$this->log(compact('context', 'trace') + $data);
return;
}
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;
}
$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 @@ class Debugger extends Object {
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 @@ class Debugger extends Object {
if (!defined('DISABLE_DEFAULT_ERROR_HANDLING')) {
Debugger::invoke(Debugger::getInstance());
}
?>

View file

@ -1,5 +1,4 @@
<?php
/* SVN FILE: $Id$ */
/**
* Object-relational mapper.
*
@ -7,27 +6,25 @@
*
* 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 @@ class Model extends Overloadable {
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 @@ class Model extends Overloadable {
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,7 +1657,7 @@ class Model extends Overloadable {
* @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;
}
@ -1674,7 +1665,10 @@ class Model extends Overloadable {
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 @@ class Model extends Overloadable {
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 @@ class Model extends Overloadable {
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 @@ class Model extends Overloadable {
$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 @@ class Model extends Overloadable {
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 @@ class Model extends Overloadable {
}
}
}
/**
* Collects foreign keys from associations.
*
@ -1837,6 +1835,7 @@ class Model extends Overloadable {
}
return $result;
}
/**
* Returns true if a record with the currently set ID exists.
*
@ -1863,6 +1862,7 @@ class Model extends Overloadable {
}
return $this->__exists = ($this->find('count', $query) > 0);
}
/**
* Returns true if a record that meets given conditions exists.
*
@ -1873,6 +1873,7 @@ class Model extends Overloadable {
function hasAny($conditions = null) {
return ($this->find('count', array('conditions' => $conditions, 'recursive' => -1)) != false);
}
/**
* Returns a result set array.
*
@ -1894,8 +1895,10 @@ class Model extends Overloadable {
* - 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 @@ class Model extends Overloadable {
}
}
}
/**
* Handles the before/after filter logic for find('first') operations. Only called by Model::find().
*
@ -1997,6 +2001,7 @@ class Model extends Overloadable {
return $results[0];
}
}
/**
* Handles the before/after filter logic for find('count') operations. Only called by Model::find().
*
@ -2028,6 +2033,7 @@ class Model extends Overloadable {
return false;
}
}
/**
* Handles the before/after filter logic for find('list') operations. Only called by Model::find().
*
@ -2086,6 +2092,7 @@ class Model extends Overloadable {
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 @@ class Model extends Overloadable {
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 @@ class Model extends Overloadable {
return $return;
}
}
/**
* Passes query results through model and behavior afterFilter() methods.
*
@ -2205,6 +2214,7 @@ class Model extends Overloadable {
}
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 @@ class Model extends Overloadable {
$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 @@ class Model extends Overloadable {
}
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 @@ class Model extends Overloadable {
$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 @@ class Model extends Overloadable {
}
return $errors;
}
/**
* Returns an array of fields that have failed validation.
*
@ -2453,6 +2467,7 @@ class Model extends Overloadable {
$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 @@ class Model extends Overloadable {
}
$this->validationErrors[$field] = $value;
}
/**
* Returns true if given field name is a foreign key in this model.
*
@ -2484,6 +2500,7 @@ class Model extends Overloadable {
}
return in_array($field, $foreignKeys);
}
/**
* Returns the display field for this model.
*
@ -2494,6 +2511,7 @@ class Model extends Overloadable {
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 @@ class Model extends Overloadable {
}
return $db->name($alias . '.' . $field);
}
/**
* Returns the current record's ID
*
@ -2547,6 +2566,7 @@ class Model extends Overloadable {
return false;
}
/**
* Returns the ID of the last record this model inserted.
*
@ -2556,6 +2576,7 @@ class Model extends Overloadable {
function getLastInsertID() {
return $this->getInsertID();
}
/**
* Returns the ID of the last record this model inserted.
*
@ -2565,6 +2586,7 @@ class Model extends Overloadable {
function getInsertID() {
return $this->__insertID;
}
/**
* Sets the ID of the last record this model inserted
*
@ -2658,7 +2680,12 @@ class Model extends Overloadable {
}
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 @@ class Model extends Overloadable {
}
}
/**
* 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 @@ class Model extends Overloadable {
} 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,7 +2858,10 @@ class Model extends Overloadable {
* @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'));
}
/**
@ -2835,7 +2869,10 @@ class Model extends Overloadable {
* @see Model::find('count')
*/
function findCount($conditions = null, $recursive = 0) {
//trigger_error(__('(Model::findCount) Deprecated, use Model::find("count")', true), E_USER_WARNING);
trigger_error(
__('(Model::findCount) Deprecated, use Model::find("count")', true),
E_USER_WARNING
);
return $this->find('count', compact('conditions', 'recursive'));
}
/**
@ -2843,7 +2880,10 @@ class Model extends Overloadable {
* @see Model::find('threaded')
*/
function findAllThreaded($conditions = null, $fields = null, $order = null) {
//trigger_error(__('(Model::findAllThreaded) Deprecated, use Model::find("threaded")', true), E_USER_WARNING);
trigger_error(
__('(Model::findAllThreaded) Deprecated, use Model::find("threaded")', true),
E_USER_WARNING
);
return $this->find('threaded', compact('conditions', 'fields', 'order'));
}
/**
@ -2851,7 +2891,10 @@ class Model extends Overloadable {
* @see Model::find('neighbors')
*/
function findNeighbours($conditions = null, $field, $value) {
//trigger_error(__('(Model::findNeighbours) Deprecated, use Model::find("neighbors")', true), E_USER_WARNING);
trigger_error(
__('(Model::findNeighbours) Deprecated, use Model::find("neighbors")', true),
E_USER_WARNING
);
$query = compact('conditions', 'field', 'value');
$query['fields'] = $field;
if (is_array($field)) {

View file

@ -1,27 +1,22 @@
<?php
/* SVN FILE: $Id$ */
/**
* String handling methods.
*
*
* 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.0.5551
* @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)
*/
/**
* String handling methods.
@ -59,7 +54,9 @@ class String extends Object {
if (strpos($node, ':') !== false) {
if (substr_count($node, '::')) {
$node = str_replace('::', str_repeat(':0000', 8 - substr_count($node, ':')) . ':', $node);
$node = str_replace(
'::', str_repeat(':0000', 8 - substr_count($node, ':')) . ':', $node
);
}
$node = explode(':', $node) ;
$ipv6 = '' ;
@ -111,14 +108,16 @@ class String extends Object {
}
list($timeMid, $timeLow) = explode(' ', microtime());
$uuid = sprintf("%08x-%04x-%04x-%02x%02x-%04x%08x", (int)$timeLow, (int)substr($timeMid, 2) & 0xffff,
mt_rand(0, 0xfff) | 0x4000, mt_rand(0, 0x3f) | 0x80, mt_rand(0, 0xff), $pid, $node);
$uuid = sprintf(
"%08x-%04x-%04x-%02x%02x-%04x%08x", (int)$timeLow, (int)substr($timeMid, 2) & 0xffff,
mt_rand(0, 0xfff) | 0x4000, mt_rand(0, 0x3f) | 0x80, mt_rand(0, 0xff), $pid, $node
);
return $uuid;
}
/**
* Tokenizes a string using $separator, ignoring any instance of $separator that appears between $leftBound
* and $rightBound
* Tokenizes a string using $separator, ignoring any instance of $separator that appears between
* $leftBound and $rightBound
*
* @param string $data The data to tokenize
* @param string $separator The token to split the data on
@ -140,7 +139,11 @@ class String extends Object {
while ($offset <= $length) {
$tmpOffset = -1;
$offsets = array(strpos($data, $separator, $offset), strpos($data, $leftBound, $offset), strpos($data, $rightBound, $offset));
$offsets = array(
strpos($data, $separator, $offset),
strpos($data, $leftBound, $offset),
strpos($data, $rightBound, $offset)
);
for ($i = 0; $i < 3; $i++) {
if ($offsets[$i] !== false && ($offsets[$i] < $tmpOffset || $tmpOffset == -1)) {
$tmpOffset = $offsets[$i];
@ -190,21 +193,22 @@ class String extends Object {
return $data;
}
/**
* Replaces variable placeholders inside a $str with any given $data. Each key in the $data array corresponds to a variable
* placeholder name in $str. Example:
*
* Sample: String::insert('My name is :name and I am :age years old.', array('name' => 'Bob', '65'));
* Returns: My name is Bob and I am 65 years old.
* Replaces variable placeholders inside a $str with any given $data. Each key in the $data array
* corresponds to a variable placeholder name in $str.
* Example: String::insert(':name is :age years old.', array('name' => 'Bob', '65'));
* Returns: Bob is 65 years old.
*
* Available $options are:
* before: The character or string in front of the name of the variable placeholder (Defaults to ':')
* after: The character or string after the name of the variable placeholder (Defaults to null)
* escape: The character or string used to escape the before character / string (Defaults to '\')
* format: A regex to use for matching variable placeholders. Default is: '/(?<!\\)\:%s/' (Overwrites before, after, breaks escape / clean)
* format: A regex to use for matching variable placeholders. Default is: '/(?<!\\)\:%s/'
* (Overwrites before, after, breaks escape / clean)
* clean: A boolean or array with instructions for String::cleanInsert
*
* @param string $str A string containing variable placeholders
* @param string $data A key => val array where each key stands for a placeholder variable name to be replaced with val
* @param string $data A key => val array where each key stands for a placeholder variable name
* to be replaced with val
* @param string $options An array of options, see description above
* @return string
* @access public
@ -247,6 +251,9 @@ class String extends Object {
}
$dataReplacements = array_combine($hashKeys, array_values($data));
foreach ($dataReplacements as $tmpHash => $data) {
if (is_array($data)) {
$data = '';
}
$str = str_replace($tmpHash, $data, $str);
}
}
@ -260,15 +267,17 @@ class String extends Object {
return String::cleanInsert($str, $options);
}
/**
* Cleans up a Set::insert formated string with given $options depending on the 'clean' key in $options. The default method used is
* text but html is also available. The goal of this function is to replace all whitespace and uneeded markup around placeholders
* that did not get replaced by Set::insert.
* Cleans up a Set::insert formated string with given $options depending on the 'clean' key in
* $options. The default method used is text but html is also available. The goal of this function
* is to replace all whitespace and uneeded markup around placeholders that did not get replaced
* by Set::insert.
*
* @param string $str
* @param string $options
* @return string
* @access public
* @static
* @see Set::insert()
*/
function cleanInsert($str, $options) {
$clean = $options['clean'];

View file

@ -1,26 +1,21 @@
<?php
/* SVN FILE: $Id$ */
/**
* Pagination Helper class file.
*
* Generates pagination links
*
* 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.view.helpers
* @since CakePHP(tm) v 1.2.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)
*/
/**
* Pagination Helper class for easy generation of pagination links.
@ -105,7 +100,9 @@ class PaginatorHelper extends AppHelper {
if (!isset($this->params['paging'][$model])) {
$this->params['paging'][$model] = array();
}
$this->params['paging'][$model] = array_merge($this->params['paging'][$model], $options[$model]);
$this->params['paging'][$model] = array_merge(
$this->params['paging'][$model], $options[$model]
);
unset($options[$model]);
}
$this->options = array_filter(array_merge($this->options, $options));
@ -278,7 +275,9 @@ class PaginatorHelper extends AppHelper {
*/
function url($options = array(), $asArray = false, $model = null) {
$paging = $this->params($model);
$url = array_merge(array_filter(Set::diff(array_merge($paging['defaults'], $paging['options']), $paging['defaults'])), $options);
$url = array_merge(array_filter(Set::diff(array_merge(
$paging['defaults'], $paging['options']), $paging['defaults'])), $options
);
if (isset($url['order'])) {
$sort = $direction = null;
@ -424,7 +423,8 @@ class PaginatorHelper extends AppHelper {
if (!is_array($options['separator'])) {
$options['separator'] = array(' - ', $options['separator']);
}
$out = $start . $options['separator'][0] . $end . $options['separator'][1] . $paging['count'];
$out = $start . $options['separator'][0] . $end . $options['separator'][1];
$out .= $paging['count'];
break;
case 'pages':
$out = $paging['page'] . $options['separator'] . $paging['pageCount'];
@ -505,7 +505,8 @@ class PaginatorHelper extends AppHelper {
$out .= $before;
for ($i = $start; $i < $params['page']; $i++) {
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options)) . $separator;
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options))
. $separator;
}
$out .= $this->Html->tag($tag, $params['page'], array('class' => 'current'));
@ -515,7 +516,8 @@ class PaginatorHelper extends AppHelper {
$start = $params['page'] + 1;
for ($i = $start; $i < $end; $i++) {
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options)). $separator;
$out .= $this->Html->tag($tag, $this->link($i, array('page' => $i), $options))
. $separator;
}
if ($end != $params['page']) {
@ -591,7 +593,8 @@ class PaginatorHelper extends AppHelper {
}
$out .= $after;
} elseif ($params['page'] > 1) {
$out = $this->Html->tag($tag, $this->link($first, array('page' => 1), $options)) . $after;
$out = $this->Html->tag($tag, $this->link($first, array('page' => 1), $options))
. $after;
}
return $out;
}
@ -637,7 +640,9 @@ class PaginatorHelper extends AppHelper {
}
$out = $before . $out;
} elseif ($params['page'] < $params['pageCount']) {
$out = $before . $this->Html->tag($tag, $this->link($last, array('page' => $params['pageCount']), $options));
$out = $before . $this->Html->tag(
$tag, $this->link($last, array('page' => $params['pageCount']), $options
));
}
return $out;
}

View file

@ -1,5 +1,4 @@
<?php
/* SVN FILE: $Id$ */
/**
* ControllerTest file
*
@ -7,22 +6,18 @@
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* 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 Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
* 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 https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org
* @package cake
* @subpackage cake.tests.cases.libs.controller
* @since CakePHP(tm) v 1.2.0.5436
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Core', 'Controller');
App::import('Component', 'Security');
@ -988,6 +983,16 @@ class ControllerTest extends CakeTestCase {
$expected = 'http://cakephp.org';
$this->assertIdentical($result, $expected);
$_SERVER['HTTP_REFERER'] = '';
$referer = array(
'controller' => 'pages',
'action' => 'display',
'home'
);
$result = $Controller->referer($referer, false);
$expected = 'http://' . env('HTTP_HOST') . '/pages/display/home';;
$this->assertIdentical($result, $expected);
$_SERVER['HTTP_REFERER'] = '';
$result = $Controller->referer(null, false);
$expected = '/';

View file

@ -7,22 +7,18 @@
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* 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 Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
* 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 https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org
* @package cake
* @subpackage cake.tests.cases.libs
* @since CakePHP(tm) v 1.2.0.5432
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Core', 'Debugger');
/**
@ -88,10 +84,18 @@ class DebuggerTest extends CakeTestCase {
* @return void
*/
function testExcerpt() {
$return = Debugger::excerpt(__FILE__, 2, 2);
$this->assertTrue(is_array($return));
$this->assertEqual(count($return), 4);
$this->assertPattern('#/*&nbsp;SVN&nbsp;FILE:&nbsp;\$Id:&nbsp;debugger.test.php#', $return[1]);
$result = Debugger::excerpt(__FILE__, __LINE__, 2);
$this->assertTrue(is_array($result));
$this->assertEqual(count($result), 5);
$this->assertPattern('/function(.+)testExcerpt/', $result[1]);
$result = Debugger::excerpt(__FILE__, 2, 2);
$this->assertTrue(is_array($result));
$this->assertEqual(count($result), 4);
$expected = '<code><span style="color: #000000"><span style="color: #0000BB">&lt;?php';
$expected .= '</span></span></code>';
$this->assertEqual($result[0], $expected);
$return = Debugger::excerpt('[internal]', 2, 2);
$this->assertTrue(empty($return));
@ -135,14 +139,60 @@ class DebuggerTest extends CakeTestCase {
ob_start();
Debugger::output('js');
$buzz .= '';
$result = ob_get_clean();
$this->assertPattern("/<a href\='javascript:void\(0\);' onclick\='/", $result);
$this->assertPattern('/<b>Notice<\/b>/', $result);
$this->assertPattern('/Undefined variable: buzz/', $result);
$this->assertPattern('/<a[^>]+>Code<\/a>/', $result);
$this->assertPattern('/<a[^>]+>Context<\/a>/', $result);
$result = explode('</a>', ob_get_clean());
$this->assertTags($result[0], array(
'a' => array(
'href' => "javascript:void(0);",
'onclick' => "document.getElementById('cakeErr4-trace').style.display = " .
"(document.getElementById('cakeErr4-trace').style.display == 'none'" .
" ? '' : 'none');"
),
'b' => array(), 'Notice', '/b', ' (8)'
));
$this->assertPattern('/Undefined variable: buzz/', $result[1]);
$this->assertPattern('/<a[^>]+>Code/', $result[1]);
$this->assertPattern('/<a[^>]+>Context/', $result[2]);
set_error_handler('simpleTestErrorHandler');
}
/**
* Tests that changes in output formats using Debugger::output() change the templates used.
*
* @return void
*/
function testChangeOutputFormats() {
Debugger::invoke(Debugger::getInstance());
Debugger::output('js', array(
'traceLine' => '{:reference} - <a href="txmt://open?url=file://{:file}' .
'&line={:line}">{:path}</a>, line {:line}'
));
$result = Debugger::trace();
$this->assertPattern('/' . preg_quote('txmt://open?url=file:///', '/') . '/', $result);
Debugger::output('xml', array(
'error' => '<error><code>{:code}</code><file>{:file}</file><line>{:line}</line>' .
'{:description}</error>',
'context' => "<context>{:context}</context>",
'trace' => "<stack>{:trace}</stack>",
));
Debugger::output('xml');
ob_start();
$foo .= '';
$result = ob_get_clean();
set_error_handler('simpleTestErrorHandler');
$data = array(
'error' => array(),
'code' => array(), '8', '/code',
'file' => array(), 'preg:/[^<]+/', '/file',
'line' => array(), '' . (intval(__LINE__) + -8), '/line',
'Undefined variable: foo',
'/error'
);
$this->assertTags($result, $data, true);
}
/**
* testTrimPath method
*

View file

@ -1,5 +1,4 @@
<?php
/* SVN FILE: $Id$ */
/**
* BehaviorTest file
*
@ -7,21 +6,18 @@
*
* PHP versions 4 and 5
*
* CakePHP(tm) : Rapid Development Framework (http://www.cakephp.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 CakePHP(tm) : Rapid Development Framework (http://www.cakephp.org)
* @link http://www.cakephp.org
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org
* @package cake
* @subpackage cake.tests.cases.libs.model
* @since 1.2
* @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)
*/
App::import('Model', 'AppModel');
require_once dirname(__FILE__) . DS . 'models.php';
@ -796,26 +792,26 @@ class BehaviorTest extends CakeTestCase {
$Apple = new Apple();
$Apple->Behaviors->attach('Test', array('beforeFind' => 'off', 'beforeDelete' => 'off'));
$this->assertIdentical($Apple->del(6), true);
$this->assertIdentical($Apple->delete(6), true);
$Apple->Behaviors->attach('Test', array('beforeDelete' => 'on'));
$this->assertIdentical($Apple->delete(4), false);
$Apple->Behaviors->attach('Test', array('beforeDelete' => 'test2'));
if (ob_start()) {
$results = $Apple->del(4);
$results = $Apple->delete(4);
$this->assertIdentical(trim(ob_get_clean()), 'beforeDelete success (cascading)');
$this->assertIdentical($results, true);
}
if (ob_start()) {
$results = $Apple->del(3, false);
$results = $Apple->delete(3, false);
$this->assertIdentical(trim(ob_get_clean()), 'beforeDelete success');
$this->assertIdentical($results, true);
}
$Apple->Behaviors->attach('Test', array('beforeDelete' => 'off', 'afterDelete' => 'on'));
if (ob_start()) {
$results = $Apple->del(2, false);
$results = $Apple->delete(2, false);
$this->assertIdentical(trim(ob_get_clean()), 'afterDelete success');
$this->assertIdentical($results, true);
}
@ -836,7 +832,7 @@ class BehaviorTest extends CakeTestCase {
}
if (ob_start()) {
$Apple->del(99);
$Apple->delete(99);
//$this->assertIdentical(trim(ob_get_clean()), 'onError trigger success');
}
}

View file

@ -1,5 +1,4 @@
<?php
/* SVN FILE: $Id$ */
/**
* ModelTest file
*
@ -7,22 +6,18 @@
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* 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 Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
* 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 https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org
* @package cake
* @subpackage cake.tests.cases.libs.model
* @since CakePHP(tm) v 1.2.0.4206
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Core', array('AppModel', 'Model'));
require_once dirname(__FILE__) . DS . 'models.php';
@ -3890,7 +3885,7 @@ class ModelTest extends CakeTestCase {
$User = new CounterCacheUser();
$Post = new CounterCachePost();
$Post->del(2);
$Post->delete(2);
$user = $User->find('first', array(
'conditions' => array('id' => 66),'recursive' => -1
));
@ -4005,7 +4000,7 @@ class ModelTest extends CakeTestCase {
$this->loadFixtures('Article');
$TestModel =& new Article();
$result = $TestModel->del(2);
$result = $TestModel->delete(2);
$this->assertTrue($result);
$result = $TestModel->read(null, 2);
@ -4019,7 +4014,7 @@ class ModelTest extends CakeTestCase {
);
$this->assertEqual($result, $expected);
$result = $TestModel->del(3);
$result = $TestModel->delete(3);
$this->assertTrue($result);
$result = $TestModel->read(null, 3);
@ -4130,7 +4125,7 @@ class ModelTest extends CakeTestCase {
$this->loadFixtures('Article', 'Comment', 'Attachment');
$TestModel =& new Article();
$result = $TestModel->del(2);
$result = $TestModel->delete(2);
$this->assertTrue($result);
$TestModel->recursive = 2;
@ -6369,7 +6364,7 @@ class ModelTest extends CakeTestCase {
$Cd =& new Cd();
$OverallFavorite =& new OverallFavorite();
$Cd->del(1);
$Cd->delete(1);
$result = $OverallFavorite->find('all', array('fields' => array('model_type', 'model_id', 'priority')));
$expected = array(array('OverallFavorite' => array('model_type' => 'Book', 'model_id' => 1, 'priority' => 2)));

View file

@ -7,22 +7,18 @@
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* 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 Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
* 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 https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @copyright Copyright 2005-2009, Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org
* @package cake
* @subpackage cake.tests.cases.libs
* @since CakePHP(tm) v 1.2.0.5432
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
*/
App::import('Core', 'String');
/**
@ -32,6 +28,7 @@ App::import('Core', 'String');
* @subpackage cake.tests.cases.libs
*/
class StringTest extends CakeTestCase {
/**
* testUuidGeneration method
*
@ -44,6 +41,7 @@ class StringTest extends CakeTestCase {
$match = preg_match($pattern, $result);
$this->assertTrue($match);
}
/**
* testMultipleUuidGeneration method
*
@ -63,6 +61,7 @@ class StringTest extends CakeTestCase {
$check[] = $result;
}
}
/**
* testInsert method
*
@ -199,13 +198,16 @@ class StringTest extends CakeTestCase {
$expected = "Pre-pended result";
$this->assertEqual($result, $expected);
}
/**
* test Clean Insert
*
* @return void
**/
function testCleanInsert() {
$result = String::cleanInsert(':incomplete', array('clean' => true, 'before' => ':', 'after' => ''));
$result = String::cleanInsert(':incomplete', array(
'clean' => true, 'before' => ':', 'after' => ''
));
$this->assertEqual($result, '');
$result = String::cleanInsert(':incomplete', array(
@ -214,18 +216,40 @@ class StringTest extends CakeTestCase {
);
$this->assertEqual($result, 'complete');
$result = String::cleanInsert(':in.complete', array('clean' => true, 'before' => ':', 'after' => ''));
$result = String::cleanInsert(':in.complete', array(
'clean' => true, 'before' => ':', 'after' => ''
));
$this->assertEqual($result, '');
$result = String::cleanInsert(':in.complete and', array('clean' => true, 'before' => ':', 'after' => ''));
$result = String::cleanInsert(':in.complete and', array(
'clean' => true, 'before' => ':', 'after' => '')
);
$this->assertEqual($result, '');
$result = String::cleanInsert(':in.complete or stuff', array('clean' => true, 'before' => ':', 'after' => ''));
$result = String::cleanInsert(':in.complete or stuff', array(
'clean' => true, 'before' => ':', 'after' => ''
));
$this->assertEqual($result, 'stuff');
$result = String::cleanInsert('<p class=":missing" id=":missing">Text here</p>', array('clean' => 'html', 'before' => ':', 'after' => ''));
$result = String::cleanInsert(
'<p class=":missing" id=":missing">Text here</p>',
array('clean' => 'html', 'before' => ':', 'after' => '')
);
$this->assertEqual($result, '<p>Text here</p>');
}
/**
* Tests that non-insertable variables (i.e. arrays) are skipped when used as values in
* String::insert().
*
* @return void
*/
function testAutoIgnoreBadInsertData() {
$data = array('foo' => 'alpha', 'bar' => 'beta', 'fale' => array());
$result = String::insert('(:foo > :bar || :fale!)', $data, array('clean' => 'text'));
$this->assertEqual($result, '(alpha > beta || !)');
}
/**
* testTokenize method
*
@ -254,4 +278,5 @@ class StringTest extends CakeTestCase {
$this->assertEqual($expected, $result);
}
}
?>

View file

@ -1,29 +1,25 @@
<?php
/* SVN FILE: $Id$ */
/**
* Requests collector.
*
* This file collects requests if:
* - no mod_rewrite is avilable or .htaccess files are not supported
* -/public is not set as a web root.
* - requires App.baseUrl to be uncommented in app/config/core.php
* - app/webroot is not set as a document root.
*
* 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
* @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)
*/
/**
* Get Cake's root directory
@ -34,29 +30,27 @@
define('WEBROOT_DIR', 'webroot');
define('WWW_ROOT', ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS);
/**
* This only needs to be changed if the cake installed libs are located
* outside of the distributed directory structure.
* This only needs to be changed if the "cake" directory is located
* outside of the distributed structure.
* Full path to the directory containing "cake". Do not add trailing directory separator
*/
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
//define ('CAKE_CORE_INCLUDE_PATH', FULL PATH TO DIRECTORY WHERE CAKE CORE IS INSTALLED DO NOT ADD A TRAILING DIRECTORY SEPARATOR';
define('CAKE_CORE_INCLUDE_PATH', ROOT);
}
/**
* Set the include path or define app and core path
*/
if (function_exists('ini_set')) {
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . CAKE_CORE_INCLUDE_PATH . PATH_SEPARATOR . ROOT . DS . APP_DIR . DS);
ini_set('include_path',
ini_get('include_path') . PATH_SEPARATOR . CAKE_CORE_INCLUDE_PATH
. PATH_SEPARATOR . ROOT . DS . APP_DIR . DS
);
define('APP_PATH', null);
define('CORE_PATH', null);
} else {
define('APP_PATH', ROOT . DS . APP_DIR . DS);
define('CORE_PATH', CAKE_CORE_INCLUDE_PATH . DS);
}
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';
$bootstrap = true;
$url = null;
require APP_DIR . DS . WEBROOT_DIR . DS . 'index.php';
?>