fixes #4836 components initialize for error pages, also changing Object::stop() to Object::_stop()

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7116 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2008-06-04 19:04:58 +00:00
parent 298ede514c
commit b3f605c1d8
27 changed files with 146 additions and 90 deletions

View file

@ -71,7 +71,7 @@ class ErrorHandler extends Object {
function error($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr($code . $name . $message."\n");
$this->stop();
$this->_stop();
}
/**
* Convenience method to display a 404 page.
@ -84,7 +84,7 @@ class ErrorHandler extends Object {
$this->error(array('code' => '404',
'name' => 'Not found',
'message' => sprintf(__("The requested address %s was not found on this server.", true), $url, $message)));
$this->stop();
$this->_stop();
}
/**
* Renders the Missing Controller web page.
@ -96,7 +96,7 @@ class ErrorHandler extends Object {
extract($params, EXTR_OVERWRITE);
$controllerName = str_replace('Controller', '', $className);
$this->stderr(sprintf(__("Missing Controller '%s'", true), $controllerName));
$this->stop();
$this->_stop();
}
/**
* Renders the Missing Action web page.
@ -107,7 +107,7 @@ class ErrorHandler extends Object {
function missingAction($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing Method '%s' in '%s'", true), $action, $className));
$this->stop();
$this->_stop();
}
/**
* Renders the Private Action web page.
@ -118,7 +118,7 @@ class ErrorHandler extends Object {
function privateAction($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Trying to access private method '%s' in '%s'", true), $action, $className));
$this->stop();
$this->_stop();
}
/**
* Renders the Missing Table web page.
@ -129,7 +129,7 @@ class ErrorHandler extends Object {
function missingTable($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing database table '%s' for model '%s'", true), $table, $className));
$this->stop();
$this->_stop();
}
/**
* Renders the Missing Database web page.
@ -140,7 +140,7 @@ class ErrorHandler extends Object {
function missingDatabase($params = array()) {
extract($params, EXTR_OVERWRITE);
$this->stderr(__("Missing Database", true));
$this->stop();
$this->_stop();
}
/**
* Renders the Missing View web page.
@ -151,7 +151,7 @@ class ErrorHandler extends Object {
function missingView($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing View '%s' for '%s' in '%s'", true), $file, $action, $className));
$this->stop();
$this->_stop();
}
/**
* Renders the Missing Layout web page.
@ -162,7 +162,7 @@ class ErrorHandler extends Object {
function missingLayout($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing Layout '%s'", true), $file));
$this->stop();
$this->_stop();
}
/**
* Renders the Database Connection web page.
@ -173,7 +173,7 @@ class ErrorHandler extends Object {
function missingConnection($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(__("Missing Database Connection. Try 'cake bake'", true));
$this->stop();
$this->_stop();
}
/**
* Renders the Missing Helper file web page.
@ -184,7 +184,7 @@ class ErrorHandler extends Object {
function missingHelperFile($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing Helper file '%s' for '%s'", true), $file, Inflector::camelize($helper)));
$this->stop();
$this->_stop();
}
/**
* Renders the Missing Helper class web page.
@ -195,7 +195,7 @@ class ErrorHandler extends Object {
function missingHelperClass($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing Helper class '%s' in '%s'", true), Inflector::camelize($helper), $file));
$this->stop();
$this->_stop();
}
/**
* Renders the Missing Component file web page.
@ -206,7 +206,7 @@ class ErrorHandler extends Object {
function missingComponentFile($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing Component file '%s' for '%s'", true), $file, Inflector::camelize($component)));
$this->stop();
$this->_stop();
}
/**
* Renders the Missing Component class web page.
@ -217,7 +217,7 @@ class ErrorHandler extends Object {
function missingComponentClass($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing Component class '%s' in '%s'", true), Inflector::camelize($component), $file));
$this->stop();
$this->_stop();
}
/**
* Renders the Missing Model class web page.
@ -228,7 +228,7 @@ class ErrorHandler extends Object {
function missingModel($params) {
extract($params, EXTR_OVERWRITE);
$this->stderr(sprintf(__("Missing model '%s'", true), $className));
$this->stop();
$this->_stop();
}
/**
* Outputs to the stdout filehandle.

View file

@ -85,7 +85,7 @@ class AclShell extends Shell {
$out .= sprintf(__("Current ACL Classname: %s", true), Configure::read('Acl.classname')) . "\n";
$out .= "--------------------------------------------------\n";
$this->err($out);
$this->stop();
$this->_stop();
}
if ($this->command && !in_array($this->command, array('help'))) {

View file

@ -94,7 +94,7 @@ class ApiShell extends Shell {
} else {
$this->err(sprintf(__("%s not found", true), $class));
$this->stop();
$this->_stop();
}
$parsed = $this->__parseClass($path . $file .'.php');
@ -103,7 +103,7 @@ class ApiShell extends Shell {
if (isset($this->params['m'])) {
if (!isset($parsed[$this->params['m']])) {
$this->err(sprintf(__("%s::%s() could not be found", true), $class, $this->params['m']));
$this->stop();
$this->_stop();
}
$method = $parsed[$this->params['m']];
$this->out($class .'::'.$method['method'] . $method['parameters']);
@ -122,7 +122,7 @@ class ApiShell extends Shell {
while ($number = $this->in(__('Select a number to see the more information about a specific method. q to quit. l to list.', true), null, 'q')) {
if ($number === 'q') {
$this->out(__('Done', true));
$this->stop();
$this->_stop();
}
if ($number === 'l') {
@ -193,7 +193,7 @@ class ApiShell extends Shell {
$File = new File($path);
if (!$File->exists()) {
$this->err(sprintf(__("%s could not be found", true), $File->name));
$this->stop();
$this->_stop();
}
$contents = $File->read();

View file

@ -55,7 +55,7 @@ class BakeShell extends Shell {
$this->{$task}->path = $this->params['working'] . DS . $path . DS;
if (!is_dir($this->{$task}->path)) {
$this->err(sprintf(__("%s directory could not be found.\nBe sure you have created %s", true), $task, $this->{$task}->path));
$this->stop();
$this->_stop();
}
}
}
@ -175,7 +175,7 @@ class BakeShell extends Shell {
if (empty($this->args)) {
$this->all();
}
$this->stop();
$this->_stop();
}
/**

View file

@ -95,10 +95,10 @@ class SchemaShell extends Shell {
$File = new File($this->Schema->path . DS .'schema.php');
if ($File->exists()) {
$this->out($File->read());
$this->stop();
$this->_stop();
} else {
$this->err(__('Schema could not be found', true));
$this->stop();
$this->_stop();
}
}
/**
@ -123,7 +123,7 @@ class SchemaShell extends Shell {
$snapshot = true;
$result = $this->in("Schema file exists.\n [O]verwrite\n [S]napshot\n [Q]uit\nWould you like to do?", array('o', 's', 'q'), 's');
if ($result === 'q') {
$this->stop();
$this->_stop();
}
if ($result === 'o') {
$snapshot = false;
@ -149,10 +149,10 @@ class SchemaShell extends Shell {
if ($this->Schema->write($content)) {
$this->out(sprintf(__('Schema file: %s generated', true), $content['file']));
$this->stop();
$this->_stop();
} else {
$this->err(__('Schema file: %s generated', true));
$this->stop();
$this->_stop();
}
}
/**
@ -167,7 +167,7 @@ class SchemaShell extends Shell {
$Schema = $this->Schema->load();
if (!$Schema) {
$this->err(__('Schema could not be loaded', true));
$this->stop();
$this->_stop();
}
if (!empty($this->args[0])) {
if ($this->args[0] == 'true') {
@ -186,10 +186,10 @@ class SchemaShell extends Shell {
$File = new File($this->Schema->path . DS . $write, true);
if ($File->write($contents)) {
$this->out(sprintf(__('SQL dump file created in %s', true), $File->pwd()));
$this->stop();
$this->_stop();
} else {
$this->err(__('SQL dump could not be created', true));
$this->stop();
$this->_stop();
}
}
$this->out($contents);
@ -203,7 +203,7 @@ class SchemaShell extends Shell {
function run() {
if (!isset($this->args[0])) {
$this->err('command not found');
$this->stop();
$this->_stop();
}
$command = $this->args[0];
@ -229,7 +229,7 @@ class SchemaShell extends Shell {
if (!$Schema) {
$this->err(sprintf(__('%s could not be loaded', true), $this->Schema->file));
$this->stop();
$this->_stop();
}
$table = null;
@ -246,7 +246,7 @@ class SchemaShell extends Shell {
break;
default:
$this->err(__('command not found', true));
$this->stop();
$this->_stop();
}
}
/**
@ -271,7 +271,7 @@ class SchemaShell extends Shell {
}
if (empty($drop) || empty($create)) {
$this->out(__('Schema is up to date.', true));
$this->stop();
$this->_stop();
}
$this->out("\n" . __('The following tables will be dropped.', true));
@ -317,7 +317,7 @@ class SchemaShell extends Shell {
if (empty($contents)) {
$this->out(__('Schema is up to date.', true));
$this->stop();
$this->_stop();
}
$this->out("\n" . __('The following statements will run.', true));
@ -396,7 +396,7 @@ class SchemaShell extends Shell {
$this->out("\n\tschema run create <schema> <table>\n\t\tdrop tables and create database based on schema file\n\t\toptional <schema> arg for selecting schema name\n\t\toptional <table> arg for creating only one table\n\t\tpass the -s param with a number to use a snapshot\n\t\tTo see the changes, perform a dry run with the -dry param");
$this->out("\n\tschema run update <schema> <table>\n\t\talter tables based on schema file\n\t\toptional <schema> arg for selecting schema name.\n\t\toptional <table> arg for altering only one table.\n\t\tTo use a snapshot, pass the -s param with the snapshot number\n\t\tTo see the changes, perform a dry run with the -dry param");
$this->out("");
$this->stop();
$this->_stop();
}
}
?>

View file

@ -292,7 +292,7 @@ class Shell extends Object {
if (!isset($this->{$taskName})) {
$this->err("Task '".$taskName."' could not be loaded");
$this->stop();
$this->_stop();
}
}
}
@ -392,7 +392,7 @@ class Shell extends Object {
$out .= "$msg\n";
$out .= "\n";
$this->err($out);
$this->stop();
$this->_stop();
}
/**
* Will check the number args matches otherwise throw an error
@ -508,7 +508,7 @@ class Shell extends Object {
if ($this->Project->cakeAdmin($admin) !== true) {
$this->out('Unable to write to /app/config/core.php.');
$this->out('You need to enable Configure::write(\'Routing.admin\',\'admin\') in /app/config/core.php to use admin routing.');
$this->stop();
$this->_stop();
} else {
$cakeAdmin = $admin . '_';
}

View file

@ -287,7 +287,7 @@ class ControllerTask extends Shell {
$actions .= "\t\t\t\t\$this->redirect(array('action'=>'index'));\n";
} else {
$actions .= "\t\t\t\t\$this->flash(__('{$currentModelName} saved.', true), array('action'=>'index'));\n";
$actions .= "\t\t\t\t\$this->stop();\n";
$actions .= "\t\t\t\t\$this->_stop();\n";
}
$actions .= "\t\t\t} else {\n";
if ($wannaUseSession) {
@ -327,7 +327,7 @@ class ControllerTask extends Shell {
$actions .= "\t\t\t\$this->redirect(array('action'=>'index'));\n";
} else {
$actions .= "\t\t\t\$this->flash(__('Invalid {$singularHumanName}', true), array('action'=>'index'));\n";
$actions .= "\t\t\t\$this->stop();\n";
$actions .= "\t\t\t\$this->_stop();\n";
}
$actions .= "\t\t}\n";
$actions .= "\t\tif (!empty(\$this->data)) {\n";
@ -337,7 +337,7 @@ class ControllerTask extends Shell {
$actions .= "\t\t\t\t\$this->redirect(array('action'=>'index'));\n";
} else {
$actions .= "\t\t\t\t\$this->flash(__('The ".$singularHumanName." has been saved.', true), array('action'=>'index'));\n";
$actions .= "\t\t\t\t\$this->stop();\n";
$actions .= "\t\t\t\t\$this->_stop();\n";
}
$actions .= "\t\t\t} else {\n";
if ($wannaUseSession) {
@ -511,7 +511,7 @@ class ControllerTask extends Shell {
if (empty($tables)) {
$this->err(__('Your database does not have any tables.', true));
$this->stop();
$this->_stop();
}
$this->__tables = $tables;
@ -541,7 +541,7 @@ class ControllerTask extends Shell {
if ($enteredController === 'q') {
$this->out(__("Exit", true));
$this->stop();
$this->_stop();
}
if ($enteredController == '' || intval($enteredController) > count($controllers)) {
@ -574,7 +574,7 @@ class ControllerTask extends Shell {
$this->out("\n\tcontroller <name> scaffold admin\n\t\tbakes a controller with scaffold actions for both public and Configure::read('Routing.admin')");
$this->out("\n\tcontroller <name> admin\n\t\tbakes a controller with scaffold actions only for Configure::read('Routing.admin')");
$this->out("");
$this->stop();
$this->_stop();
}
}
?>

View file

@ -71,7 +71,7 @@ class DbConfigTask extends Shell {
function execute() {
if (empty($this->args)) {
$this->__interactive();
$this->stop();
$this->_stop();
}
}
/**

View file

@ -140,7 +140,7 @@ class ExtractTask extends Shell{
$response = $this->in("What is the full path you would like to extract?\nExample: " . $this->params['root'] . DS . "myapp\n[Q]uit", null, 'Q');
if (strtoupper($response) === 'Q') {
$this->out('Extract Aborted');
$this->stop();
$this->_stop();
}
}
@ -165,7 +165,7 @@ class ExtractTask extends Shell{
$response = $this->in("What is the full path you would like to output?\nExample: " . $this->path . DS . "locale\n[Q]uit", null, $this->path . DS . "locale");
if (strtoupper($response) === 'Q') {
$this->out('Extract Aborted');
$this->stop();
$this->_stop();
}
}
@ -526,7 +526,7 @@ class ExtractTask extends Shell{
$response = $this->in("\n\nError: ".$file . ' already exists in this location. Overwrite?', array('y','n', 'q'), 'n');
if (strtoupper($response) === 'Q') {
$this->out('Extract Aborted');
$this->stop();
$this->_stop();
} elseif (strtoupper($response) === 'N') {
$response = '';
while ($response == '') {

View file

@ -754,7 +754,7 @@ class ModelTask extends Shell {
}
if (empty($tables)) {
$this->err(__('Your database does not have any tables.', true));
$this->stop();
$this->_stop();
}
$this->__tables = $tables;
@ -785,7 +785,7 @@ class ModelTask extends Shell {
if ($enteredModel === 'q') {
$this->out(__("Exit", true));
$this->stop();
$this->_stop();
}
if ($enteredModel == '' || intval($enteredModel) > count($this->_modelNames)) {
@ -815,7 +815,7 @@ class ModelTask extends Shell {
$this->out("\n\tmodel\n\t\tbakes model in interactive mode.");
$this->out("\n\tmodel <name>\n\t\tbakes model file with no associations or validation");
$this->out("");
$this->stop();
$this->_stop();
}
/**
* Builds the tests fixtures for the model and create the file

View file

@ -81,7 +81,7 @@ class PluginTask extends Shell {
$this->hr();
} elseif (isset($this->args[0])) {
$this->err(sprintf('%s in path %s not found.', $plugin, $this->path . $pluginPath));
$this->stop();
$this->_stop();
} else {
$this->__interactive($plugin);
}
@ -198,7 +198,7 @@ class PluginTask extends Shell {
$this->out("\n\tplugin <name> controller\n\t\tbakes controller. Run 'cake bake controller help' for more info.");
$this->out("\n\tplugin <name> view\n\t\tbakes view. Run 'cake bake view help' for more info.");
$this->out("");
$this->stop();
$this->_stop();
}
}
?>

View file

@ -274,7 +274,7 @@ class ProjectTask extends Shell {
$this->out('Commands:');
$this->out("\n\tproject <name>\n\t\tbakes app directory structure.\n\t\tif <name> begins with '/' path is absolute.");
$this->out("");
$this->stop();
$this->_stop();
}
}

View file

@ -128,7 +128,7 @@ class TestTask extends Shell {
}
}
} else {
$this->stop();
$this->_stop();
}
}
}

View file

@ -216,7 +216,7 @@ class ViewTask extends Shell {
$looksGood = $this->in('Look okay?', array('y','n'), 'y');
if (low($looksGood) == 'y' || low($looksGood) == 'yes') {
$this->bake($action);
$this->stop();
$this->_stop();
} else {
$this->out('Bake Aborted.');
}
@ -245,7 +245,7 @@ class ViewTask extends Shell {
if (!App::import('Controller', $import)) {
$file = $this->controllerPath . '_controller.php';
$this->err(sprintf(__("The file '%s' could not be found.\nIn order to bake a view, you'll need to first create the controller.", true), $file));
$this->stop();
$this->_stop();
}
$controllerClassName = $this->controllerName . 'Controller';
$controllerObj = & new $controllerClassName();
@ -362,7 +362,7 @@ class ViewTask extends Shell {
$this->out("\n\tview <controller> <action>\n\t\twill bake a template. core templates: (index, add, edit, view)");
$this->out("\n\tview <controller> <template> <alias>\n\t\twill use the template specified but name the file based on the alias");
$this->out("");
$this->stop();
$this->_stop();
}
/**
* Returns associations for controllers models.

View file

@ -128,7 +128,7 @@ class Dispatcher extends Object {
$this->here = $this->base . '/' . $url;
if ($this->cached($url)) {
$this->stop();
$this->_stop();
}
if ($parse) {
@ -647,10 +647,10 @@ class Dispatcher extends Object {
function cached($url) {
if (strpos($url, 'ccss/') === 0) {
include WWW_ROOT . DS . Configure::read('Asset.filter.css');
$this->stop();
$this->_stop();
} elseif (strpos($url, 'cjs/') === 0) {
include WWW_ROOT . DS . Configure::read('Asset.filter.js');
$this->stop();
$this->_stop();
}
$assets = array('js' => 'text/javascript', 'css' => 'text/css');

View file

@ -324,7 +324,7 @@ class AuthComponent extends Object {
} elseif (!empty($this->ajaxLogin)) {
$controller->viewPath = 'elements';
echo $controller->render($this->ajaxLogin, 'ajax');
$this->stop();
$this->_stop();
return false;
}
}

View file

@ -222,7 +222,7 @@ class RequestHandlerComponent extends Object {
unset($_POST[$key]);
}
echo $this->requestAction($url, array('return'));
$this->stop();
$this->_stop();
}
/**
* Returns true if the current HTTP request is Ajax, false otherwise

View file

@ -562,7 +562,7 @@ class Controller extends Object {
}
if ($exit) {
$this->stop();
$this->_stop();
}
}
/**

View file

@ -57,6 +57,7 @@ class ErrorHandler extends Object {
$this->controller->_set(Router::getPaths());
$this->controller->params = Router::getParams();
$this->controller->constructClasses();
$this->controller->Component->initialize($this->controller);
$this->controller->_set(array('cacheAction' => false, 'viewPath' => 'errors'));
$allow = array('.', '/', '_', ' ', '-', '~');
@ -80,16 +81,16 @@ class ErrorHandler extends Object {
if ($method == 'error') {
$this->dispatchMethod($method, $messages);
$this->stop();
$this->_stop();
} elseif (Configure::read() == 0 && (isset($code) && $code == 500)) {
$this->dispatchMethod('error500', $messages);
exit();
} elseif (Configure::read() == 0) {
$this->dispatchMethod('error404', $messages);
$this->stop();
$this->_stop();
} else {
$this->dispatchMethod($method, $messages);
$this->stop();
$this->_stop();
}
}
/**

View file

@ -134,7 +134,7 @@ class Object {
* @return void
* @access public
*/
function stop($status = 0) {
function _stop($status = 0) {
exit($status);
}
/**

View file

@ -864,7 +864,7 @@ class AjaxHelper extends AppHelper {
e($this->Javascript->codeBlock($scripts, false));
}
$this->stop();
$this->_stop();
}
}
}

View file

@ -256,6 +256,7 @@ class CacheHelper extends AppHelper {
if ($useCallbacks == true) {
$file .= '$controller->constructClasses();
$controller->Component->initialize($controller);
$controller->beforeFilter();
$controller->Component->startup($controller);';
}

View file

@ -50,7 +50,7 @@ class TestAuthComponent extends AuthComponent {
* @access public
* @return void
*/
function stop() {
function _stop() {
$this->testStop = true;
}
}

View file

@ -35,32 +35,84 @@ if (!defined('CAKEPHP_UNIT_TEST_EXECUTION')) {
define('CAKEPHP_UNIT_TEST_EXECUTION', 1);
}
/**
* TestErrorAppController class
* OrangeComponent class
*
* @package cake
* @subpackage cake.tests.cases.libs
*/
class TestErrorAppController extends Controller {
class OrangeComponent extends Object {
/**
* beforeFilter method
* testName property
*
* @access public
* @return void
*/
function beforeFilter() {
$this->cakeError('error404', array('oops' => 'Nothing to see here'));
*/
var $testName = null;
/**
* initialize method
*
* @access public
* @return void
*/
function initialize(&$controller) {
$this->testName = 'OrangeComponent';
}
}
/**
* cakeError method
* AppController class
*
* @param mixed $method
* @param array $messages
* @access public
* @return void
* @package cake
* @subpackage cake.tests.cases.libs
*/
function cakeError($method, $messages = array()) {
$error =& new TestErrorHandler($method, $messages);
return $error;
if (!class_exists('AppController')) {
class AppController extends Controller {
/**
* components property
*
* @access public
* @return void
*/
var $components = array('Orange');
/**
* beforeFilter method
*
* @access public
* @return void
*/
function beforeFilter() {
$this->cakeError('error404', array('oops' => 'Nothing to see here'));
}
/**
* beforeRender method
*
* @access public
* @return void
*/
function beforeRender() {
echo $this->Orange->testName;
}
/**
* cakeError method
*
* @param mixed $method
* @param array $messages
* @access public
* @return void
*/
function cakeError($method, $messages = array()) {
$error =& new TestErrorHandler($method, $messages);
return $error;
}
/**
* header method
*
* @access public
* @return void
*/
function header($header) {
echo $header;
}
}
}
/**
@ -69,7 +121,7 @@ class TestErrorAppController extends Controller {
* @package cake
* @subpackage cake.tests.cases.libs
*/
class TestErrorController extends TestErrorAppController {
class TestErrorController extends AppController {
/**
* uses property
*
@ -101,7 +153,7 @@ class TestErrorHandler extends ErrorHandler {
* @access public
* @return void
*/
function stop() {
function _stop() {
return;
}
}
@ -189,6 +241,8 @@ class TestErrorHandlerTest extends CakeTestCase {
$result = ob_get_clean();
$this->assertPattern('/<h2>Missing Controller<\/h2>/', $result);
$this->assertPattern('/<em>PostsController<\/em>/', $result);
$this->assertPattern('/OrangeComponent/', $result);
}
/**
* testMissingAction method

View file

@ -102,7 +102,7 @@ class TestAjaxHelper extends AjaxHelper {
* @access public
* @return void
*/
function stop() {
function _stop() {
}
}
/**

View file

@ -71,7 +71,7 @@ class ThemeViewTestErrorHandler extends ErrorHandler {
* @access public
* @return void
*/
function stop() {
function _stop() {
return;
}
}

View file

@ -78,7 +78,7 @@ class ViewTestErrorHandler extends ErrorHandler {
* @access public
* @return void
*/
function stop() {
function _stop() {
return;
}
}