Last active
February 16, 2017 09:29
-
-
Save cagataygurturk/b25c2605ff9fde8f2560ee2f3c573361 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 | |
public function onBootstrap(EventInterface $e){ | |
$em = $e->getApplication()->getEventManager(); | |
$em->attach(MvcEvent::EVENT_ROUTE, array( | |
$this, | |
'detachNotFoundStrategy' | |
) , 1); | |
} | |
public function detachNotFoundStrategy(MvcEvent $event) { | |
$controller = $event->getRouteMatch()->getParam('controller'); | |
if ($controller != 'Title') { | |
return false; | |
} | |
$app = $event->getApplication(); | |
$services = $app->getServiceManager(); | |
$events = $app->getEventManager(); | |
$sharedEvents = $events->getSharedManager(); | |
$listener = $services->get('Zend\Mvc\View\RouteNotFoundStrategy'); | |
$events->detach($listener); | |
/** @var CallbackHandler[] $handlers */ | |
$handlers = $sharedEvents->getListeners('Zend\Stdlib\DispatchableInterface', MvcEvent::EVENT_DISPATCH); | |
foreach($handlers as $handler) { | |
$callback = $handler->getCallback(); | |
if (is_array($callback) && $callback[0] === $listener){ | |
$sharedEvents->detach('Zend\Stdlib\DispatchableInterface', $handler); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment