From b2f92bb19c48262c493126c442aa22aa95934ce3 Mon Sep 17 00:00:00 2001 From: dantleech Date: Sat, 9 Nov 2013 20:26:01 +0100 Subject: [PATCH 01/13] Example configuration --- .../Resources/app/config/routingautoroute.yml | 83 +++++++------------ 1 file changed, 30 insertions(+), 53 deletions(-) diff --git a/Tests/Resources/app/config/routingautoroute.yml b/Tests/Resources/app/config/routingautoroute.yml index 45eb682..55bc061 100644 --- a/Tests/Resources/app/config/routingautoroute.yml +++ b/Tests/Resources/app/config/routingautoroute.yml @@ -15,75 +15,52 @@ cmf_routing: route_basepath: /test/routing cmf_routing_auto: - auto_route_mapping: - - ## # e.g. /cms/auto-route/blog/my-blogs-title Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Blog: - # generate or use path components leading up to the final part of the path content_path: base: - provider: - name: specified - path: test/auto-route - exists_action: - strategy: use - not_exists_action: - strategy: create + provider: [ specified, { path: test/auto-route } ] + exists_action: [ use ] + not_exists_action: [ create ] namespace: - provider: - name: specified - path: blog - exists_action: - strategy: use - not_exists_action: - strategy: create - + provider: [ specified, { path: blog } ] + exists_action: [ use ] + not_exists_action: [ create ] + # using alternative syntax content_name: provider: - name: content_method - method: getTitle + - content_method + - + method: getTitle exists_action: - strategy: auto_increment - pattern: -%d - not_exists_action: - strategy: create - - ## + - auto_increment + - + pattern: -%d + not_exists_action: + - create # e.g. /cms/auto-route/blog/my-blogs-title/2013-04-09/my-post-title Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Post: - content_path: - # /cms/auto-route/blog/my-blogs-title blog_path: - provider: - name: content_object - method: getBlog - exists_action: - strategy: use - not_exists_action: - strategy: throw_exception - + provider: [ content_object, { method: getBlog } ] + exists_action: [ use ] + not_exists_action: [ throw_exception ] date: provider: - name: content_datetime - method: getDate - date_format: Y/m/d - exists_action: - strategy: use - not_exists_action: - strategy: create - + - content_datetime + - + method: getDate + date_format: Y/m/d + exists_action: [ use ] + not_exists_action: [ create ] content_name: # my-post-title - provider: - name: content_method - method: getTitle - exists_action: - strategy: auto_increment - pattern: -%d - not_exists_action: - strategy: create + provider: [ content_method, { method: getTitle } ] + exists_action: [ auto_increment, { pattern: -%d } ] + not_exists_action: [ create ] + on_content_change: + - [ remove_orphans ] + - [ leave_redirect, { option_1: foo } ] From 3f9ce778b7596e47c77c884b757dda9b1a9188d6 Mon Sep 17 00:00:00 2001 From: Wouter J Date: Mon, 18 Nov 2013 14:16:37 +0100 Subject: [PATCH 02/13] Added Config test --- Tests/Resources/Fixtures/config/config.xml | 27 ++++ Tests/Resources/Fixtures/config/config.yml | 12 ++ .../DependencyInjection/ConfigurationTest.php | 138 +++++------------- composer.json | 2 +- 4 files changed, 73 insertions(+), 106 deletions(-) create mode 100644 Tests/Resources/Fixtures/config/config.xml create mode 100644 Tests/Resources/Fixtures/config/config.yml diff --git a/Tests/Resources/Fixtures/config/config.xml b/Tests/Resources/Fixtures/config/config.xml new file mode 100644 index 0000000..5370b5b --- /dev/null +++ b/Tests/Resources/Fixtures/config/config.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/Resources/Fixtures/config/config.yml b/Tests/Resources/Fixtures/config/config.yml new file mode 100644 index 0000000..ee6bc99 --- /dev/null +++ b/Tests/Resources/Fixtures/config/config.yml @@ -0,0 +1,12 @@ +cmf_routing_auto: + auto_route_mapping: + Acme\BasicCmsBundle\Document\Page: + content_path: + pages: + provider: [ specified, { path: /cms/routes/page} ] + exists_action: [ use ] + not_exists_action: [ create ] + content_name: + provider: [ content_method, { method: getTitle } ] + exists_action: [ auto_increment, { pattern: -%d } ] + not_exists_action: [ create ] diff --git a/Tests/Unit/DependencyInjection/ConfigurationTest.php b/Tests/Unit/DependencyInjection/ConfigurationTest.php index 9848c11..b06274f 100644 --- a/Tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/Tests/Unit/DependencyInjection/ConfigurationTest.php @@ -2,145 +2,73 @@ namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Unit\DependencyInjection; -use Matthias\SymfonyConfigTest\PhpUnit\AbstractConfigurationTestCase; use Symfony\Cmf\Bundle\RoutingAutoBundle\DependencyInjection\Configuration; +use Symfony\Cmf\Bundle\RoutingAutoBundle\DependencyInjection\CmfRoutingAutoExtension; +use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionConfigurationTestCase; -class ConfigurationTest extends AbstractConfigurationTestCase +class ConfigurationTest extends AbstractExtensionConfigurationTestCase { - protected $inputConfig; + protected function getContainerExtension() + { + return new CmfRoutingAutoExtension(); + } + + protected function getConfiguration() + { + return new Configuration(); + } - public function setUp() + public function testSupportsAllConfigFormats() { - $this->inputConfig = array( + $expectedConfiguration = array( 'auto_route_mapping' => array( - 'Acme\BasicCmsBundle\Document\Page' => array( + 'Acme\BasisCmsBundle\Document\Page' => array( 'content_path' => array( 'pages' => array( 'provider' => array( 'name' => 'specified', - 'path' => '/cms/routes/page', + 'options' => array( + 'path' => '/cms/routes/page', + ), ), 'exists_action' => array( 'strategy' => 'use', + 'options' => array(), ), 'not_exists_action' => array( 'strategy' => 'create', + 'options' => array(), ), ), ), 'content_name' => array( 'provider' => array( 'name' => 'content_method', - 'method' => 'getTitle', + 'options' => array( + 'method' => 'getTitle', + ), ), 'exists_action' => array( 'strategy' => 'auto_increment', - 'pattern' => '-%d', + 'options' => array( + 'pattern' => '-%d', + ), ), 'not_exists_action' => array( 'strategy' => 'create', + 'options' => array(), ), ), ), ), ); - } - - protected function getConfiguration() - { - return new Configuration(); - } - public function testYamlConfig() - { - $this->assertProcessedConfigurationEquals( - array( - $this->inputConfig, - ), - $this->inputConfig - ); - } + $sources = array_map(function ($path) { + return __DIR__.'/../../Resources/Fixtures/'.$path; + }, array( + 'config/config.yml', + )); - public function testXmlConfig() - { - $this->assertProcessedConfigurationEquals( - array( - array( - 'auto-route-mapping' => array( - array( - 'class' => 'Acme\BasicCmsBundle\Document\Page', - 'content-path' => array( - array( - 'name' => 'pages', - 'provider' => array( - 'option' => array( - array( - 'name' => 'name', - 'value' => 'specified', - ), - array( - 'name' => 'path', - 'value' => '/cms/routes/page', - ), - ), - ), - 'exists-action' => array( - 'option' => array( - array( - 'name' => 'strategy', - 'value' => 'use', - ) - ), - ), - 'not-exists-action' => array( - 'option' => array( - array( - 'name' => 'strategy', - 'value' => 'create', - ), - ), - ), - ), - ), - 'content-name' => array( - 'provider' => array( - 'option' => array( - array( - 'name' => 'name', - 'value' => 'content_method', - ), - array( - 'name' => 'method', - 'value' => 'getTitle', - ), - ), - ), - 'exists-action' => array( - 'option' => array( - array( - 'name' => 'strategy', - 'value' => 'auto_increment', - ), - array( - 'name' => 'pattern', - 'value' => '-%d', - ), - ), - ), - 'not-exists-action' => array( - 'option' => array( - array( - 'name' => 'strategy', - 'value' => 'create', - ), - ), - ), - ), - ), - ), - ), - ), - $this->inputConfig - ); + $this->assertProcessedConfigurationEquals($expectedConfiguration, $sources); } } diff --git a/composer.json b/composer.json index 864f5bb..a6cd513 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ }, "require-dev": { "symfony-cmf/testing": "1.0.*", - "matthiasnoback/symfony-config-test": "0.*" + "matthiasnoback/symfony-dependency-injection-test": "0.*", }, "suggest": { "doctrine/phpcr-bundle": "To enable support for the PHPCR ODM documents" From 0c582f6d36b41f366cbace005f033762a8287248 Mon Sep 17 00:00:00 2001 From: Wouter J Date: Mon, 18 Nov 2013 14:44:29 +0100 Subject: [PATCH 03/13] Refactored Configuration builder --- DependencyInjection/Configuration.php | 91 ++++++++----------- Tests/Resources/Fixtures/config/config.yml | 24 +++-- .../DependencyInjection/ConfigurationTest.php | 2 +- 3 files changed, 57 insertions(+), 60 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 145bfac..6728a80 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -33,66 +33,51 @@ public function getConfigTreeBuilder() $treeBuilder = new TreeBuilder(); $treeBuilder->root('cmf_routing_auto') ->children() - ->arrayNode('auto_route_mapping') - ->useAttributeAsKey('class') - ->prototype('array') - ->children() - ->arrayNode('content_path') - ->useAttributeAsKey('name') - ->prototype('array') - ->children() - ->arrayNode('provider') - ->beforeNormalization() - ->ifTrue($needsNormalization) - ->then($doNormalization) - ->end() - ->prototype('scalar')->end() - ->end() - ->arrayNode('exists_action') - ->beforeNormalization() - ->ifTrue($needsNormalization) - ->then($doNormalization) + ->arrayNode('auto_route_mapping') + ->useAttributeAsKey('class') + ->prototype('array') + ->children() + ->arrayNode('content_path') + ->useAttributeAsKey('name') + ->prototype('array') + ->children() + ->append($this->getBuilderUnitConfigOption('provider', 'name')) + ->append($this->getBuilderUnitConfigOption('exists_action')) + ->append($this->getBuilderUnitConfigOption('not_exists_action')) + ->end() ->end() - ->prototype('scalar')->end() - ->end() - ->arrayNode('not_exists_action') - ->beforeNormalization() - ->ifTrue($needsNormalization) - ->then($doNormalization) + ->end() // content_path + ->arrayNode('content_name') + ->children() + ->append($this->getBuilderUnitConfigOption('provider', 'name')) + ->append($this->getBuilderUnitConfigOption('exists_action')) + ->append($this->getBuilderUnitConfigOption('not_exists_action')) ->end() - ->prototype('scalar')->end() - ->end() - ->end() + ->end() // content_name ->end() ->end() - ->arrayNode('content_name') - ->children() - ->arrayNode('provider') - ->beforeNormalization() - ->ifTrue($needsNormalization) - ->then($doNormalization) - ->end() - ->prototype('scalar')->end() - ->end() - ->arrayNode('exists_action') - ->beforeNormalization() - ->ifTrue($needsNormalization) - ->then($doNormalization) - ->end() - ->prototype('scalar')->end() - ->end() - ->arrayNode('not_exists_action') - ->beforeNormalization() - ->ifTrue($needsNormalization) - ->then($doNormalization) - ->end() - ->prototype('scalar')->end() - ->end() - ->end() - ->end() + ->end() // auto_route_mapping ->end(); return $treeBuilder; } + + protected function getBuilderUnitConfigOption($name, $nameOption = 'strategy') + { + $builder = new TreeBuilder(); + $node = $builder->root($name); + + $node + ->fixXmlConfig('option') + ->children() + ->scalarNode($nameOption)->isRequired()->cannotBeEmpty()->end() + ->arrayNode('options') + ->useAttributeAsKey('name') + ->prototype('scalar')->end() + ->end() + ->end(); + + return $node; + } } diff --git a/Tests/Resources/Fixtures/config/config.yml b/Tests/Resources/Fixtures/config/config.yml index ee6bc99..1151af4 100644 --- a/Tests/Resources/Fixtures/config/config.yml +++ b/Tests/Resources/Fixtures/config/config.yml @@ -3,10 +3,22 @@ cmf_routing_auto: Acme\BasicCmsBundle\Document\Page: content_path: pages: - provider: [ specified, { path: /cms/routes/page} ] - exists_action: [ use ] - not_exists_action: [ create ] + provider: + name: specified + options: + path: /cms/routes/page + exists_action: + strategy: use + not_exists_action: + strategy: create content_name: - provider: [ content_method, { method: getTitle } ] - exists_action: [ auto_increment, { pattern: -%d } ] - not_exists_action: [ create ] + provider: + name: content_method + options: + method: getTitle + exists_action: + strategy: auto_increment + options: + pattern: -%d + not_exists_action: + strategy: create diff --git a/Tests/Unit/DependencyInjection/ConfigurationTest.php b/Tests/Unit/DependencyInjection/ConfigurationTest.php index b06274f..eccb8a0 100644 --- a/Tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/Tests/Unit/DependencyInjection/ConfigurationTest.php @@ -22,7 +22,7 @@ public function testSupportsAllConfigFormats() { $expectedConfiguration = array( 'auto_route_mapping' => array( - 'Acme\BasisCmsBundle\Document\Page' => array( + 'Acme\BasicCmsBundle\Document\Page' => array( 'content_path' => array( 'pages' => array( 'provider' => array( From 0107391186fc0a176b4183f0e60a92f283062256 Mon Sep 17 00:00:00 2001 From: Wouter J Date: Mon, 18 Nov 2013 14:51:34 +0100 Subject: [PATCH 04/13] Implemented new config --- DependencyInjection/Configuration.php | 22 ++++++++++++++++++++++ Tests/Resources/Fixtures/config/config.yml | 20 ++++++-------------- 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 6728a80..0ef4f78 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -69,6 +69,28 @@ protected function getBuilderUnitConfigOption($name, $nameOption = 'strategy') $node ->fixXmlConfig('option') + ->beforeNormalization() + ->ifTrue(function ($v) { + return is_string($v); + }) + ->then(function ($v) use ($nameOption) { + return array( + $nameOption => $v, + 'options' => array(), + ); + }) + ->end() + ->beforeNormalization() + ->ifTrue(function ($v) use ($nameOption) { + return !isset($v[$nameOption]); + }) + ->then(function ($v) use ($nameOption) { + return array( + $nameOption => $v[0], + 'options' => isset($v[1]) ? $v[1] : array(), + ); + }) + ->end() ->children() ->scalarNode($nameOption)->isRequired()->cannotBeEmpty()->end() ->arrayNode('options') diff --git a/Tests/Resources/Fixtures/config/config.yml b/Tests/Resources/Fixtures/config/config.yml index 1151af4..7678355 100644 --- a/Tests/Resources/Fixtures/config/config.yml +++ b/Tests/Resources/Fixtures/config/config.yml @@ -3,22 +3,14 @@ cmf_routing_auto: Acme\BasicCmsBundle\Document\Page: content_path: pages: - provider: - name: specified - options: - path: /cms/routes/page - exists_action: - strategy: use - not_exists_action: + provider: [ specified, { path: /cms/routes/page } ] + exists_action: use + not_exists_action: strategy: create content_name: - provider: - name: content_method - options: - method: getTitle + provider: [ content_method, { method: getTitle } ] exists_action: strategy: auto_increment - options: + options: pattern: -%d - not_exists_action: - strategy: create + not_exists_action: [ create ] From 0ca343e264986febd5d4862b0696edb45872de76 Mon Sep 17 00:00:00 2001 From: Wouter J Date: Mon, 18 Nov 2013 14:56:21 +0100 Subject: [PATCH 05/13] Removed options new in #37 --- Tests/Resources/app/config/routingautoroute.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/Tests/Resources/app/config/routingautoroute.yml b/Tests/Resources/app/config/routingautoroute.yml index 55bc061..b2de1a5 100644 --- a/Tests/Resources/app/config/routingautoroute.yml +++ b/Tests/Resources/app/config/routingautoroute.yml @@ -61,6 +61,3 @@ cmf_routing_auto: provider: [ content_method, { method: getTitle } ] exists_action: [ auto_increment, { pattern: -%d } ] not_exists_action: [ create ] - on_content_change: - - [ remove_orphans ] - - [ leave_redirect, { option_1: foo } ] From 93cbf9faffe793c004f71841a442a1d59fad1af7 Mon Sep 17 00:00:00 2001 From: Wouter J Date: Mon, 18 Nov 2013 15:44:06 +0100 Subject: [PATCH 06/13] Added XML support --- .../CmfRoutingAutoExtension.php | 5 +++ DependencyInjection/Configuration.php | 24 ++++++++------ Tests/Resources/Fixtures/config/config.xml | 8 +++-- Tests/Resources/Fixtures/config/config.yml | 13 ++++---- .../DependencyInjection/ConfigurationTest.php | 31 ++++++++++--------- 5 files changed, 49 insertions(+), 32 deletions(-) diff --git a/DependencyInjection/CmfRoutingAutoExtension.php b/DependencyInjection/CmfRoutingAutoExtension.php index f57c16c..04a126f 100644 --- a/DependencyInjection/CmfRoutingAutoExtension.php +++ b/DependencyInjection/CmfRoutingAutoExtension.php @@ -34,5 +34,10 @@ public function load(array $configs, ContainerBuilder $container) $chainFactoryDef->addMethodCall('registerMapping', array($classFqn, $config)); } } + + public function getNamespace() + { + return 'http://cmf.symfony.com/schema/dic/routing_auto'; + } } diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 0ef4f78..5eeea9d 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -32,19 +32,25 @@ public function getConfigTreeBuilder() $treeBuilder = new TreeBuilder(); $treeBuilder->root('cmf_routing_auto') + ->fixXmlConfig('mapping') ->children() - ->arrayNode('auto_route_mapping') + ->arrayNode('mappings') ->useAttributeAsKey('class') ->prototype('array') ->children() ->arrayNode('content_path') - ->useAttributeAsKey('name') - ->prototype('array') - ->children() - ->append($this->getBuilderUnitConfigOption('provider', 'name')) - ->append($this->getBuilderUnitConfigOption('exists_action')) - ->append($this->getBuilderUnitConfigOption('not_exists_action')) - ->end() + ->fixXmlConfig('path_unit') + ->children() + ->arrayNode('path_units') + ->useAttributeAsKey('name') + ->prototype('array') + ->children() + ->append($this->getBuilderUnitConfigOption('provider', 'name')) + ->append($this->getBuilderUnitConfigOption('exists_action')) + ->append($this->getBuilderUnitConfigOption('not_exists_action')) + ->end() + ->end() + ->end() // path_units ->end() ->end() // content_path ->arrayNode('content_name') @@ -56,7 +62,7 @@ public function getConfigTreeBuilder() ->end() // content_name ->end() ->end() - ->end() // auto_route_mapping + ->end() // mappings ->end(); return $treeBuilder; diff --git a/Tests/Resources/Fixtures/config/config.xml b/Tests/Resources/Fixtures/config/config.xml index 5370b5b..cb963c7 100644 --- a/Tests/Resources/Fixtures/config/config.xml +++ b/Tests/Resources/Fixtures/config/config.xml @@ -3,14 +3,16 @@ - + - + + + @@ -22,6 +24,6 @@ - + diff --git a/Tests/Resources/Fixtures/config/config.yml b/Tests/Resources/Fixtures/config/config.yml index 7678355..b9dc05c 100644 --- a/Tests/Resources/Fixtures/config/config.yml +++ b/Tests/Resources/Fixtures/config/config.yml @@ -1,12 +1,13 @@ cmf_routing_auto: - auto_route_mapping: + mappings: Acme\BasicCmsBundle\Document\Page: content_path: - pages: - provider: [ specified, { path: /cms/routes/page } ] - exists_action: use - not_exists_action: - strategy: create + path_units: + pages: + provider: [ specified, { path: /cms/routes/page } ] + exists_action: use + not_exists_action: + strategy: create content_name: provider: [ content_method, { method: getTitle } ] exists_action: diff --git a/Tests/Unit/DependencyInjection/ConfigurationTest.php b/Tests/Unit/DependencyInjection/ConfigurationTest.php index eccb8a0..108c3af 100644 --- a/Tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/Tests/Unit/DependencyInjection/ConfigurationTest.php @@ -21,23 +21,25 @@ protected function getConfiguration() public function testSupportsAllConfigFormats() { $expectedConfiguration = array( - 'auto_route_mapping' => array( + 'mappings' => array( 'Acme\BasicCmsBundle\Document\Page' => array( 'content_path' => array( - 'pages' => array( - 'provider' => array( - 'name' => 'specified', - 'options' => array( - 'path' => '/cms/routes/page', + 'path_units' => array( + 'pages' => array( + 'provider' => array( + 'name' => 'specified', + 'options' => array( + 'path' => '/cms/routes/page', + ), + ), + 'exists_action' => array( + 'strategy' => 'use', + 'options' => array(), + ), + 'not_exists_action' => array( + 'strategy' => 'create', + 'options' => array(), ), - ), - 'exists_action' => array( - 'strategy' => 'use', - 'options' => array(), - ), - 'not_exists_action' => array( - 'strategy' => 'create', - 'options' => array(), ), ), ), @@ -67,6 +69,7 @@ public function testSupportsAllConfigFormats() return __DIR__.'/../../Resources/Fixtures/'.$path; }, array( 'config/config.yml', + 'config/config.xml', )); $this->assertProcessedConfigurationEquals($expectedConfiguration, $sources); From 51ff3f63a7fde90177df5f814f8810268e6a2f32 Mon Sep 17 00:00:00 2001 From: Wouter J Date: Mon, 18 Nov 2013 15:51:07 +0100 Subject: [PATCH 07/13] Fixed tests --- AutoRoute/Factory.php | 4 +- .../CmfRoutingAutoExtension.php | 2 +- .../Resources/app/config/routingautoroute.yml | 56 ++++++++++--------- Tests/Unit/AutoRoute/FactoryTest.php | 34 +++++++---- 4 files changed, 54 insertions(+), 42 deletions(-) diff --git a/AutoRoute/Factory.php b/AutoRoute/Factory.php index 9500448..7576ccd 100644 --- a/AutoRoute/Factory.php +++ b/AutoRoute/Factory.php @@ -132,7 +132,7 @@ protected function generateRouteStackChain($classFqn) $routeStackChain = new BuilderUnitChain($this->builder); - foreach ($mapping['content_path'] as $builderName => $builderConfig) { + foreach ($mapping['content_path']['path_units'] as $builderName => $builderConfig) { $builderUnit = $this->generateBuilderUnit($builderConfig); $routeStackChain->addBuilderUnit($builderName, $builderUnit); } @@ -230,7 +230,7 @@ private function getBuilderService($builderConfig, $type, $aliasKey) // to be stateless (which is good here) $service = $this->container->get($serviceId); unset($builderConfig[$type][$aliasKey]); - $service->init($builderConfig[$type]); + $service->init($builderConfig[$type]['options']); return $service; } diff --git a/DependencyInjection/CmfRoutingAutoExtension.php b/DependencyInjection/CmfRoutingAutoExtension.php index 04a126f..c2a5626 100644 --- a/DependencyInjection/CmfRoutingAutoExtension.php +++ b/DependencyInjection/CmfRoutingAutoExtension.php @@ -30,7 +30,7 @@ public function load(array $configs, ContainerBuilder $container) $chainFactoryDef = $container->getDefinition('cmf_routing_auto.factory'); // normalize configuration - foreach ($config['auto_route_mapping'] as $classFqn => $config) { + foreach ($config['mappings'] as $classFqn => $config) { $chainFactoryDef->addMethodCall('registerMapping', array($classFqn, $config)); } } diff --git a/Tests/Resources/app/config/routingautoroute.yml b/Tests/Resources/app/config/routingautoroute.yml index b2de1a5..bb391ec 100644 --- a/Tests/Resources/app/config/routingautoroute.yml +++ b/Tests/Resources/app/config/routingautoroute.yml @@ -15,47 +15,49 @@ cmf_routing: route_basepath: /test/routing cmf_routing_auto: - auto_route_mapping: + mappings: # e.g. /cms/auto-route/blog/my-blogs-title Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Blog: # generate or use path components leading up to the final part of the path content_path: - base: - provider: [ specified, { path: test/auto-route } ] - exists_action: [ use ] - not_exists_action: [ create ] - namespace: - provider: [ specified, { path: blog } ] - exists_action: [ use ] - not_exists_action: [ create ] + path_units: + base: + provider: [ specified, { path: test/auto-route } ] + exists_action: use + not_exists_action: create + namespace: + provider: [ specified, { path: blog } ] + exists_action: use + not_exists_action: create # using alternative syntax content_name: provider: - - content_method - - + name: content_method + options: method: getTitle exists_action: - - auto_increment - - + strategy: auto_increment + options: pattern: -%d not_exists_action: - - create + strategy: create # e.g. /cms/auto-route/blog/my-blogs-title/2013-04-09/my-post-title Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Resources\Document\Post: content_path: - # /cms/auto-route/blog/my-blogs-title - blog_path: - provider: [ content_object, { method: getBlog } ] - exists_action: [ use ] - not_exists_action: [ throw_exception ] - date: - provider: - - content_datetime - - - method: getDate - date_format: Y/m/d - exists_action: [ use ] - not_exists_action: [ create ] + path_units: + # /cms/auto-route/blog/my-blogs-title + blog_path: + provider: [ content_object, { method: getBlog } ] + exists_action: use + not_exists_action: throw_exception + date: + provider: + name: content_datetime + options: + method: getDate + date_format: Y/m/d + exists_action: use + not_exists_action: create content_name: # my-post-title provider: [ content_method, { method: getTitle } ] diff --git a/Tests/Unit/AutoRoute/FactoryTest.php b/Tests/Unit/AutoRoute/FactoryTest.php index 4f4bbe8..d16e06b 100644 --- a/Tests/Unit/AutoRoute/FactoryTest.php +++ b/Tests/Unit/AutoRoute/FactoryTest.php @@ -61,29 +61,39 @@ public function provideTestGetChain() array( array( 'content_path' => array( - 'base' => array( - 'provider' => array( - 'name' => 'fixed', - 'message' => 'foobar' - ), - 'exists_action' => array( - 'strategy' => 'create' - ), - 'not_exists_action' => array( - 'strategy' => 'throw_excep', + 'path_units' => array( + 'base' => array( + 'provider' => array( + 'name' => 'fixed', + 'options' => array( + 'message' => 'foobar', + ), + ), + 'exists_action' => array( + 'strategy' => 'create', + 'options' => array(), + ), + 'not_exists_action' => array( + 'strategy' => 'throw_excep', + 'options' => array(), + ), ), ), ), 'content_name' => array( 'provider' => array( 'name' => 'fixed', - 'message' => 'barfoo' + 'options' => array( + 'message' => 'barfoo', + ), ), 'exists_action' => array( - 'strategy' => 'create' + 'strategy' => 'create', + 'options' => array(), ), 'not_exists_action' => array( 'strategy' => 'throw_excep', + 'options' => array(), ), ), ), From 1c444da38f47f1a7af4f4b4d1a51576f0dbd5012 Mon Sep 17 00:00:00 2001 From: Wouter J Date: Mon, 18 Nov 2013 15:55:33 +0100 Subject: [PATCH 08/13] Added PHP config test --- Tests/Resources/Fixtures/config/config.php | 29 +++++++++++++++++++ .../DependencyInjection/ConfigurationTest.php | 1 + 2 files changed, 30 insertions(+) create mode 100644 Tests/Resources/Fixtures/config/config.php diff --git a/Tests/Resources/Fixtures/config/config.php b/Tests/Resources/Fixtures/config/config.php new file mode 100644 index 0000000..2df3aee --- /dev/null +++ b/Tests/Resources/Fixtures/config/config.php @@ -0,0 +1,29 @@ +loadFromExtension('cmf_routing_auto', array( + 'mappings' => array( + 'Acme\BasicCmsBundle\Document\Page' => array( + 'content_path' => array( + 'path_units' => array( + 'pages' => array( + 'provider' => array('specified', array('path' => '/cms/routes/page')), + 'exists_action' => 'use', + 'not_exists_action' => array( + 'strategy' => 'create', + ), + ), + ), + ), + 'content_name' => array( + 'provider' => array('content_method', array('method' => 'getTitle')), + 'exists_action' => array( + 'strategy' => 'auto_increment', + 'options' => array( + 'pattern' => '-%d', + ), + ), + 'not_exists_action' => array('create'), + ), + ), + ), +)); diff --git a/Tests/Unit/DependencyInjection/ConfigurationTest.php b/Tests/Unit/DependencyInjection/ConfigurationTest.php index 108c3af..6e2cecb 100644 --- a/Tests/Unit/DependencyInjection/ConfigurationTest.php +++ b/Tests/Unit/DependencyInjection/ConfigurationTest.php @@ -70,6 +70,7 @@ public function testSupportsAllConfigFormats() }, array( 'config/config.yml', 'config/config.xml', + 'config/config.php', )); $this->assertProcessedConfigurationEquals($expectedConfiguration, $sources); From 4f87d685870d56e65ffb4588f2131d760a5f8857 Mon Sep 17 00:00:00 2001 From: dantleech Date: Mon, 18 Nov 2013 22:16:36 +0100 Subject: [PATCH 09/13] Fixed composer and changed internal method name. --- DependencyInjection/Configuration.php | 14 +++++++------- composer.json | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 5eeea9d..b250a6e 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -45,9 +45,9 @@ public function getConfigTreeBuilder() ->useAttributeAsKey('name') ->prototype('array') ->children() - ->append($this->getBuilderUnitConfigOption('provider', 'name')) - ->append($this->getBuilderUnitConfigOption('exists_action')) - ->append($this->getBuilderUnitConfigOption('not_exists_action')) + ->append($this->getUnitConfigOption('provider', 'name')) + ->append($this->getUnitConfigOption('exists_action')) + ->append($this->getUnitConfigOption('not_exists_action')) ->end() ->end() ->end() // path_units @@ -55,9 +55,9 @@ public function getConfigTreeBuilder() ->end() // content_path ->arrayNode('content_name') ->children() - ->append($this->getBuilderUnitConfigOption('provider', 'name')) - ->append($this->getBuilderUnitConfigOption('exists_action')) - ->append($this->getBuilderUnitConfigOption('not_exists_action')) + ->append($this->getUnitConfigOption('provider', 'name')) + ->append($this->getUnitConfigOption('exists_action')) + ->append($this->getUnitConfigOption('not_exists_action')) ->end() ->end() // content_name ->end() @@ -68,7 +68,7 @@ public function getConfigTreeBuilder() return $treeBuilder; } - protected function getBuilderUnitConfigOption($name, $nameOption = 'strategy') + protected function getUnitConfigOption($name, $nameOption = 'strategy') { $builder = new TreeBuilder(); $node = $builder->root($name); diff --git a/composer.json b/composer.json index a6cd513..3af7726 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ }, "require-dev": { "symfony-cmf/testing": "1.0.*", - "matthiasnoback/symfony-dependency-injection-test": "0.*", + "matthiasnoback/symfony-dependency-injection-test": "0.*" }, "suggest": { "doctrine/phpcr-bundle": "To enable support for the PHPCR ODM documents" From b5913dfb9e6873c04b73985b7c3908dd56a1799f Mon Sep 17 00:00:00 2001 From: Wouter J Date: Mon, 18 Nov 2013 22:37:06 +0100 Subject: [PATCH 10/13] fixed dependencies --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 3af7726..d121e6f 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ }, "require-dev": { "symfony-cmf/testing": "1.0.*", - "matthiasnoback/symfony-dependency-injection-test": "0.*" + "matthiasnoback/symfony-dependency-injection-test": "0.*", + "matthiasnoback/symfony-config-test": "0.*" }, "suggest": { "doctrine/phpcr-bundle": "To enable support for the PHPCR ODM documents" From df8395ad89900727e0908d0c7342f5d7368736e1 Mon Sep 17 00:00:00 2001 From: Wouter J Date: Wed, 20 Nov 2013 16:09:03 +0100 Subject: [PATCH 11/13] Removed rendundant code --- DependencyInjection/Configuration.php | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index b250a6e..9c8959a 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -14,22 +14,6 @@ class Configuration implements ConfigurationInterface */ public function getConfigTreeBuilder() { - $needsNormalization = function ($v) { - if (!is_array($v)) { - return false; - } - - return isset($v['option']); - }; - $doNormalization = function ($v) { - $value = array(); - foreach ($v['option'] as $option) { - $value[$option['name']] = $option['value']; - } - - return $value; - }; - $treeBuilder = new TreeBuilder(); $treeBuilder->root('cmf_routing_auto') ->fixXmlConfig('mapping') From b5a7272c148a7f574dfe874076184499e715b776 Mon Sep 17 00:00:00 2001 From: Wouter J Date: Wed, 20 Nov 2013 16:13:30 +0100 Subject: [PATCH 12/13] Made path_units optional (Better Yaml, PHP support) --- DependencyInjection/Configuration.php | 10 ++++++++ Tests/Resources/Fixtures/config/config.php | 12 ++++------ Tests/Resources/Fixtures/config/config.yml | 11 ++++----- Tests/Unit/AutoRoute/FactoryTest.php | 28 ++++++++++------------ 4 files changed, 33 insertions(+), 28 deletions(-) diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 9c8959a..1646d01 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -23,6 +23,16 @@ public function getConfigTreeBuilder() ->prototype('array') ->children() ->arrayNode('content_path') + ->beforeNormalization() + ->ifTrue(function ($v) { + return !isset($v['path_unit']) && !isset($v['path_units']); + }) + ->then(function ($v) { + return array( + 'path_units' => $v, + ); + }) + ->end() ->fixXmlConfig('path_unit') ->children() ->arrayNode('path_units') diff --git a/Tests/Resources/Fixtures/config/config.php b/Tests/Resources/Fixtures/config/config.php index 2df3aee..4288ab6 100644 --- a/Tests/Resources/Fixtures/config/config.php +++ b/Tests/Resources/Fixtures/config/config.php @@ -4,13 +4,11 @@ 'mappings' => array( 'Acme\BasicCmsBundle\Document\Page' => array( 'content_path' => array( - 'path_units' => array( - 'pages' => array( - 'provider' => array('specified', array('path' => '/cms/routes/page')), - 'exists_action' => 'use', - 'not_exists_action' => array( - 'strategy' => 'create', - ), + 'pages' => array( + 'provider' => array('specified', array('path' => '/cms/routes/page')), + 'exists_action' => 'use', + 'not_exists_action' => array( + 'strategy' => 'create', ), ), ), diff --git a/Tests/Resources/Fixtures/config/config.yml b/Tests/Resources/Fixtures/config/config.yml index b9dc05c..d3ebad2 100644 --- a/Tests/Resources/Fixtures/config/config.yml +++ b/Tests/Resources/Fixtures/config/config.yml @@ -2,12 +2,11 @@ cmf_routing_auto: mappings: Acme\BasicCmsBundle\Document\Page: content_path: - path_units: - pages: - provider: [ specified, { path: /cms/routes/page } ] - exists_action: use - not_exists_action: - strategy: create + pages: + provider: [ specified, { path: /cms/routes/page } ] + exists_action: use + not_exists_action: + strategy: create content_name: provider: [ content_method, { method: getTitle } ] exists_action: diff --git a/Tests/Unit/AutoRoute/FactoryTest.php b/Tests/Unit/AutoRoute/FactoryTest.php index d16e06b..ec43520 100644 --- a/Tests/Unit/AutoRoute/FactoryTest.php +++ b/Tests/Unit/AutoRoute/FactoryTest.php @@ -61,23 +61,21 @@ public function provideTestGetChain() array( array( 'content_path' => array( - 'path_units' => array( - 'base' => array( - 'provider' => array( - 'name' => 'fixed', - 'options' => array( - 'message' => 'foobar', - ), - ), - 'exists_action' => array( - 'strategy' => 'create', - 'options' => array(), - ), - 'not_exists_action' => array( - 'strategy' => 'throw_excep', - 'options' => array(), + 'base' => array( + 'provider' => array( + 'name' => 'fixed', + 'options' => array( + 'message' => 'foobar', ), ), + 'exists_action' => array( + 'strategy' => 'create', + 'options' => array(), + ), + 'not_exists_action' => array( + 'strategy' => 'throw_excep', + 'options' => array(), + ), ), ), 'content_name' => array( From 00c599d4ea23788aec96306c355afcf9c3e1e082 Mon Sep 17 00:00:00 2001 From: Wouter J Date: Sun, 24 Nov 2013 16:49:09 +0100 Subject: [PATCH 13/13] Fixed test --- Tests/Unit/AutoRoute/FactoryTest.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/Tests/Unit/AutoRoute/FactoryTest.php b/Tests/Unit/AutoRoute/FactoryTest.php index ec43520..d16e06b 100644 --- a/Tests/Unit/AutoRoute/FactoryTest.php +++ b/Tests/Unit/AutoRoute/FactoryTest.php @@ -61,20 +61,22 @@ public function provideTestGetChain() array( array( 'content_path' => array( - 'base' => array( - 'provider' => array( - 'name' => 'fixed', - 'options' => array( - 'message' => 'foobar', + 'path_units' => array( + 'base' => array( + 'provider' => array( + 'name' => 'fixed', + 'options' => array( + 'message' => 'foobar', + ), + ), + 'exists_action' => array( + 'strategy' => 'create', + 'options' => array(), + ), + 'not_exists_action' => array( + 'strategy' => 'throw_excep', + 'options' => array(), ), - ), - 'exists_action' => array( - 'strategy' => 'create', - 'options' => array(), - ), - 'not_exists_action' => array( - 'strategy' => 'throw_excep', - 'options' => array(), ), ), ),