-
-
Save robintema/6030604 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 | |
namespace MyFunnyValentine; | |
// Detect if the currently matched route belongs to this module. | |
// The assumption is that the controller name includes the module namespace. | |
class Module | |
{ | |
public function onBootstrap($e) | |
{ | |
$app = $e->getTarget(); | |
$events = $app->getEventManager(); | |
$events->attach('route', array($this, 'onRoute'), -100); | |
} | |
public function onRoute($e) | |
{ | |
$matches = $e->getRouteMatch(); | |
if (!$matches instanceof \Zend\Mvc\Router\RouteMatch) { | |
// No matches == not a match! | |
return; | |
} | |
$controller = $matches->getParam('controller'); | |
if (__NAMESPACE__ != substr($controller, 0, strlen(__NAMESPACE__))) { | |
// Namespace does not match! | |
return; | |
} | |
// Namespace matches! Do something interesting! | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment