/** * {@inheritdoc} */ public function parse($name) { if ($name instanceof TemplateReferenceInterface) { return $name; } elseif (isset($this->cache[$name])) { return $this->cache[$name]; } // normalize name $name = str_replace(':/', ':', preg_replace('#/{2,}#', '/', strtr($name, '\\', '/'))); if (false !== strpos($name, '..')) { throw new \RuntimeException(sprintf('Template name "%s" contains invalid characters.', $name)); } $parts = explode(':', $name); if (3 !== count($parts)) { throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid (format is "bundle:section:template.format.engine").', $name)); } $elements = explode('.', $parts[2]); if (3 > count($elements)) { throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid (format is "bundle:section:template.format.engine").', $name)); } $engine = array_pop($elements); $format = array_pop($elements); $template = new TemplateReference($parts[0], $parts[1], implode('.', $elements), $format, $engine); if ($template->get('module')) { try { $this->moduleManager->getModule($template->get('module')); } catch (\Exception $e) { throw new \InvalidArgumentException(sprintf('Template name "%s" is not valid.', $name), 0, $e); } } return $this->cache[$name] = $template; }
/** * Creates and returns the module manager. * * Instantiates the default module listeners, providing them configuration * from the "module_listener_options" key of the ApplicationConfig * service. Also sets the default config glob path. * * Module manager is instantiated and provided with an EventManager, to which * the default listener aggregate is attached. The ModuleEvent is also created * and attached to the module manager. * * @param ServiceLocatorInterface $serviceLocator * * @return ModuleManager */ public function createService(ServiceLocatorInterface $serviceLocator) { if (!$serviceLocator->has('ServiceListener')) { $serviceLocator->setFactory('ServiceListener', 'PPI\\Framework\\ServiceManager\\Factory\\ServiceListenerFactory'); } $config = $serviceLocator->get('ApplicationConfig'); $defaultListeners = $serviceLocator->get('ModuleDefaultListener'); $serviceListener = $serviceLocator->get('ServiceListener'); $serviceListener->addServiceManager($serviceLocator, 'service_manager', 'Zend\\ModuleManager\\Feature\\ServiceProviderInterface', 'getServiceConfig'); $serviceListener->addServiceManager('RoutePluginManager', 'route_manager', 'Zend\\ModuleManager\\Feature\\RouteProviderInterface', 'getRouteConfig'); $modules = isset($config['modules']['active_modules']) ? $config['modules']['active_modules'] : array(); $events = $serviceLocator->get('EventManager'); $events->attach($defaultListeners); $events->attach($serviceListener); $moduleEvent = new ModuleEvent(); $moduleEvent->setParam('ServiceManager', $serviceLocator); $moduleManager = new ModuleManager($modules, $events); $moduleManager->setEvent($moduleEvent); return $moduleManager; }