Created
October 23, 2012 11:01
-
-
Save pawellenart/3938175 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class HookSentry_HookHandler { | |
public function __construct() {} | |
/** | |
* Kontroler: index | |
* Akcja: index | |
* Trigger: default | |
* | |
* @param Zend_Controller_Response_Abstract $response | |
*/ | |
public function triggerIndexIndexDefault($response) { | |
if (!is_null($response) && $response instanceof Zend_Controller_Response_Abstract) { | |
$response->appendBody("<p>" . __FUNCTION__ . " called.</p>"); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class HookSentry_HookManager { | |
private $controller; | |
private $action; | |
private $trigger; | |
private $args = null; | |
public function __construct($controller, $action, $trigger = 'default') { | |
$this->controller = $controller; | |
$this->action = $action; | |
$this->trigger = $trigger; | |
} | |
public function setArgs($args) { | |
$this->args = $args; | |
} | |
public function call() { | |
// TODO: sprawdzenie, czy dany trigger istnieje | |
// TODO: "{$controller}.{$action}.{$trigger}" | |
$handler = new HookSentry_HookHandler(); | |
$handler_method = "trigger" | |
. ucfirst($this->controller) | |
. ucfirst($this->action) | |
. ucfirst($this->trigger); | |
if (is_callable(array($handler, $handler_method))) { | |
call_user_func_array(array($handler, $handler_method), array($this->args)); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class HookSentry_HookSentryPlugin extends Zend_Controller_Plugin_Abstract { | |
public function postDispatch(\Zend_Controller_Request_Abstract $request) { | |
parent::postDispatch($request); | |
$controller = $this->getRequest()->getControllerName(); | |
$action = $this->getRequest()->getActionName(); | |
$manager = new HookSentry_HookManager($controller, $action); | |
$manager->setArgs($this->getResponse()); | |
$manager->call(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment