Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 8ac2718

Browse files
committed
Added type option for the configured resources
1 parent 10fa629 commit 8ac2718

File tree

8 files changed

+111
-6
lines changed

8 files changed

+111
-6
lines changed

AutoRoute/Mapping/MetadataFactoryBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function getMetadataFactory()
3131
$mappingFactory = new MetadataFactory();
3232

3333
foreach ($this->resources as $resource) {
34-
$mappingFactory->addMetadatas($this->loader->load($resource));
34+
$mappingFactory->addMetadatas($this->loader->load($resource['path'], $resource['type']));
3535
}
3636

3737
return $mappingFactory;

DependencyInjection/Configuration.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,16 @@ public function getConfigTreeBuilder()
3131
->fixXmlConfig('path')
3232
->children()
3333
->arrayNode('paths')
34-
->prototype('scalar')->end()
34+
->prototype('array')
35+
->beforeNormalization()
36+
->ifString()
37+
->then(function ($v) { return array('path' => $v); })
38+
->end()
39+
->children()
40+
->scalarNode('path')->isRequired()->end()
41+
->scalarNode('type')->defaultNull()->end()
42+
->end()
43+
->end()
3544
->end() // directories
3645
->end()
3746
->end() // mapping

Resources/config/schema/routing-auto-1.0.xsd

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,16 @@
1717

1818
<xsd:complexType name="mapping">
1919
<xsd:sequence>
20-
<xsd:element name="path" type="xsd:string" minOccurs="0" maxOccurs="unbounded" />
20+
<xsd:element name="path" type="path" minOccurs="0" maxOccurs="unbounded" />
2121
</xsd:sequence>
2222
</xsd:complexType>
23+
24+
<xsd:complexType name="path">
25+
<xsd:simpleContent>
26+
<xsd:extension base="xsd:string">
27+
<xsd:attribute name="path" type="xsd:string" />
28+
<xsd:attribute name="type" type="xsd:string" />
29+
</xsd:extension>
30+
</xsd:simpleContent>
31+
</xsd:complexType>
2332
</xsd:schema>

Tests/Resources/Fixtures/config/config.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
'mapping' => array(
66
'paths' => array(
77
'Resources/config/SpecificObject.yml',
8-
'Resources/config/foo.xml',
8+
array('path' => 'Document/Post.php', 'type' => 'annotation'),
9+
array('path' => 'Resources/config/foo.xml'),
910
),
1011
),
1112
));

Tests/Resources/Fixtures/config/config.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
<mapping>
88
<path>Resources/config/SpecificObject.yml</path>
9-
<path>Resources/config/foo.xml</path>
9+
<path path="Document/Post.php" type="annotation" />
10+
<path path="Resources/config/foo.xml" />
1011
</mapping>
1112
</config>
1213
</container>

Tests/Resources/Fixtures/config/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ cmf_routing_auto:
33
mapping:
44
paths:
55
- Resources/config/SpecificObject.yml
6-
- Resources/config/foo.xml
6+
- { path: Document/Post.php, type: annotation }
7+
- { path: Resources/config/foo.xml }
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony CMF package.
5+
*
6+
* (c) 2011-2013 Symfony CMF
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Unit\DependencyInjection;
13+
14+
use Symfony\Cmf\Bundle\RoutingAutoBundle\DependencyInjection\Configuration;
15+
use Symfony\Cmf\Bundle\RoutingAutoBundle\DependencyInjection\CmfRoutingAutoExtension;
16+
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionConfigurationTestCase;
17+
18+
class ConfigurationTest extends AbstractExtensionConfigurationTestCase
19+
{
20+
protected function getContainerExtension()
21+
{
22+
return new CmfRoutingAutoExtension();
23+
}
24+
25+
protected function getConfiguration()
26+
{
27+
return new Configuration();
28+
}
29+
30+
public function testSupportsAllConfigFormats()
31+
{
32+
$expectedConfiguration = array(
33+
'auto_mapping' => false,
34+
'mapping' => array(
35+
'paths' => array(
36+
array('path' => 'Resources/config/SpecificObject.yml', 'type' => null),
37+
array('path' => 'Document/Post.php', 'type' => 'annotation'),
38+
array('path' => 'Resources/config/foo.xml', 'type' => null),
39+
),
40+
),
41+
);
42+
43+
$sources = array_map(function ($path) {
44+
return __DIR__.'/../../Resources/Fixtures/'.$path;
45+
}, array(
46+
'config/config.yml',
47+
'config/config.xml',
48+
'config/config.php',
49+
));
50+
51+
foreach ($sources as $source) {
52+
$this->assertProcessedConfigurationEquals($expectedConfiguration, array($source));
53+
}
54+
}
55+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony CMF package.
5+
*
6+
* (c) 2011-2013 Symfony CMF
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Cmf\Bundle\RoutingAutoBundle\Tests\Unit\DependencyInjection;
13+
14+
use Symfony\Cmf\Component\Testing\Unit\XmlSchemaTestCase;
15+
16+
class XmlSchemaTest extends XmlSchemaTestCase
17+
{
18+
public function testSchema()
19+
{
20+
$xmlFiles = array_map(function ($file) {
21+
return __DIR__.'/../../Resources/Fixtures/config/'.$file;
22+
}, array(
23+
'config1.xml',
24+
'config.xml',
25+
));
26+
27+
$this->assertSchemaAcceptsXml($xmlFiles, __DIR__.'/../../../Resources/config/schema/routing-auto-1.0.xsd');
28+
}
29+
}

0 commit comments

Comments
 (0)