Skip to content
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

feat Ability to configure resource_class_directories #1665

Merged
merged 1 commit into from
Jan 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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