Created
August 26, 2011 05:58
-
-
Save Thinkscape/1172807 to your computer and use it in GitHub Desktop.
ZF2 Front Controller Debugger plugin
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 | |
namespace Zend\Controller\Plugin; | |
use Zend\Controller; | |
use Zend\Controller\Request; | |
use Zend\Controller\Plugin\AbstractPlugin; | |
class Debug extends AbstractPlugin | |
{ | |
protected $_logger; | |
public function __construct(\Zend\Log\Logger $logger){ | |
$this->_logger = $logger; | |
} | |
public function preDispatch(\Zend\Controller\Request\AbstractRequest $request){ | |
$router = \Zend\Controller\Front::getInstance()->getRouter(); | |
if($this->_logger){ | |
$this->_logger->debug( | |
'Front: Dispatching request | '. | |
'Module: '.$request->getModuleName().' | '. | |
'Controller: '.$request->getControllerName().' | '. | |
'Action: '.$request->getActionName().' | '. | |
'Current route: '.$router->getCurrentRouteName().' | '. | |
'URI: '.$request->getRequestUri() | |
); | |
} | |
} | |
public function postDispatch(\Zend\Controller\Request\AbstractRequest $request){ | |
$router = \Zend\Controller\Front::getInstance()->getRouter(); | |
if($this->_logger){ | |
$this->_logger->debug( | |
'Front: Finished dispatching | '. | |
'Module: '.$request->getModuleName().' | '. | |
'Controller: '.$request->getControllerName().' | '. | |
'Action: '.$request->getActionName().' | '. | |
'Current route: '.$router->getCurrentRouteName().' | '. | |
'URI: '.$request->getRequestUri() | |
); | |
} | |
} | |
public function dispatchLoopShutdown(){ | |
if($this->_logger){ | |
$this->_logger->debug( | |
'Front: Finished processing request.' | |
); | |
} | |
} | |
public function getName(){ | |
return 'Debug'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment