Skip to content

Instantly share code, notes, and snippets.

@Thinkscape
Created August 26, 2011 05:58
Show Gist options
  • Save Thinkscape/1172807 to your computer and use it in GitHub Desktop.
Save Thinkscape/1172807 to your computer and use it in GitHub Desktop.
ZF2 Front Controller Debugger plugin
<?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