Skip to content

Commit

Permalink
feat Ability to configure resource_class_directories
Browse files Browse the repository at this point in the history
  • Loading branch information
abluchet committed Jan 25, 2018
1 parent d4d8fa8 commit 721da25
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ private function registerMetadataConfiguration(ContainerBuilder $container, arra

list($xmlResources, $yamlResources) = $this->getResourcesToWatch($container, $config['mapping']['paths']);

if (isset($config['resource_class_directories']) && $config['resource_class_directories']) {
$container->setParameter('api_platform.resource_class_directories', array_merge(
$config['resource_class_directories'], $container->getParameter('api_platform.resource_class_directories')
));
}

$container->getDefinition('api_platform.metadata.extractor.xml')->addArgument($xmlResources);

if (class_exists(Annotation::class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ public function getConfigTreeBuilder()
->end()
->end()

->arrayNode('resource_class_directories')
->prototype('scalar')->end()
->end()

->arrayNode('http_cache')
->addDefaultsIfNotSet()
->children()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,28 @@ public function testEnableSecurity()
$this->extension->load(self::DEFAULT_CONFIG, $containerBuilder);
}

public function testAddResourceClassDirectories()
{
$containerBuilderProphecy = $this->getBaseContainerBuilderProphecy();
$containerBuilderProphecy->getParameter('api_platform.resource_class_directories')->shouldBeCalled()->willReturn([]);
$i = 0;
// it's called once from getResourcesToWatch and then if the configuration exists
$containerBuilderProphecy->setParameter('api_platform.resource_class_directories', Argument::that(function ($arg) use ($i) {
if (0 === $i++) {
return $arg;
}

if (!in_array('foobar', $arg, true)) {
throw new \Exception('"foobar" should be in "resource_class_directories"');
}

return $arg;
}))->shouldBeCalled();
$containerBuilder = $containerBuilderProphecy->reveal();

$this->extension->load(array_merge_recursive(self::DEFAULT_CONFIG, ['api_platform' => ['resource_class_directories' => ['foobar']]]), $containerBuilder);
}

/**
* @expectedException \ApiPlatform\Core\Exception\RuntimeException
* @expectedExceptionMessageRegExp /Unsupported mapping type in ".+", supported types are XML & Yaml\./
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ public function testDefaultConfig()
'vary' => ['Accept'],
'public' => null,
],
'resource_class_directories' => []
], $config);
}

Expand Down

0 comments on commit 721da25

Please sign in to comment.