-
Notifications
You must be signed in to change notification settings - Fork 45
refactor common features into RoutingBundle #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6c64022
3d4dcdd
0ae210f
7025761
b631cd4
9ae1897
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,9 +32,32 @@ class CmfSimpleCmsExtension extends Extension implements PrependExtensionInterfa | |
| */ | ||
| public function prepend(ContainerBuilder $container) | ||
| { | ||
| $prependConfig = array('persistence' => array('phpcr' => (array('enabled' => true)))); | ||
| $container->prependExtensionConfig('cmf_menu', $prependConfig); | ||
| $prependConfig = array('dynamic' => $prependConfig); | ||
| // process the configuration of CmfCoreExtension | ||
| $configs = $container->getExtensionConfig($this->getAlias()); | ||
| $parameterBag = $container->getParameterBag(); | ||
| $configs = $parameterBag->resolveValue($configs); | ||
| $config = $this->processConfiguration(new Configuration(), $configs); | ||
|
|
||
| if (empty($config['persistence']['phpcr']['enabled'])) { | ||
| return; | ||
| } | ||
|
|
||
| $prependConfig = array( | ||
| 'chain' => array( | ||
| 'routers_by_id' => array( | ||
| 'router.default' => 0, | ||
| 'cmf_routing.dynamic_router' => -100, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok to do like this? i don't know how you could remove a prepended config again, but you can overwrite the priorities. this way symfony router is first, which makes less impact. and we only do this if phpcr is enabled. do we need something here to skip prepending again or is it good enough?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why no creating a compiler pass to tag the CmfRouting's DynamicRouter as a
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what would be the advantage?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that is not a rhetorical question, btw :-)
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to use prepended config anymore to set the router, you just use the compiler pass to do that. |
||
| ) | ||
| ), | ||
| 'dynamic' => array( | ||
| 'enabled' => true, | ||
| ) | ||
| ); | ||
| if (isset($config['persistence']['phpcr']['basepath']) | ||
| && '/cms/simple' != $config['persistence']['phpcr']['basepath'] | ||
| ) { | ||
| $prependConfig['dynamic']['persistence']['phpcr']['route_basepaths'] = array($config['persistence']['phpcr']['basepath']); | ||
| } | ||
| $container->prependExtensionConfig('cmf_routing', $prependConfig); | ||
| } | ||
|
|
||
|
|
@@ -43,101 +66,20 @@ public function load(array $configs, ContainerBuilder $container) | |
| $config = $this->processConfiguration(new Configuration(), $configs); | ||
| $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | ||
|
|
||
| $this->loadRouting($config['routing'], $loader, $container); | ||
|
|
||
| if ($config['persistence']['phpcr']) { | ||
| $this->loadPhpcr($config['persistence']['phpcr'], $loader, $container); | ||
| $locales = isset($config['multilang']['locales']) ? $config['multilang']['locales'] : false; | ||
| $this->loadPhpcrRouting($config, $loader, $container, $locales); | ||
|
|
||
| if ($config['use_menu']) { | ||
| $this->loadPhpcrMenu($config, $loader, $container); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected function loadRouting($config, XmlFileLoader $loader, ContainerBuilder $container) | ||
| { | ||
| $container->setParameter($this->getAlias() . '.uri_filter_regexp', $config['uri_filter_regexp']); | ||
|
|
||
| $loader->load('routing.xml'); | ||
|
|
||
| $dynamic = $container->getDefinition($this->getAlias().'.dynamic_router'); | ||
|
|
||
| if (!empty($config['generic_controller'])) { | ||
| $definition = new DefinitionDecorator('cmf_routing.enhancer.explicit_template'); | ||
| $definition->replaceArgument(2, $config['generic_controller']); | ||
| $container->setDefinition( | ||
| $this->getAlias() . '.enhancer.explicit_template', | ||
| $definition | ||
| ); | ||
| $dynamic->addMethodCall('addRouteEnhancer', array( | ||
| new Reference($this->getAlias() . '.enhancer.explicit_template') | ||
| )); | ||
| } | ||
|
|
||
| if (!empty($config['controllers_by_type'])) { | ||
| $definition = new DefinitionDecorator('cmf_routing.enhancer.controllers_by_type'); | ||
| $definition->replaceArgument(2, $config['controllers_by_type']); | ||
| $container->setDefinition( | ||
| $this->getAlias() . '.enhancer.controllers_by_type', | ||
| $definition | ||
| ); | ||
| $dynamic->addMethodCall('addRouteEnhancer', array( | ||
| new Reference($this->getAlias() . '.enhancer.controllers_by_type') | ||
| )); | ||
| } | ||
|
|
||
| if (!empty($config['controllers_by_class'])) { | ||
| $definition = new DefinitionDecorator('cmf_routing.enhancer.controllers_by_class'); | ||
| $definition->replaceArgument(2, $config['controllers_by_class']); | ||
| $container->setDefinition( | ||
| $this->getAlias() . '.enhancer.controllers_by_class', | ||
| $definition | ||
| ); | ||
| $dynamic->addMethodCall('addRouteEnhancer', array( | ||
| new Reference($this->getAlias() . '.enhancer.controllers_by_class') | ||
| )); | ||
| } | ||
|
|
||
| if (!empty($config['generic_controller']) && !empty($config['templates_by_class'])) { | ||
| $controllerForTemplates = array(); | ||
| foreach ($config['templates_by_class'] as $key => $value) { | ||
| $controllerForTemplates[$key] = $config['generic_controller']; | ||
| } | ||
|
|
||
| $definition = new DefinitionDecorator('cmf_routing.enhancer.controller_for_templates_by_class'); | ||
| $definition->replaceArgument(2, $controllerForTemplates); | ||
|
|
||
| $container->setDefinition( | ||
| $this->getAlias() . '.enhancer.controller_for_templates_by_class', | ||
| $definition | ||
| ); | ||
|
|
||
| $definition = new DefinitionDecorator('cmf_routing.enhancer.templates_by_class'); | ||
| $definition->replaceArgument(2, $config['templates_by_class']); | ||
|
|
||
| $container->setDefinition( | ||
| $this->getAlias() . '.enhancer.templates_by_class', | ||
| $definition | ||
| ); | ||
|
|
||
| $dynamic->addMethodCall('addRouteEnhancer', array( | ||
| new Reference($this->getAlias() . '.enhancer.controller_for_templates_by_class') | ||
| )); | ||
| $dynamic->addMethodCall('addRouteEnhancer', array( | ||
| new Reference($this->getAlias() . '.enhancer.templates_by_class') | ||
| )); | ||
| } | ||
| } | ||
|
|
||
| protected function loadPhpcr($config, XmlFileLoader $loader, ContainerBuilder $container) | ||
| { | ||
| $loader->load('services-phpcr.xml'); | ||
| // migrator is only for PHPCR | ||
| $loader->load('migrator-phpcr.xml'); | ||
|
|
||
| // save some characters | ||
| $prefix = $this->getAlias() . '.persistence.phpcr'; | ||
|
|
||
| $container->setParameter($prefix . '.basepath', $config['basepath']); | ||
|
|
@@ -155,24 +97,6 @@ protected function loadPhpcr($config, XmlFileLoader $loader, ContainerBuilder $c | |
| $container->setParameter($prefix . '.document.class', $config['document_class']); | ||
| } | ||
|
|
||
| protected function loadPhpcrRouting($config, XmlFileLoader $loader, ContainerBuilder $container, $locales) | ||
| { | ||
| $loader->load('routing-phpcr.xml'); | ||
| $prefix = $this->getAlias() . '.persistence.phpcr'; | ||
|
|
||
| $routeProvider = $container->getDefinition($prefix.'.route_provider'); | ||
| $routeProvider->replaceArgument(0, new Reference($config['persistence']['phpcr']['manager_registry'])); | ||
| if (!empty($locales)) { | ||
| $routeProvider->addMethodCall('setLocales', array($locales)); | ||
| } | ||
| $container->setAlias($this->getAlias() . '.route_provider', $prefix.'.route_provider'); | ||
|
|
||
| $generator = $container->getDefinition($this->getAlias().'.generator'); | ||
| $generator->addMethodCall('setContentRepository', array( | ||
| new Reference($config['routing']['content_repository_id']) | ||
| )); | ||
| } | ||
|
|
||
| protected function loadPhpcrMenu($config, XmlFileLoader $loader, ContainerBuilder $container) | ||
| { | ||
| $bundles = $container->getParameter('kernel.bundles'); | ||
|
|
||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i remove this part as the corebundle already does it, and we depend on it