Skip to content

Instantly share code, notes, and snippets.

@samsonasik
Forked from weierophinney/Module.php
Created July 18, 2013 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save samsonasik/6032475 to your computer and use it in GitHub Desktop.
Save samsonasik/6032475 to your computer and use it in GitHub Desktop.
<?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