From 3b62675faecb84a4dea4425f96d738feac1eb5fa Mon Sep 17 00:00:00 2001 From: Erik Andersson Date: Thu, 22 Nov 2012 11:05:16 +0100 Subject: [PATCH] Added optional onError callback to command. Changed CSS/JS plugins to register JS/CSS packages after command is run, so you can add packages during command run --- command.php | 29 +++++++---------------------- library/plugins/css/plugin.css.php | 2 +- library/plugins/js/plugin.js.php | 2 +- plugins.php | 1 + 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/command.php b/command.php index 047f77d..f786f7e 100755 --- a/command.php +++ b/command.php @@ -148,9 +148,6 @@ public final function run(RequestData $request) $request->response_type = 'html'; } - // Set cache path, if the user wants to activate cacheing - $this->template->setCachePath($this->getCachePath(), 600); - $this->template->add('request', $request); Current::$request->setInfo('request', $request); @@ -161,8 +158,8 @@ public final function run(RequestData $request) $this->error_occured = false; - // _This_ is where all the magic happens try { + // _This_ is where all the magic happens $ret = call_user_func_array(array($this, $method), $args); // If an array is returned it is used as pieces for a redirect @@ -185,6 +182,12 @@ public final function run(RequestData $request) header("HTTP/1.1", true, $code); } + + if ( $this->error_occured ) + if ( method_exists($this, 'onError') ) + $this->onError(); + Current::$plugins->hook('postCommandRun', $this, $method, $request); + // Render the template if not in CLI environment if ( ! COWL_CLI ) { @@ -278,24 +281,6 @@ public function setView() $this->view = $path; } - /* - Method: - - - Returns: - A path that can be used for any that is specific to the method run and arguments passed. - */ - - public function getCachePath() - { - $argv = $this->request->argv; - $pieces = $this->request->pieces; - array_shift($argv); - $pieces = array_merge($pieces, $argv); - - return 'command.' . implode('.', $pieces); - } - // Method: // Returns public function getJS() { return $this->js; } diff --git a/library/plugins/css/plugin.css.php b/library/plugins/css/plugin.css.php index 3da4845..1ee7e0a 100755 --- a/library/plugins/css/plugin.css.php +++ b/library/plugins/css/plugin.css.php @@ -63,7 +63,7 @@ public function __construct() Get the commands specified and CSS packages */ - public function commandRun(Command $command, $method, $args) + public function postCommandRun(Command $command, $method, $args) { $mode = Current::$config->get('mode'); diff --git a/library/plugins/js/plugin.js.php b/library/plugins/js/plugin.js.php index 63640b4..40a7f11 100755 --- a/library/plugins/js/plugin.js.php +++ b/library/plugins/js/plugin.js.php @@ -40,7 +40,7 @@ public function __construct() This method is called after a command is run to determine which JS files to be included. */ - public function commandRun(Command $command, $method, $request) + public function postCommandRun(Command $command, $method, $request) { $mode = Current::$config->get('mode'); $js_packages = $command->getJS(); diff --git a/plugins.php b/plugins.php index 2297d74..d90ba57 100755 --- a/plugins.php +++ b/plugins.php @@ -155,6 +155,7 @@ public function postStaticServe(StaticServer $server) {} // Command-related hooks public function commandRun(Command $command, $method, $args) {} + public function postCommandRun(Command $command, $method, $args) {} // ORM-related hooks public function dbPopulate(DataMapper $mapper, DomainObject $object) {}