* @copyright 2012 Jurian Sluiman. * @license http://www.opensource.org/licenses/bsd-license.php BSD License * @link http://zf-commons.github.com */ namespace ZfcAdmin; use Zend\ModuleManager\Feature; use Zend\Loader; use Zend\EventManager\EventInterface; use Zend\Mvc\MvcEvent; use Zend\Mvc\Router\RouteMatch; /** * Module class for ZfcAdmin * * @package ZfcAdmin */ class Module implements Feature\AutoloaderProviderInterface, Feature\ConfigProviderInterface, Feature\ServiceProviderInterface, Feature\BootstrapListenerInterface { /** * @{inheritdoc} */ public function getAutoloaderConfig() { return array( Loader\AutoloaderFactory::STANDARD_AUTOLOADER => array( Loader\StandardAutoloader::LOAD_NS => array( __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__, ), ), ); } /** * @{inheritdoc} */ public function getConfig() { return include __DIR__ . '/config/module.config.php'; } /** * @{inheritdoc} */ public function getServiceConfig() { return array( 'factories' => array( 'admin_navigation' => 'ZfcAdmin\Navigation\Service\AdminNavigationFactory', 'gestC_navigation' => 'ZfcAdmin\Navigation\Service\GestNavigationFactory', ), ); } /** * @{inheritdoc} */ public function onBootstrap(EventInterface $e) { $app = $e->getParam('application'); $em = $app->getEventManager(); $em->attach(MvcEvent::EVENT_DISPATCH, array($this, 'selectLayoutBasedOnRoute')); } /** * Select the admin layout based on route name * * @param MvcEvent $e * @return void */ public function selectLayoutBasedOnRoute(MvcEvent $e) { $app = $e->getParam('application'); $sm = $app->getServiceManager(); $config = $sm->get('config'); if (false === $config['zfcadmin']['use_admin_layout']) { return; } $match = $e->getRouteMatch(); $controller = $e->getTarget(); if (!$match instanceof RouteMatch || 0 !== strpos($match->getMatchedRouteName(), 'zfcadmin') || $controller->getEvent()->getResult()->terminate() ) { return; } $layout = $config['zfcadmin']['admin_layout_template']; $controller->layout($layout); } }