diff --git a/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php b/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php
index b24a3180b6c..d6d6742df4b 100644
--- a/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php
+++ b/src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php
@@ -59,7 +59,7 @@ public function load(array $configs, ContainerBuilder $container)
}
}
- $container->setAlias('api_platform.routing.resource_path_generator', $config['routing']['resource_path_generator']);
+ $container->setAlias('api_platform.naming.resource_path_naming_strategy', $config['naming']['resource_path_naming_strategy']);
if ($config['name_converter']) {
$container->setAlias('api_platform.name_converter', $config['name_converter']);
diff --git a/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php b/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php
index e6826a457a8..4461bf1438f 100644
--- a/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php
+++ b/src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php
@@ -58,10 +58,10 @@ public function getConfigTreeBuilder()
->end()
->end()
->end()
- ->arrayNode('routing')
+ ->arrayNode('naming')
->addDefaultsIfNotSet()
->children()
- ->scalarNode('resource_path_generator')->defaultValue('api_platform.routing.resource_path_generator.underscore')->info('Specify the strategy to use for generating resource paths.')->end()
+ ->scalarNode('resource_path_naming_strategy')->defaultValue('api_platform.naming.resource_path_naming_strategy.underscore')->info('Specify the strategy to use for generating resource paths.')->end()
->end()
->end()
->scalarNode('name_converter')->defaultNull()->info('Specify a name converter to use.')->end()
diff --git a/src/Bridge/Symfony/Bundle/Resources/config/api.xml b/src/Bridge/Symfony/Bundle/Resources/config/api.xml
index 6d90d0d8070..da1989027f2 100644
--- a/src/Bridge/Symfony/Bundle/Resources/config/api.xml
+++ b/src/Bridge/Symfony/Bundle/Resources/config/api.xml
@@ -24,7 +24,7 @@
-
+
@@ -49,11 +49,10 @@
-
+
-
-
-
+
+
diff --git a/src/Bridge/Symfony/Routing/ApiLoader.php b/src/Bridge/Symfony/Routing/ApiLoader.php
index 4cc9ab57a75..4bcf17a8db1 100644
--- a/src/Bridge/Symfony/Routing/ApiLoader.php
+++ b/src/Bridge/Symfony/Routing/ApiLoader.php
@@ -15,7 +15,7 @@
use ApiPlatform\Core\Exception\RuntimeException;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
-use ApiPlatform\Core\Routing\ResourcePathGeneratorInterface;
+use ApiPlatform\Core\Naming\ResourcePathNamingStrategyInterface;
use Doctrine\Common\Inflector\Inflector;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Config\Loader\Loader;
@@ -41,7 +41,7 @@ final class ApiLoader extends Loader
private $resourcePathGenerator;
private $container;
- public function __construct(KernelInterface $kernel, ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, ResourcePathGeneratorInterface $resourcePathGenerator, ContainerInterface $container)
+ public function __construct(KernelInterface $kernel, ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, ResourcePathNamingStrategyInterface $resourcePathGenerator, ContainerInterface $container)
{
$this->fileLoader = new XmlFileLoader(new FileLocator($kernel->locateResource('@ApiPlatformBundle/Resources/config/routing')));
$this->resourceNameCollectionFactory = $resourceNameCollectionFactory;
diff --git a/src/Routing/UnderscoreResourcePathGenerator.php b/src/Naming/DashResourcePathNamingStrategy.php
similarity index 56%
rename from src/Routing/UnderscoreResourcePathGenerator.php
rename to src/Naming/DashResourcePathNamingStrategy.php
index 5a59b9cdcc0..9786814f420 100644
--- a/src/Routing/UnderscoreResourcePathGenerator.php
+++ b/src/Naming/DashResourcePathNamingStrategy.php
@@ -9,19 +9,22 @@
* file that was distributed with this source code.
*/
-namespace ApiPlatform\Core\Routing;
+namespace ApiPlatform\Core\Naming;
use Doctrine\Common\Inflector\Inflector;
/**
+ * Generates a path with words separated by dashes.
+ *
* @author Paul Le Corre
*/
-class UnderscoreResourcePathGenerator implements ResourcePathGeneratorInterface
+final class DashResourcePathNamingStrategy implements ResourcePathNamingStrategyInterface
{
+ /**
+ * {@inheritdoc}
+ */
public function generateResourceBasePath(string $resourceShortName) : string
{
- $pathName = Inflector::tableize($resourceShortName);
-
- return Inflector::pluralize($pathName);
+ return Inflector::pluralize(strtolower(preg_replace('~(?<=\\w)([A-Z])~', '-$1', $resourceShortName)));
}
}
diff --git a/src/Routing/ResourcePathGeneratorInterface.php b/src/Naming/ResourcePathNamingStrategyInterface.php
similarity index 60%
rename from src/Routing/ResourcePathGeneratorInterface.php
rename to src/Naming/ResourcePathNamingStrategyInterface.php
index 2e21079aa31..d53241b45f6 100644
--- a/src/Routing/ResourcePathGeneratorInterface.php
+++ b/src/Naming/ResourcePathNamingStrategyInterface.php
@@ -9,12 +9,21 @@
* file that was distributed with this source code.
*/
-namespace ApiPlatform\Core\Routing;
+namespace ApiPlatform\Core\Naming;
/**
+ * Generates a path from a resource name.
+ *
* @author Paul Le Corre
*/
-interface ResourcePathGeneratorInterface
+interface ResourcePathNamingStrategyInterface
{
+ /**
+ * Generates the base path.
+ *
+ * @param string $resourceShortName
+ *
+ * @return string
+ */
public function generateResourceBasePath(string $resourceShortName) : string;
}
diff --git a/src/Routing/DashResourcePathGenerator.php b/src/Naming/UnderscoreResourcePathNamingStrategy.php
similarity index 58%
rename from src/Routing/DashResourcePathGenerator.php
rename to src/Naming/UnderscoreResourcePathNamingStrategy.php
index f2d7e41c708..3fb5eb92dfc 100644
--- a/src/Routing/DashResourcePathGenerator.php
+++ b/src/Naming/UnderscoreResourcePathNamingStrategy.php
@@ -9,19 +9,22 @@
* file that was distributed with this source code.
*/
-namespace ApiPlatform\Core\Routing;
+namespace ApiPlatform\Core\Naming;
use Doctrine\Common\Inflector\Inflector;
/**
+ * Generates a path with words separated by underscores.
+ *
* @author Paul Le Corre
*/
-class DashResourcePathGenerator implements ResourcePathGeneratorInterface
+final class UnderscoreResourcePathNamingStrategy implements ResourcePathNamingStrategyInterface
{
+ /**
+ * {@inheritdoc}
+ */
public function generateResourceBasePath(string $resourceShortName) : string
{
- $pathName = strtolower(preg_replace('~(?<=\\w)([A-Z])~', '-$1', $resourceShortName));
-
- return Inflector::pluralize($pathName);
+ return Inflector::pluralize(Inflector::tableize($resourceShortName));
}
}
diff --git a/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php b/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php
index e6ae21e675f..cfc682de640 100644
--- a/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php
+++ b/tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php
@@ -260,8 +260,8 @@ private function getContainerBuilderProphecy()
'api_platform.route_loader',
'api_platform.router',
'api_platform.iri_converter',
- 'api_platform.routing.resource_path_generator.underscore',
- 'api_platform.routing.resource_path_generator.dash',
+ 'api_platform.naming.resource_path_naming_strategy.underscore',
+ 'api_platform.naming.resource_path_naming_strategy.dash',
'api_platform.listener.request.format',
'api_platform.listener.view.serializer',
'api_platform.listener.view.deserializer',
@@ -317,7 +317,7 @@ private function getContainerBuilderProphecy()
}
$aliases = [
- 'api_platform.routing.resource_path_generator' => 'api_platform.routing.resource_path_generator.underscore',
+ 'api_platform.naming.resource_path_naming_strategy' => 'api_platform.naming.resource_path_naming_strategy.underscore',
'api_platform.metadata.resource.name_collection_factory' => 'api_platform.metadata.resource.name_collection_factory.annotation',
];
diff --git a/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php b/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php
index bd00e614adb..2fe86407519 100644
--- a/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php
+++ b/tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php
@@ -34,8 +34,8 @@ public function testDefaultConfig()
'title' => 'title',
'description' => 'description',
'formats' => ['jsonld' => ['mime_types' => ['application/ld+json']]],
- 'routing' => [
- 'resource_path_generator' => 'api_platform.routing.resource_path_generator.underscore',
+ 'naming' => [
+ 'resource_path_naming_strategy' => 'api_platform.naming.resource_path_naming_strategy.underscore',
],
'name_converter' => null,
'enable_fos_user' => false,
diff --git a/tests/Bridge/Symfony/Routing/ApiLoaderTest.php b/tests/Bridge/Symfony/Routing/ApiLoaderTest.php
index 1f1c413d9b7..9eea6d866a1 100644
--- a/tests/Bridge/Symfony/Routing/ApiLoaderTest.php
+++ b/tests/Bridge/Symfony/Routing/ApiLoaderTest.php
@@ -16,7 +16,7 @@
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata;
use ApiPlatform\Core\Metadata\Resource\ResourceNameCollection;
-use ApiPlatform\Core\Routing\ResourcePathGeneratorInterface;
+use ApiPlatform\Core\Naming\ResourcePathNamingStrategyInterface;
use ApiPlatform\Core\Tests\Fixtures\DummyEntity;
use Prophecy\Argument;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -156,7 +156,7 @@ private function getApiLoaderWithResourceMetadata(ResourceMetadata $resourceMeta
$resourceNameCollectionFactoryProphecy = $this->prophesize(ResourceNameCollectionFactoryInterface::class);
$resourceNameCollectionFactoryProphecy->create()->willReturn(new ResourceNameCollection([DummyEntity::class]));
- $resourcePathGeneratorProphecy = $this->prophesize(ResourcePathGeneratorInterface::class);
+ $resourcePathGeneratorProphecy = $this->prophesize(ResourcePathNamingStrategyInterface::class);
$resourcePathGeneratorProphecy->generateResourceBasePath('dummy')->willReturn('dummies');
$apiLoader = new ApiLoader($kernelProphecy->reveal(), $resourceNameCollectionFactoryProphecy->reveal(), $resourceMetadataFactoryProphecy->reveal(), $resourcePathGeneratorProphecy->reveal(), $containerProphecy->reveal());
diff --git a/tests/Routing/DashResourcePathGeneratorTest.php b/tests/Naming/DashResourcePathNamingStrategyTest.php
similarity index 62%
rename from tests/Routing/DashResourcePathGeneratorTest.php
rename to tests/Naming/DashResourcePathNamingStrategyTest.php
index 5476862cc9f..b780fefc3b1 100644
--- a/tests/Routing/DashResourcePathGeneratorTest.php
+++ b/tests/Naming/DashResourcePathNamingStrategyTest.php
@@ -9,15 +9,15 @@
* file that was distributed with this source code.
*/
-namespace ApiPlatform\Core\Tests\Routing;
+namespace ApiPlatform\Core\Tests\Naming;
-use ApiPlatform\Core\Routing\DashResourcePathGenerator;
+use ApiPlatform\Core\Naming\DashResourcePathNamingStrategy;
-class DashResourcePathGeneratorTest extends \PHPUnit_Framework_TestCase
+class DashResourcePathNamingStrategyTest extends \PHPUnit_Framework_TestCase
{
public function testGenerateResourceBasePath()
{
- $dashResourcePathGenerator = new DashResourcePathGenerator();
+ $dashResourcePathGenerator = new DashResourcePathNamingStrategy();
$this->assertSame('short-names', $dashResourcePathGenerator->generateResourceBasePath('ShortName'));
}
diff --git a/tests/Routing/RouterTest.php b/tests/Naming/RouterTest.php
similarity index 98%
rename from tests/Routing/RouterTest.php
rename to tests/Naming/RouterTest.php
index 0afcba19115..e8aaa34b8f6 100644
--- a/tests/Routing/RouterTest.php
+++ b/tests/Naming/RouterTest.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace ApiPlatform\Core\Tests\Routing;
+namespace ApiPlatform\Core\Tests\Naming;
use ApiPlatform\Core\Bridge\Symfony\Routing\Router;
use Prophecy\Argument;
diff --git a/tests/Routing/UnderscoreResourcePathGeneratorTest.php b/tests/Naming/UnderscoreResourcePathNamingStrategyTest.php
similarity index 69%
rename from tests/Routing/UnderscoreResourcePathGeneratorTest.php
rename to tests/Naming/UnderscoreResourcePathNamingStrategyTest.php
index 80b321a8dc9..a33ed2bdde4 100644
--- a/tests/Routing/UnderscoreResourcePathGeneratorTest.php
+++ b/tests/Naming/UnderscoreResourcePathNamingStrategyTest.php
@@ -9,15 +9,15 @@
* file that was distributed with this source code.
*/
-namespace ApiPlatform\Core\Tests\Routing;
+namespace ApiPlatform\Core\Tests\Naming;
-use ApiPlatform\Core\Routing\UnderscoreResourcePathGenerator;
+use ApiPlatform\Core\Naming\UnderscoreResourcePathNamingStrategy;
-class UnderscoreResourcePathGeneratorTest extends \PHPUnit_Framework_TestCase
+class UnderscoreResourcePathNamingStrategyTest extends \PHPUnit_Framework_TestCase
{
public function testGenerateResourceBasePath()
{
- $underscoreResourcePathGenerator = new UnderscoreResourcePathGenerator();
+ $underscoreResourcePathGenerator = new UnderscoreResourcePathNamingStrategy();
$this->assertSame('short_names', $underscoreResourcePathGenerator->generateResourceBasePath('ShortName'));
}