"Closes #2508, Allow requestAction to use array urls

Fixes #4325, error pages no longer displayed since changeset
Closes #4329, remove am() usage in core"

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6563 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2008-03-12 21:19:31 +00:00
parent 698d3e4f40
commit acc79fe0f3
21 changed files with 292 additions and 114 deletions

View file

@ -47,7 +47,7 @@ class ApiShell extends Shell {
* @access public * @access public
*/ */
function initialize () { function initialize () {
$this->paths = am($this->paths, array( $this->paths = array_merge($this->paths, array(
'behavior' => LIBS . 'model' . DS . 'behaviors' . DS, 'behavior' => LIBS . 'model' . DS . 'behaviors' . DS,
'cache' => LIBS . 'cache' . DS, 'cache' => LIBS . 'cache' . DS,
'controller' => LIBS . 'controller' . DS, 'controller' => LIBS . 'controller' . DS,

View file

@ -178,7 +178,7 @@ class DbConfigTask extends Shell {
* @access private * @access private
*/ */
function __verify($config) { function __verify($config) {
$config = am($this->__defaultConfig, $config); $config = array_merge($this->__defaultConfig, $config);
extract($config); extract($config);
$this->out(''); $this->out('');
$this->hr(); $this->hr();
@ -262,12 +262,12 @@ class DbConfigTask extends Shell {
} }
} }
$configs = am($oldConfigs, $configs); $configs = array_merge($oldConfigs, $configs);
$out = "<?php\n"; $out = "<?php\n";
$out .= "class DATABASE_CONFIG {\n\n"; $out .= "class DATABASE_CONFIG {\n\n";
foreach ($configs as $config) { foreach ($configs as $config) {
$config = am($this->__defaultConfig, $config); $config = array_merge($this->__defaultConfig, $config);
extract($config); extract($config);
$out .= "\tvar \${$name} = array(\n"; $out .= "\tvar \${$name} = array(\n";
$out .= "\t\t'driver' => '{$driver}',\n"; $out .= "\t\t'driver' => '{$driver}',\n";

View file

@ -138,7 +138,7 @@ class ViewTask extends Shell {
$adminDelete = $adminRoute.'_delete'; $adminDelete = $adminRoute.'_delete';
} }
foreach ($methods as $method) { foreach ($methods as $method) {
if ($method{0} != '_' && !in_array(low($method), am($protected, array('delete', $adminDelete)))) { if ($method{0} != '_' && !in_array(low($method), array_merge($protected, array('delete', $adminDelete)))) {
$content = $this->getContent($method, $vars); $content = $this->getContent($method, $vars);
$this->bake($method, $content); $this->bake($method, $content);
} }

View file

@ -108,20 +108,32 @@ class Dispatcher extends Object {
* @access public * @access public
*/ */
function dispatch($url = null, $additionalParams = array()) { function dispatch($url = null, $additionalParams = array()) {
$parse = true;
if ($this->base === false) { if ($this->base === false) {
$this->base = $this->baseUrl(); $this->base = $this->baseUrl();
} }
if (is_array($url)) {
$url = $this->extractParams($url, $additionalParams);
$parse = false;
}
if ($url !== null) { if ($url !== null) {
$_GET['url'] = $url; $_GET['url'] = $url;
} }
$url = $this->getUrl(); if ($parse) {
$url = $this->getUrl();
}
$this->here = $this->base . '/' . $url; $this->here = $this->base . '/' . $url;
if ($this->cached($url)) { if ($this->cached($url)) {
exit(); exit();
} }
$this->params = array_merge($this->parseParams($url), $additionalParams);
if ($parse) {
$this->params = array_merge($this->parseParams($url), $additionalParams);
}
$controller = $this->__getController(); $controller = $this->__getController();
if (!is_object($controller)) { if (!is_object($controller)) {
@ -155,7 +167,7 @@ class Dispatcher extends Object {
$protected = array_map('strtolower', get_class_methods('controller')); $protected = array_map('strtolower', get_class_methods('controller'));
$classMethods = array_map('strtolower', get_class_methods($controller)); $classMethods = array_map('strtolower', get_class_methods($controller));
if (in_array(strtolower($this->params['action']), $protected) || strpos($this->params['action'], '_', 0) === 0) { if (in_array(strtolower($this->params['action']), $protected) || strpos($this->params['action'], '_', 0) === 0) {
$privateAction = true; $privateAction = true;
} }
@ -267,6 +279,9 @@ class Dispatcher extends Object {
} }
} }
$controller->afterFilter(); $controller->afterFilter();
if (isset($params['return'])) {
return $controller->output;
}
e($controller->output); e($controller->output);
} }
/** /**
@ -278,7 +293,7 @@ class Dispatcher extends Object {
*/ */
function start(&$controller) { function start(&$controller) {
if (!empty($controller->beforeFilter)) { if (!empty($controller->beforeFilter)) {
trigger_error(sprintf(__('Dispatcher::start - Controller::$beforeFilter property usage is deprecated and will no longer be supported. Use Controller::beforeFilter().', true)), E_USER_WARNING); trigger_error(sprintf(__('Dispatcher::start - Controller::$beforeFilter property usage is deprecated and will no longer be supported. Use Controller::beforeFilter().', true)), E_USER_WARNING);
if (is_array($controller->beforeFilter)) { if (is_array($controller->beforeFilter)) {
foreach ($controller->beforeFilter as $filter) { foreach ($controller->beforeFilter as $filter) {
@ -304,7 +319,22 @@ class Dispatcher extends Object {
} }
} }
} }
/**
* Sets the params when $url is passed as an array to Object::requestAction();
*
* @param array $url
* @param array $additionalParams
* @return null
* @access private
* @todo commented Router::url(). this improved performance,
* will work on this more later.
*/
function extractParams($url, $additionalParams = array()) {
$defaults = array('pass' => array(), 'named' => array(), 'form' => array());
$this->params = array_merge($defaults, $url, $additionalParams);
//$url = Router::url($url);
//return $url;
}
/** /**
* Returns array of GET and POST parameters. GET parameters are taken from given URL. * Returns array of GET and POST parameters. GET parameters are taken from given URL.
* *
@ -401,10 +431,10 @@ class Dispatcher extends Object {
$base = dirname(env('PHP_SELF')); $base = dirname(env('PHP_SELF'));
if ($webroot === 'webroot' && $webroot === basename($base)) { if ($webroot === 'webroot' && $webroot === basename($base)) {
$base = dirname($base); $base = dirname($base);
} }
if ($dir === 'app' && $dir === basename($base)) { if ($dir === 'app' && $dir === basename($base)) {
$base = dirname($base); $base = dirname($base);
} }
if (in_array($base, array(DS, '.'))) { if (in_array($base, array(DS, '.'))) {
@ -425,7 +455,7 @@ class Dispatcher extends Object {
$this->webroot = $base .'/'; $this->webroot = $base .'/';
if (strpos($this->webroot, $dir) === false) { if (strpos($this->webroot, $dir) === false) {
$this->webroot .= $dir . '/' ; $this->webroot .= $dir . '/' ;
} }
if (strpos($this->webroot, $webroot) === false) { if (strpos($this->webroot, $webroot) === false) {
$this->webroot .= $webroot . '/'; $this->webroot .= $webroot . '/';
@ -640,7 +670,7 @@ class Dispatcher extends Object {
$isAsset = false; $isAsset = false;
foreach ($assets as $type => $contentType) { foreach ($assets as $type => $contentType) {
$pos = strpos($url, $type . '/'); $pos = strpos($url, $type . '/');
if ($pos !== false) { if ($pos !== false) {
$isAsset = true; $isAsset = true;
break; break;
} }

View file

@ -59,9 +59,9 @@ class ErrorHandler extends Object {
$this->controller->viewPath = 'errors'; $this->controller->viewPath = 'errors';
$allow = array('.', '/', '_', ' ', '-', '~'); $allow = array('.', '/', '_', ' ', '-', '~');
if (substr(PHP_OS,0,3) == "WIN") { if (substr(PHP_OS,0,3) == "WIN") {
$allow = array_merge($allow, array('\\', ':') ); $allow = array_merge($allow, array('\\', ':') );
} }
App::import('Core', 'Sanitize'); App::import('Core', 'Sanitize');
$messages = Sanitize::paranoid($messages, $allow); $messages = Sanitize::paranoid($messages, $allow);
@ -103,7 +103,7 @@ class ErrorHandler extends Object {
'name' => $name, 'name' => $name,
'message' => $message, 'message' => $message,
'title' => $code . ' ' . $name)); 'title' => $code . ' ' . $name));
$this->controller->render('error404'); $this->__outputMessage('error404');
} }
/** /**
* Convenience method to display a 404 page. * Convenience method to display a 404 page.
@ -123,7 +123,7 @@ class ErrorHandler extends Object {
'name' => __('Not Found', true), 'name' => __('Not Found', true),
'message' => sprintf(__("The requested address %s was not found on this server.", true), "<strong>'{$url}'</strong>"), 'message' => sprintf(__("The requested address %s was not found on this server.", true), "<strong>'{$url}'</strong>"),
'base' => $this->controller->base)); 'base' => $this->controller->base));
$this->controller->render('error404'); $this->__outputMessage('error404');
} }
/** /**
* Renders the Missing Controller web page. * Renders the Missing Controller web page.
@ -138,7 +138,7 @@ class ErrorHandler extends Object {
$this->controller->set(array('controller' => $className, $this->controller->set(array('controller' => $className,
'controllerName' => $controllerName, 'controllerName' => $controllerName,
'title' => __('Missing Controller', true))); 'title' => __('Missing Controller', true)));
$this->controller->render('missingController'); $this->__outputMessage('missingController');
} }
/** /**
* Renders the Missing Action web page. * Renders the Missing Action web page.
@ -154,7 +154,7 @@ class ErrorHandler extends Object {
'controllerName' => $controllerName, 'controllerName' => $controllerName,
'action' => $action, 'action' => $action,
'title' => __('Missing Method in Controller', true))); 'title' => __('Missing Method in Controller', true)));
$this->controller->render('missingAction'); $this->__outputMessage('missingAction');
} }
/** /**
* Renders the Private Action web page. * Renders the Private Action web page.
@ -168,7 +168,7 @@ class ErrorHandler extends Object {
$this->controller->set(array('controller' => $className, $this->controller->set(array('controller' => $className,
'action' => $action, 'action' => $action,
'title' => __('Trying to access private method in class', true))); 'title' => __('Trying to access private method in class', true)));
$this->controller->render('privateAction'); $this->__outputMessage('privateAction');
} }
/** /**
* Renders the Missing Table web page. * Renders the Missing Table web page.
@ -182,7 +182,7 @@ class ErrorHandler extends Object {
$this->controller->set(array('model' => $className, $this->controller->set(array('model' => $className,
'table' => $table, 'table' => $table,
'title' => __('Missing Database Table', true))); 'title' => __('Missing Database Table', true)));
$this->controller->render('missingTable'); $this->__outputMessage('missingTable');
} }
/** /**
* Renders the Missing Database web page. * Renders the Missing Database web page.
@ -194,7 +194,7 @@ class ErrorHandler extends Object {
extract($params, EXTR_OVERWRITE); extract($params, EXTR_OVERWRITE);
$this->controller->set(array('title' => __('Scaffold Missing Database Connection', true))); $this->controller->set(array('title' => __('Scaffold Missing Database Connection', true)));
$this->controller->render('missingScaffolddb'); $this->__outputMessage('missingScaffolddb');
} }
/** /**
* Renders the Missing View web page. * Renders the Missing View web page.
@ -209,7 +209,8 @@ class ErrorHandler extends Object {
'action' => $action, 'action' => $action,
'file' => $file, 'file' => $file,
'title' => __('Missing View', true))); 'title' => __('Missing View', true)));
$this->controller->render('missingView'); $this->__outputMessage('missingView');
} }
/** /**
* Renders the Missing Layout web page. * Renders the Missing Layout web page.
@ -221,9 +222,9 @@ class ErrorHandler extends Object {
extract($params, EXTR_OVERWRITE); extract($params, EXTR_OVERWRITE);
$this->controller->layout = 'default'; $this->controller->layout = 'default';
$this->controller->set(array('file' => $file, $this->controller->set(array('file' => $file,
'title' => __('Missing Layout', true))); 'title' => __('Missing Layout', true)));
$this->controller->render('missingLayout'); $this->__outputMessage('missingLayout');
} }
/** /**
* Renders the Database Connection web page. * Renders the Database Connection web page.
@ -236,7 +237,7 @@ class ErrorHandler extends Object {
$this->controller->set(array('model' => $className, $this->controller->set(array('model' => $className,
'title' => __('Missing Database Connection', true))); 'title' => __('Missing Database Connection', true)));
$this->controller->render('missingConnection'); $this->__outputMessage('missingConnection');
} }
/** /**
* Renders the Missing Helper file web page. * Renders the Missing Helper file web page.
@ -250,7 +251,7 @@ class ErrorHandler extends Object {
$this->controller->set(array('helperClass' => Inflector::camelize($helper) . "Helper", $this->controller->set(array('helperClass' => Inflector::camelize($helper) . "Helper",
'file' => $file, 'file' => $file,
'title' => __('Missing Helper File', true))); 'title' => __('Missing Helper File', true)));
$this->controller->render('missingHelperFile'); $this->__outputMessage('missingHelperFile');
} }
/** /**
* Renders the Missing Helper class web page. * Renders the Missing Helper class web page.
@ -264,7 +265,7 @@ class ErrorHandler extends Object {
$this->controller->set(array('helperClass' => Inflector::camelize($helper) . "Helper", $this->controller->set(array('helperClass' => Inflector::camelize($helper) . "Helper",
'file' => $file, 'file' => $file,
'title' => __('Missing Helper Class', true))); 'title' => __('Missing Helper Class', true)));
$this->controller->render('missingHelperClass'); $this->__outputMessage('missingHelperClass');
} }
/** /**
* Renders the Missing Component file web page. * Renders the Missing Component file web page.
@ -279,7 +280,7 @@ class ErrorHandler extends Object {
'component' => $component, 'component' => $component,
'file' => $file, 'file' => $file,
'title' => __('Missing Component File', true))); 'title' => __('Missing Component File', true)));
$this->controller->render('missingComponentFile'); $this->__outputMessage('missingComponentFile');
} }
/** /**
* Renders the Missing Component class web page. * Renders the Missing Component class web page.
@ -294,7 +295,7 @@ class ErrorHandler extends Object {
'component' => $component, 'component' => $component,
'file' => $file, 'file' => $file,
'title' => __('Missing Component Class', true))); 'title' => __('Missing Component Class', true)));
$this->controller->render('missingComponentClass'); $this->__outputMessage('missingComponentClass');
} }
/** /**
* Renders the Missing Model class web page. * Renders the Missing Model class web page.
@ -307,7 +308,17 @@ class ErrorHandler extends Object {
$this->controller->set(array('model' => $className, $this->controller->set(array('model' => $className,
'title' => __('Missing Model', true))); 'title' => __('Missing Model', true)));
$this->controller->render('missingModel'); $this->__outputMessage('missingModel');
}
/**
* Output message
*
* @access private
*/
function __outputMessage($template) {
$this->controller->render($template);
$this->controller->afterFilter();
e($this->controller->output);
} }
} }
?> ?>

View file

@ -487,7 +487,7 @@ class TreeBehavior extends ModelBehavior {
* @todo Could be written to be faster, *maybe*. Ideally using a subquery and putting all the logic burden on the DB. * @todo Could be written to be faster, *maybe*. Ideally using a subquery and putting all the logic burden on the DB.
* @param AppModel $model * @param AppModel $model
* @param string $mode parent or tree * @param string $mode parent or tree
* @param mixed $missingParentAction 'return' to do nothing and return, 'delete' to * @param mixed $missingParentAction 'return' to do nothing and return, 'delete' to
* delete, or the id of the parent to set as the parent_id * delete, or the id of the parent to set as the parent_id
* @return boolean true on success, false on failure * @return boolean true on success, false on failure
* @access public * @access public
@ -505,14 +505,14 @@ class TreeBehavior extends ModelBehavior {
'fields' => array($model->primaryKey, $left, $right, $parent, 'fields' => array($model->primaryKey, $left, $right, $parent,
'actsAs' => '') 'actsAs' => '')
)))); ))));
$missingParents = $model->find('list', array('recursive' => 0, 'conditions' => $missingParents = $model->find('list', array('recursive' => 0, 'conditions' =>
array($scope, array('NOT' => array($model->escapeField($parent) => null), $model->VerifyParent->escapeField() => null)))); array($scope, array('NOT' => array($model->escapeField($parent) => null), $model->VerifyParent->escapeField() => null))));
$model->unbindModel(array('belongsTo' => array('VerifyParent'))); $model->unbindModel(array('belongsTo' => array('VerifyParent')));
if ($missingParents) { if ($missingParents) {
if ($missingParentAction == 'return') { if ($missingParentAction == 'return') {
foreach ($missingParents as $id => $display) { foreach ($missingParents as $id => $display) {
$this->errors[] = 'cannot find the parent for ' . $model->alias . ' with id ' . $id . '(' . $display . ')'; $this->errors[] = 'cannot find the parent for ' . $model->alias . ' with id ' . $id . '(' . $display . ')';
} }
return false; return false;
} elseif ($missingParentAction == 'delete') { } elseif ($missingParentAction == 'delete') {
@ -555,11 +555,11 @@ class TreeBehavior extends ModelBehavior {
* Requires a valid tree, by default it verifies the tree before beginning. * Requires a valid tree, by default it verifies the tree before beginning.
* *
* @param AppModel $model * @param AppModel $model
* @param array $options * @param array $options
* @return boolean true on success, false on failure * @return boolean true on success, false on failure
*/ */
function reorder(&$model, $options = array()) { function reorder(&$model, $options = array()) {
$options = am(array('id' => null, 'field' => $model->displayField, 'order' => 'ASC', 'verify' => true), $options); $options = array_merge(array('id' => null, 'field' => $model->displayField, 'order' => 'ASC', 'verify' => true), $options);
extract($options); extract($options);
if ($verify && !$model->verify()) { if ($verify && !$model->verify()) {
return false; return false;
@ -575,7 +575,7 @@ class TreeBehavior extends ModelBehavior {
$model->moveDown($id, true); $model->moveDown($id, true);
if ($node[$model->alias][$left] != $node[$model->alias][$right] - 1) { if ($node[$model->alias][$left] != $node[$model->alias][$right] - 1) {
$this->reorder($model, compact('id', 'field', 'order', 'verify')); $this->reorder($model, compact('id', 'field', 'order', 'verify'));
} }
} }
} }
return true; return true;

View file

@ -131,7 +131,7 @@ class DboOracle extends DboSource {
* @access protected * @access protected
*/ */
var $_results; var $_results;
/** /**
* Base configuration settings for MySQL driver * Base configuration settings for MySQL driver
* *
@ -156,7 +156,7 @@ class DboOracle extends DboSource {
$config = $this->config; $config = $this->config;
$this->connected = false; $this->connected = false;
$config['charset'] = !empty($config['charset']) ? $config['charset'] : null; $config['charset'] = !empty($config['charset']) ? $config['charset'] : null;
if ($this->config['persistent']) { if ($this->config['persistent']) {
$connect = 'ociplogon'; $connect = 'ociplogon';
} else { } else {
@ -451,7 +451,7 @@ class DboOracle extends DboSource {
$this->__cacheDescription($this->fullTableName($model, false), $fields); $this->__cacheDescription($this->fullTableName($model, false), $fields);
return $fields; return $fields;
} }
/** /**
* Returns an array of the indexes in given table name. * Returns an array of the indexes in given table name.
* *
@ -462,20 +462,20 @@ class DboOracle extends DboSource {
$index = array(); $index = array();
$table = $this->fullTableName($model, false); $table = $this->fullTableName($model, false);
if($table) { if($table) {
$indexes = $this->query('SELECT $indexes = $this->query('SELECT
cc.table_name, cc.table_name,
cc.column_name, cc.column_name,
cc.constraint_name, cc.constraint_name,
c.constraint_type, c.constraint_type,
i.index_name, i.index_name,
i.uniqueness i.uniqueness
FROM user_cons_columns cc FROM user_cons_columns cc
LEFT JOIN user_indexes i ON(cc.constraint_name = i.index_name) LEFT JOIN user_indexes i ON(cc.constraint_name = i.index_name)
LEFT JOIN user_constraints c ON(c.constraint_name = cc.constraint_name) LEFT JOIN user_constraints c ON(c.constraint_name = cc.constraint_name)
WHERE cc.table_name = \'' . strtoupper($table) .'\''); WHERE cc.table_name = \'' . strtoupper($table) .'\'');
foreach ($indexes as $i => $idx) { foreach ($indexes as $i => $idx) {
if ($idx['c']['constraint_type'] == 'P') { if ($idx['c']['constraint_type'] == 'P') {
$key = 'PRIMARY'; $key = 'PRIMARY';
} else { } else {
continue; continue;
} }
@ -493,7 +493,7 @@ class DboOracle extends DboSource {
} }
return $index; return $index;
} }
/** /**
* Generate a Oracle Alter Table syntax for the given Schema comparison * Generate a Oracle Alter Table syntax for the given Schema comparison
* *
@ -542,7 +542,7 @@ class DboOracle extends DboSource {
} }
return $out; return $out;
} }
/** /**
* This method should quote Oracle identifiers. Well it doesn't. * This method should quote Oracle identifiers. Well it doesn't.
* It would break all scaffolding and all of Cake's default assumptions. * It would break all scaffolding and all of Cake's default assumptions.
@ -740,7 +740,7 @@ class DboOracle extends DboSource {
function insertMulti($table, $fields, $values) { function insertMulti($table, $fields, $values) {
parent::__insertMulti($table, $fields, $values); parent::__insertMulti($table, $fields, $values);
} }
/** /**
* Renders a final SQL statement by putting together the component parts in the correct order * Renders a final SQL statement by putting together the component parts in the correct order
* *
@ -770,7 +770,7 @@ class DboOracle extends DboSource {
break; break;
} }
} }
/** /**
* Enter description here... * Enter description here...
* *
@ -814,7 +814,7 @@ class DboOracle extends DboSource {
foreach ($ins as $i) { foreach ($ins as $i) {
$q = str_replace('{$__cakeID__$}', join(', ', $i), $query); $q = str_replace('{$__cakeID__$}', join(', ', $i), $query);
$res = $this->fetchAll($q, $model->cacheQueries, $model->alias); $res = $this->fetchAll($q, $model->cacheQueries, $model->alias);
$fetch = am($fetch, $res); $fetch = array_merge($fetch, $res);
} }
} }
@ -845,7 +845,7 @@ class DboOracle extends DboSource {
$ins[] = $in; $ins[] = $in;
} }
} }
$foreignKey = $model->hasAndBelongsToMany[$association]['foreignKey']; $foreignKey = $model->hasAndBelongsToMany[$association]['foreignKey'];
$joinKeys = array($foreignKey, $model->hasAndBelongsToMany[$association]['associationForeignKey']); $joinKeys = array($foreignKey, $model->hasAndBelongsToMany[$association]['associationForeignKey']);
list($with, $habtmFields) = $model->joinModel($model->hasAndBelongsToMany[$association]['with'], $joinKeys); list($with, $habtmFields) = $model->joinModel($model->hasAndBelongsToMany[$association]['with'], $joinKeys);
@ -861,7 +861,7 @@ class DboOracle extends DboSource {
$q = $this->insertQueryData($q, null, $association, $assocData, $model, $linkModel, $stack); $q = $this->insertQueryData($q, null, $association, $assocData, $model, $linkModel, $stack);
if ($q != false) { if ($q != false) {
$res = $this->fetchAll($q, $model->cacheQueries, $model->alias); $res = $this->fetchAll($q, $model->cacheQueries, $model->alias);
$fetch = am($fetch, $res); $fetch = array_merge($fetch, $res);
} }
} }
} }
@ -927,7 +927,7 @@ class DboOracle extends DboSource {
} }
} }
} }
} }
?> ?>

View file

@ -79,46 +79,36 @@ class Object {
/** /**
* Calls a controller's method from any location. * Calls a controller's method from any location.
* *
* @param string $url URL in the form of Cake URL ("/controller/method/parameter") * @param string $url URL in the form of Cake URL ("/controller/method/parameter")
* @param array $extra If array includes the key "return" it sets the AutoRender to true. * @param array $extra if array includes the key "return" it sets the AutoRender to true.
* @return mixed Success (true/false) or contents if 'return' is set in $extra * @return mixed Success (true/false) or contents if 'return' is set in $extra
* @access public * @access public
*/ */
function requestAction($url, $extra = array()) { function requestAction($url, $extra = array()) {
if (!empty($url)) { if (empty($url)) {
if (!class_exists('dispatcher')) {
require CAKE . 'dispatcher.php';
}
$dispatcher =& new Dispatcher();
if (in_array('return', $extra, true)) {
$extra['return'] = 0;
$extra['bare'] = 1;
$extra['requested'] = 1;
ob_start();
$out = $dispatcher->dispatch($url, $extra);
$out = ob_get_clean();
return $out;
} else {
$extra['return'] = 1;
$extra['bare'] = 1;
$extra['requested'] = 1;
return $dispatcher->dispatch($url, $extra);
}
} else {
return false; return false;
} }
} if (!class_exists('dispatcher')) {
require CAKE . 'dispatcher.php';
}
if (in_array('return', $extra, true)) {
$extra = array_merge($extra, array('return' => 0, 'autoRender' => 1));
}
$params = am(array('autoRender' => 0, 'return' => 1, 'bare' => 1, 'requested' => 1), $extra);
$dispatcher = new Dispatcher;
return $dispatcher->dispatch($url, $params);
}
/** /**
* Calls a method on this object with the given parameters. Provides an OO wrapper * Calls a method on this object with the given parameters. Provides an OO wrapper
* for call_user_func_array, and improves performance by using straight method calls * for call_user_func_array, and improves performance by using straight method calls
* in most cases. * in most cases.
* *
* @param string $method Name of the method to call * @param string $method Name of the method to call
* @param array $params Parameter list to use when calling $method * @param array $params Parameter list to use when calling $method
* @param boolean $strict If true, checks to make sure that $method is defined * @param boolean $strict If true, checks to make sure that $method is defined
* in this object. Throws a warning if not. * in this object. Throws a warning if not.
* @return mixed Returns the result of the method call, or null if $strict is * @return mixed Returns the result of the method call, or null if $strict is
* true and the method was not found * true and the method was not found
* @access public * @access public
*/ */
function dispatchMethod($method, $params = array(), $strict = false) { function dispatchMethod($method, $params = array(), $strict = false) {

View file

@ -881,7 +881,7 @@ class Set extends Object {
$stack = array(); $stack = array();
foreach ($results as $k => $r) { foreach ($results as $k => $r) {
if (is_array($r)) { if (is_array($r)) {
$stack = am($stack, Set::__flatten($r, $k)); $stack = array_merge($stack, Set::__flatten($r, $k));
} else { } else {
if (!empty($key)) { if (!empty($key)) {
$id = $key; $id = $key;
@ -894,7 +894,7 @@ class Set extends Object {
return $stack; return $stack;
} }
/** /**
* Sorts an array by any value, determined by a Set-compatible path * Sorts an array by any value, determined by a Set-compatible path
* *
* @param array $data * @param array $data
* @param string $path A Set-compatible path to the array value * @param string $path A Set-compatible path to the array value

View file

@ -303,8 +303,8 @@ class View extends Object {
return $cache; return $cache;
} else { } else {
$element = $this->renderElement($name, $params); $element = $this->renderElement($name, $params);
cache('views' . DS . $cacheFile, $element, $expires); cache('views' . DS . $cacheFile, $element, $expires);
return $element; return $element;
} }
} }
} }
@ -428,10 +428,10 @@ class View extends Object {
$data_for_layout = array_merge($this->viewVars, $data_for_layout = array_merge($this->viewVars,
array( array(
'title_for_layout' => $pageTitle, 'title_for_layout' => $pageTitle,
'content_for_layout' => $content_for_layout, 'content_for_layout' => $content_for_layout,
'scripts_for_layout' => join("\n\t", $this->__scripts), 'scripts_for_layout' => join("\n\t", $this->__scripts),
'cakeDebug' => $debug 'cakeDebug' => $debug
) )
); );
@ -557,7 +557,7 @@ class View extends Object {
} }
/** /**
* Allows a template or element to set a variable that will be available in * Allows a template or element to set a variable that will be available in
* a layout or other element. Analagous to Controller::set. * a layout or other element. Analagous to Controller::set.
* *
* @param mixed $one A string or an array of data. * @param mixed $one A string or an array of data.
* @param mixed $two Value in case $one is a string (which then works as the key). * @param mixed $two Value in case $one is a string (which then works as the key).
@ -707,7 +707,7 @@ class View extends Object {
if (in_array($helper, array_keys($loaded)) !== true) { if (in_array($helper, array_keys($loaded)) !== true) {
if (!class_exists($helperCn)) { if (!class_exists($helperCn)) {
if (is_null($plugin) || !App::import('Helper', $plugin . '.' . $helper)) { if (is_null($plugin) || !App::import('Helper', $plugin . '.' . $helper)) {
if (!App::import('Helper', $helper)) { if (!App::import('Helper', $helper)) {
$this->cakeError('missingHelperFile', array(array( $this->cakeError('missingHelperFile', array(array(
'helper' => $helper, 'helper' => $helper,
@ -716,7 +716,7 @@ class View extends Object {
))); )));
return false; return false;
} }
} }
if (!class_exists($helperCn)) { if (!class_exists($helperCn)) {
$this->cakeError('missingHelperClass', array(array( $this->cakeError('missingHelperClass', array(array(
'helper' => $helper, 'helper' => $helper,

View file

@ -565,10 +565,10 @@ class HttpSocketTest extends UnitTestCase {
foreach ($tests as $name => $test) { foreach ($tests as $name => $test) {
$testResponse = am($testResponse, $test['response']); $testResponse = array_merge($testResponse, $test['response']);
$testResponse['response'] = $testResponse['status-line'].$testResponse['header']."\r\n".$testResponse['body']; $testResponse['response'] = $testResponse['status-line'].$testResponse['header']."\r\n".$testResponse['body'];
$r = $this->Socket->parseResponse($testResponse['response']); $r = $this->Socket->parseResponse($testResponse['response']);
$expectations = am($expectations, $test['expectations']); $expectations = array_merge($expectations, $test['expectations']);
foreach ($expectations as $property => $expectedVal) { foreach ($expectations as $property => $expectedVal) {
$val = Set::extract($r, $property); $val = Set::extract($r, $property);

View file

@ -325,7 +325,7 @@ class TranslateTest extends CakeTestCase {
$this->Model->create($data); $this->Model->create($data);
$this->Model->save(); $this->Model->save();
$result = $this->Model->read(); $result = $this->Model->read();
$expected = array('TranslatedItem' => am($data, array('id' => $this->Model->id, 'locale' => 'spa'))); $expected = array('TranslatedItem' => array_merge($data, array('id' => $this->Model->id, 'locale' => 'spa')));
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
} }
@ -339,7 +339,7 @@ class TranslateTest extends CakeTestCase {
$this->Model->create($newData); $this->Model->create($newData);
$this->Model->save(); $this->Model->save();
$result = $this->Model->read(null, $id); $result = $this->Model->read(null, $id);
$expected = array('TranslatedItem' => am($oldData, $newData, array('locale' => 'spa'))); $expected = array('TranslatedItem' => array_merge($oldData, $newData, array('locale' => 'spa')));
$this->assertEqual($result, $expected); $this->assertEqual($result, $expected);
} }

View file

@ -279,7 +279,7 @@ class ModelTest extends CakeTestCase {
$this->model =& new Article(); $this->model =& new Article();
$this->model->belongsTo = $this->model->hasAndBelongsToMany = $this->model->hasOne = array(); $this->model->belongsTo = $this->model->hasAndBelongsToMany = $this->model->hasOne = array();
$this->model->hasMany['Comment'] = am($this->model->hasMany['Comment'], array( $this->model->hasMany['Comment'] = array_merge($this->model->hasMany['Comment'], array(
'foreignKey' => false, 'foreignKey' => false,
'conditions' => array('Comment.user_id' => '= 2') 'conditions' => array('Comment.user_id' => '= 2')
)); ));

View file

@ -70,7 +70,7 @@ class TestValidate extends Model {
); );
function validateNumber($value, $options) { function validateNumber($value, $options) {
$options = am(array('min' => 0, 'max' => 100), $options); $options = array_merge(array('min' => 0, 'max' => 100), $options);
$valid = ($value['number'] >= $options['min'] && $value['number'] <= $options['max']); $valid = ($value['number'] >= $options['min'] && $value['number'] <= $options['max']);
return $valid; return $valid;
} }

View file

@ -26,8 +26,20 @@
* @lastmodified $Date$ * @lastmodified $Date$
* @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
*/ */
App::import('Core', 'Object'); App::import('Core', array('Object', 'Controller'));
if (!class_exists('RequestActionController')) {
class RequestActionController extends Controller {
var $uses = array();
function test_request_action() {
return 'This is a test';
}
function another_ra_test($id, $other) {
return $id + $other;
}
}
}
class TestObject extends Object { class TestObject extends Object {
var $methodCalls = array(); var $methodCalls = array();
@ -82,11 +94,11 @@ class ObjectTest extends UnitTestCase {
$this->object->oneParamMethod('Hello'); $this->object->oneParamMethod('Hello');
$expected[] = array('oneParamMethod' => array('Hello')); $expected[] = array('oneParamMethod' => array('Hello'));
$this->assertIdentical($this->object->methodCalls, $expected); $this->assertIdentical($this->object->methodCalls, $expected);
$this->object->twoParamMethod(true, false); $this->object->twoParamMethod(true, false);
$expected[] = array('twoParamMethod' => array(true, false)); $expected[] = array('twoParamMethod' => array(true, false));
$this->assertIdentical($this->object->methodCalls, $expected); $this->assertIdentical($this->object->methodCalls, $expected);
$this->object->threeParamMethod(true, false, null); $this->object->threeParamMethod(true, false, null);
$expected[] = array('threeParamMethod' => array(true, false, null)); $expected[] = array('threeParamMethod' => array(true, false, null));
$this->assertIdentical($this->object->methodCalls, $expected); $this->assertIdentical($this->object->methodCalls, $expected);
@ -123,9 +135,62 @@ class ObjectTest extends UnitTestCase {
$this->assertIdentical($this->object->methodCalls, $expected); $this->assertIdentical($this->object->methodCalls, $expected);
} }
function testRequestAction(){
$result = $this->object->requestAction('/request_action/test_request_action');
$expected = 'This is a test';
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'test_request_action'));
$expected = 'This is a test';
$this->assertEqual($result, $expected);
$result = $this->object->requestAction('/request_action/another_ra_test/2/5');
$expected = 7;
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(array('controller' => 'request_action', 'action' => 'another_ra_test'), array('pass' => array('5', '7')));
$expected = 12;
$this->assertEqual($result, $expected);
Configure::write('controllerPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'controllers' . DS));
Configure::write('viewPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'views' . DS));
Configure::write('pluginPaths', array(TEST_CAKE_CORE_INCLUDE_PATH . 'tests' . DS . 'test_app' . DS . 'plugins' . DS));
$result = $this->object->requestAction('/tests_apps/index', array('return'));
$expected = 'This is the TestsAppsController index view';
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(array('controller' => 'tests_apps', 'action' => 'index'), array('return'));
$expected = 'This is the TestsAppsController index view';
$this->assertEqual($result, $expected);
$result = $this->object->requestAction('/tests_apps/some_method');
$expected = 5;
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(array('controller' => 'tests_apps', 'action' => 'some_method'));
$expected = 5;
$this->assertEqual($result, $expected);
$result = $this->object->requestAction('/test_plugin/tests_plugins_tests/index', array('return'));
$expected = 'This is the TestsPluginsTestsController index view';
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(array('controller' => 'tests_plugins_tests', 'action' => 'index', 'plugin' => 'test_plugin'), array('return'));
$expected = 'This is the TestsPluginsTestsController index view';
$this->assertEqual($result, $expected);
$result = $this->object->requestAction('/test_plugin/tests_plugins_tests/some_method');
$expected = 25;
$this->assertEqual($result, $expected);
$result = $this->object->requestAction(array('controller' => 'tests_plugins_tests', 'action' => 'some_method', 'plugin' => 'test_plugin'));
$expected = 25;
$this->assertEqual($result, $expected);
}
function tearDown() { function tearDown() {
unset($this->object); unset($this->object);
} }
} }
?> ?>

View file

@ -173,13 +173,13 @@ class CakeTestCase extends UnitTestCase {
$dropFixture = $fixture->drop(); $dropFixture = $fixture->drop();
if (!empty($createFixture)) { if (!empty($createFixture)) {
$this->_queries['create'] = am($this->_queries['create'], array($createFixture)); $this->_queries['create'] = array_merge($this->_queries['create'], array($createFixture));
} }
if (!empty($insertsFixture)) { if (!empty($insertsFixture)) {
$this->_queries['insert'] = am($this->_queries['insert'], $insertsFixture); $this->_queries['insert'] = array_merge($this->_queries['insert'], $insertsFixture);
} }
if (!empty($dropFixture)) { if (!empty($dropFixture)) {
$this->_queries['drop'] = am($this->_queries['drop'], array($dropFixture)); $this->_queries['drop'] = array_merge($this->_queries['drop'], array($dropFixture));
} }
} }
@ -239,7 +239,7 @@ class CakeTestCase extends UnitTestCase {
'method' => 'post' 'method' => 'post'
); );
$params = am($default, $params); $params = array_merge($default, $params);
if (!empty($params['data'])) { if (!empty($params['data'])) {
$data = array('data' => $params['data']); $data = array('data' => $params['data']);
@ -278,7 +278,7 @@ class CakeTestCase extends UnitTestCase {
} }
if (!empty($view->pageTitle)) { if (!empty($view->pageTitle)) {
$result = am($result, array('title' => $view->pageTitle)); $result = array_merge($result, array('title' => $view->pageTitle));
} }
} }
} else { } else {
@ -391,7 +391,7 @@ class CakeTestCase extends UnitTestCase {
*/ */
function getTests() { function getTests() {
$methods = array_diff(parent::getTests(), array('testAction', 'testaction')); $methods = array_diff(parent::getTests(), array('testAction', 'testaction'));
$methods = am(am(array('start', 'startCase'), $methods), array('endCase', 'end')); $methods = array_merge(array_merge(array('start', 'startCase'), $methods), array('endCase', 'end'));
return $methods; return $methods;
} }
/** /**

View file

@ -57,10 +57,10 @@ class CakeTestFixture extends Object {
$import = array(); $import = array();
if (is_string($this->import) || is_array($this->import) && isset($this->import['model'])) { if (is_string($this->import) || is_array($this->import) && isset($this->import['model'])) {
$import = am(array('records' => false), ife(is_array($this->import), $this->import, array())); $import = array_merge(array('records' => false), ife(is_array($this->import), $this->import, array()));
$import['model'] = ife(is_array($this->import), $this->import['model'], $this->import); $import['model'] = ife(is_array($this->import), $this->import['model'], $this->import);
} elseif (isset($this->import['table'])) { } elseif (isset($this->import['table'])) {
$import = am(array('connection' => 'default', 'records' => false), $this->import); $import = array_merge(array('connection' => 'default', 'records' => false), $this->import);
} }
if (isset($import['model']) && (class_exists($import['model']) || App::import('Model', $import['model']))) { if (isset($import['model']) && (class_exists($import['model']) || App::import('Model', $import['model']))) {

View file

@ -0,0 +1,40 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright 2005-2008, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake.tests
* @subpackage cake.tests.test_app.plugins.test_plugin.views.helpers
* @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
*/
class TestsAppsController extends AppController {
var $name = 'TestsApps';
var $uses = array();
function index(){
}
function some_method() {
return 5;
}
}
?>

View file

@ -0,0 +1,40 @@
<?php
/* SVN FILE: $Id$ */
/**
* Short description for file.
*
* Long description for file
*
* PHP versions 4 and 5
*
* CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
* Copyright 2005-2008, Cake Software Foundation, Inc.
* 1785 E. Sahara Avenue, Suite 490-204
* Las Vegas, Nevada 89104
*
* Licensed under The Open Group Test Suite License
* Redistributions of files must retain the above copyright notice.
*
* @filesource
* @copyright Copyright 2005-2008, Cake Software Foundation, Inc.
* @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
* @package cake.tests
* @subpackage cake.tests.test_app.plugins.test_plugin.views.helpers
* @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
*/
class TestsPluginsTestsController extends AppController {
var $name = 'TestsPluginsTests';
var $uses = array();
function index(){
}
function some_method() {
return 25;
}
}
?>

View file

@ -0,0 +1 @@
This is the TestsPluginsTestsController index view

View file

@ -0,0 +1 @@
This is the TestsAppsController index view