Skip to content

Commit

Permalink
Added optional onError callback to command. Changed CSS/JS plugins to…
Browse files Browse the repository at this point in the history
… register JS/CSS packages after command is run, so you can add packages during command run
  • Loading branch information
erkie committed Nov 22, 2012
1 parent 4f957ab commit 3b62675
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 24 deletions.
29 changes: 7 additions & 22 deletions command.php
Expand Up @@ -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);

Expand All @@ -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 <Cowl::url> redirect
Expand All @@ -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 )
{
Expand Down Expand Up @@ -278,24 +281,6 @@ public function setView()
$this->view = $path;
}

/*
Method:
<Command::getCachePath>
Returns:
A path that can be used for any <Cache> 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: <Command::getJS>
// Returns <Command::$js>
public function getJS() { return $this->js; }
Expand Down
2 changes: 1 addition & 1 deletion library/plugins/css/plugin.css.php
Expand Up @@ -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');

Expand Down
2 changes: 1 addition & 1 deletion library/plugins/js/plugin.js.php
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions plugins.php
Expand Up @@ -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) {}
Expand Down

0 comments on commit 3b62675

Please sign in to comment.