From efdc5ece05f3827d8fa424d77ade2184d757a1f3 Mon Sep 17 00:00:00 2001 From: Christoph Reiter <reiter.christoph@gmail.com> Date: Wed, 28 Jul 2021 16:12:26 +0200 Subject: [PATCH] Adjust to new naming schema everywhere --- README.md | 26 +++++------ composer.json | 6 +-- phpunit.xml.dist | 2 +- src/Command/TestCommand.php | 2 +- src/Controller/LoggedInOnly.php | 4 +- src/DataPersister/PlaceDataPersister.php | 6 +-- .../PlaceCollectionDataProvider.php | 6 +-- src/DataProvider/PlaceItemDataProvider.php | 6 +-- ...rBundle.php => DbpRelayTemplateBundle.php} | 4 +- src/DependencyInjection/Configuration.php | 4 +- ...sion.php => DbpRelayTemplateExtension.php} | 6 +-- src/Entity/Place.php | 46 ++++++++++++++----- src/Resources/config/services.yaml | 16 +++---- src/Service/ExternalApi.php | 4 +- src/Service/MyCustomService.php | 2 +- src/Service/PlaceProviderInterface.php | 4 +- tests/ApiTest.php | 12 ++--- tests/Kernel.php | 8 ++-- tests/Service/ExternalApiTest.php | 6 +-- 19 files changed, 97 insertions(+), 73 deletions(-) rename src/{DbpStarterBundle.php => DbpRelayTemplateBundle.php} (72%) rename src/DependencyInjection/{DbpStarterExtension.php => DbpRelayTemplateExtension.php} (84%) diff --git a/README.md b/README.md index c2fa977..32b2c18 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ -# DBP API Starter Bundle +# Relay Template Bundle This Symfony bundle can be used as a template for creating new bundles for the -DBP API project. +DBP Relay project. -When including this bundle into your DBP API server it will gain the following +When including this bundle into your API server it will gain the following features: * A custom `./bin/console` command @@ -13,9 +13,9 @@ features: ## Using the Bundle as a Template * Copy the repo contents -* Adjust the project name in `composer.json` +* Adjust the package name in `composer.json` * Invent a new PHP namespace and adjust it in all PHP files -* Rename `src/DbpStarterBundle` and `DependencyInjection/DbpStarterExtension` to match the new project name +* Rename `src/DbpRelayTemplateBundle` and `DependencyInjection/DbpRelayTemplateExtension` to match the new project name ## Integration into the API Server @@ -25,7 +25,7 @@ features: "repositories": [ { "type": "vcs", - "url": "git@gitlab.tugraz.at:dbp/dbp-api/api-starter-bundle.git" + "url": "git@gitlab.tugraz.at:dbp/dbp-api/dbp-relay-template-bundle.git" } ], ``` @@ -33,14 +33,14 @@ features: * Add the bundle package as a dependency: ``` -composer require dbp/api-starter-bundle=dev-main +composer require dbp/relay-template-bundle=dev-main ``` * Add the bundle to your `config/bundles.php`: ```php ... -DBP\API\StarterBundle\DbpStarterBundle::class => ['all' => true], +Dbp\Relay\TemplateBundle\DbpRelayTemplateBundle::class => ['all' => true], DBP\API\CoreBundle\DbpCoreBundle::class => ['all' => true], ]; ``` @@ -52,16 +52,16 @@ DBP\API\CoreBundle\DbpCoreBundle::class => ['all' => true], The bundle has a `secret_token` configuration value that you can specify in your app, either by hardcoding it, or by referencing an environment variable. -For this create `config/packages/dbp_starter.yaml` in the app with the following +For this create `config/packages/dbp_relay_template.yaml` in the app with the following content: ```yaml -dbp_starter: +dbp_relay_template: secret_token: 42 # secret_token: '%env(SECRET_TOKEN)%' ``` -The value gets read in `DbpStarterExtension` and passed when creating the +The value gets read in `DbpRelayTemplateExtension` and passed when creating the `MyCustomService` service. For more info on bundle configuration see @@ -79,6 +79,6 @@ https://symfony.com/doc/current/bundles/configuration.html Don't forget you need to pull down your dependencies in your main application if you are installing packages in a bundle. ```bash -# updates and installs dependencies from dbp/api-starter-bundle -composer update dbp/api-starter-bundle +# updates and installs dependencies from dbp/relay-template-bundle +composer update dbp/relay-template-bundle ``` diff --git a/composer.json b/composer.json index cf4fb3b..1774635 100644 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "dbp/api-starter-bundle", + "name": "dbp/relay-template-bundle", "type": "symfony-bundle", "license": "AGPL-3.0-or-later", "require": { @@ -26,12 +26,12 @@ ], "autoload": { "psr-4": { - "DBP\\API\\StarterBundle\\": "src/" + "Dbp\\Relay\\TemplateBundle\\": "src/" } }, "autoload-dev": { "psr-4": { - "DBP\\API\\StarterBundle\\Tests\\": "tests/" + "Dbp\\Relay\\TemplateBundle\\Tests\\": "tests/" } }, "config": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c8117a0..ed9ccc1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -14,7 +14,7 @@ <server name="SYMFONY_PHPUNIT_REMOVE" value=""/> <server name="SYMFONY_PHPUNIT_VERSION" value="9"/> <server name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/> - <server name="KERNEL_CLASS" value="DBP\API\StarterBundle\Tests\Kernel"/> + <server name="KERNEL_CLASS" value="Dbp\Relay\TemplateBundle\Tests\Kernel"/> </php> <testsuites> <testsuite name="Project Test Suite"> diff --git a/src/Command/TestCommand.php b/src/Command/TestCommand.php index 61b7bf8..aae2a4c 100644 --- a/src/Command/TestCommand.php +++ b/src/Command/TestCommand.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DBP\API\StarterBundle\Command; +namespace Dbp\Relay\TemplateBundle\Command; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; diff --git a/src/Controller/LoggedInOnly.php b/src/Controller/LoggedInOnly.php index 18b5785..16aee9c 100644 --- a/src/Controller/LoggedInOnly.php +++ b/src/Controller/LoggedInOnly.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace DBP\API\StarterBundle\Controller; +namespace Dbp\Relay\TemplateBundle\Controller; -use DBP\API\StarterBundle\Entity\Place; +use Dbp\Relay\TemplateBundle\Entity\Place; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; diff --git a/src/DataPersister/PlaceDataPersister.php b/src/DataPersister/PlaceDataPersister.php index c9b8631..2fd5095 100644 --- a/src/DataPersister/PlaceDataPersister.php +++ b/src/DataPersister/PlaceDataPersister.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace DBP\API\StarterBundle\DataPersister; +namespace Dbp\Relay\TemplateBundle\DataPersister; use ApiPlatform\Core\DataPersister\DataPersisterInterface; -use DBP\API\StarterBundle\Entity\Place; -use DBP\API\StarterBundle\Service\PlaceProviderInterface; +use Dbp\Relay\TemplateBundle\Entity\Place; +use Dbp\Relay\TemplateBundle\Service\PlaceProviderInterface; class PlaceDataPersister implements DataPersisterInterface { diff --git a/src/DataProvider/PlaceCollectionDataProvider.php b/src/DataProvider/PlaceCollectionDataProvider.php index f89871e..ef8da3e 100644 --- a/src/DataProvider/PlaceCollectionDataProvider.php +++ b/src/DataProvider/PlaceCollectionDataProvider.php @@ -2,13 +2,13 @@ declare(strict_types=1); -namespace DBP\API\StarterBundle\DataProvider; +namespace Dbp\Relay\TemplateBundle\DataProvider; use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface; use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use DBP\API\CoreBundle\Helpers\ArrayFullPaginator; -use DBP\API\StarterBundle\Entity\Place; -use DBP\API\StarterBundle\Service\PlaceProviderInterface; +use Dbp\Relay\TemplateBundle\Entity\Place; +use Dbp\Relay\TemplateBundle\Service\PlaceProviderInterface; final class PlaceCollectionDataProvider implements CollectionDataProviderInterface, RestrictedDataProviderInterface { diff --git a/src/DataProvider/PlaceItemDataProvider.php b/src/DataProvider/PlaceItemDataProvider.php index e5b21c2..69a8b1b 100644 --- a/src/DataProvider/PlaceItemDataProvider.php +++ b/src/DataProvider/PlaceItemDataProvider.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace DBP\API\StarterBundle\DataProvider; +namespace Dbp\Relay\TemplateBundle\DataProvider; use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; -use DBP\API\StarterBundle\Entity\Place; -use DBP\API\StarterBundle\Service\PlaceProviderInterface; +use Dbp\Relay\TemplateBundle\Entity\Place; +use Dbp\Relay\TemplateBundle\Service\PlaceProviderInterface; final class PlaceItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface { diff --git a/src/DbpStarterBundle.php b/src/DbpRelayTemplateBundle.php similarity index 72% rename from src/DbpStarterBundle.php rename to src/DbpRelayTemplateBundle.php index d602859..e040da7 100644 --- a/src/DbpStarterBundle.php +++ b/src/DbpRelayTemplateBundle.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace DBP\API\StarterBundle; +namespace Dbp\Relay\TemplateBundle; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\HttpKernel\Bundle\Bundle; -class DbpStarterBundle extends Bundle +class DbpRelayTemplateBundle extends Bundle { public function build(ContainerBuilder $container) { diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index b1ac473..7416da8 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DBP\API\StarterBundle\DependencyInjection; +namespace Dbp\Relay\TemplateBundle\DependencyInjection; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; @@ -11,7 +11,7 @@ class Configuration implements ConfigurationInterface { public function getConfigTreeBuilder() { - $treeBuilder = new TreeBuilder('dbp_starter'); + $treeBuilder = new TreeBuilder('dbp_relay_template'); $treeBuilder->getRootNode() ->children() diff --git a/src/DependencyInjection/DbpStarterExtension.php b/src/DependencyInjection/DbpRelayTemplateExtension.php similarity index 84% rename from src/DependencyInjection/DbpStarterExtension.php rename to src/DependencyInjection/DbpRelayTemplateExtension.php index 8cfbf94..2d55a11 100644 --- a/src/DependencyInjection/DbpStarterExtension.php +++ b/src/DependencyInjection/DbpRelayTemplateExtension.php @@ -2,14 +2,14 @@ declare(strict_types=1); -namespace DBP\API\StarterBundle\DependencyInjection; +namespace Dbp\Relay\TemplateBundle\DependencyInjection; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; use Symfony\Component\HttpKernel\DependencyInjection\ConfigurableExtension; -class DbpStarterExtension extends ConfigurableExtension +class DbpRelayTemplateExtension extends ConfigurableExtension { public function loadInternal(array $mergedConfig, ContainerBuilder $container) { @@ -23,7 +23,7 @@ class DbpStarterExtension extends ConfigurableExtension $loader->load('services.yaml'); // Inject the config value into the MyCustomService service - $definition = $container->getDefinition('DBP\API\StarterBundle\Service\MyCustomService'); + $definition = $container->getDefinition('Dbp\Relay\TemplateBundle\Service\MyCustomService'); $definition->addArgument($mergedConfig['secret_token']); } diff --git a/src/Entity/Place.php b/src/Entity/Place.php index 967145d..1efa7c0 100644 --- a/src/Entity/Place.php +++ b/src/Entity/Place.php @@ -2,37 +2,61 @@ declare(strict_types=1); -namespace DBP\API\StarterBundle\Entity; +namespace Dbp\Relay\TemplateBundle\Entity; use ApiPlatform\Core\Annotation\ApiProperty; use ApiPlatform\Core\Annotation\ApiResource; -use DBP\API\StarterBundle\Controller\LoggedInOnly; +use Dbp\Relay\TemplateBundle\Controller\LoggedInOnly; use Symfony\Component\Serializer\Annotation\Groups; /** * @ApiResource( * collectionOperations={ - * "get" + * "get" = { + * "path" = "/template/places", + * "openapi_context" = { + * "tags" = {"Template"}, + * }, + * } * }, * itemOperations={ - * "get", - * "put", - * "delete", + * "get" = { + * "path" = "/template/places/{identifier}", + * "openapi_context" = { + * "tags" = {"Template"}, + * }, + * }, + * "put" = { + * "path" = "/template/places/{identifier}", + * "openapi_context" = { + * "tags" = {"Template"}, + * }, + * }, + * "delete" = { + * "path" = "/template/places/{identifier}", + * "openapi_context" = { + * "tags" = {"Template"}, + * }, + * }, * "loggedin_only" = { * "security" = "is_granted('IS_AUTHENTICATED_FULLY')", * "method" = "GET", - * "path" = "/places/{identifier}/loggedin-only", + * "path" = "/template/places/{identifier}/loggedin-only", * "controller" = LoggedInOnly::class, - * "openapi_context" = {"summary" = "Only works when logged in."}, + * "openapi_context" = { + * "summary" = "Only works when logged in.", + * "tags" = {"Template"}, + * }, * } * }, * iri="https://schema.org/Place", + * shortName="TemplatePlace", * normalizationContext={ - * "groups" = {"Place:output"}, + * "groups" = {"TemplatePlace:output"}, * "jsonld_embed_context" = true * }, * denormalizationContext={ - * "groups" = {"Place:input"}, + * "groups" = {"TemplatePlace:input"}, * "jsonld_embed_context" = true * } * ) @@ -46,7 +70,7 @@ class Place /** * @ApiProperty(iri="https://schema.org/name") - * @Groups({"Place:output", "Place:input"}) + * @Groups({"TemplatePlace:output", "TemplatePlace:input"}) * * @var string */ diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index c326a10..8a9e173 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -1,28 +1,28 @@ services: - DBP\API\StarterBundle\Command\TestCommand: + Dbp\Relay\TemplateBundle\Command\TestCommand: autowire: true autoconfigure: true - DBP\API\StarterBundle\Controller\: + Dbp\Relay\TemplateBundle\Controller\: resource: '../../Controller' tags: ['controller.service_arguments'] autowire: true - DBP\API\StarterBundle\DataProvider\PlaceCollectionDataProvider: + Dbp\Relay\TemplateBundle\DataProvider\PlaceCollectionDataProvider: tags: [{ name: 'api_platform.collection_data_provider'}] autowire: true - DBP\API\StarterBundle\DataProvider\PlaceItemDataProvider: + Dbp\Relay\TemplateBundle\DataProvider\PlaceItemDataProvider: tags: ['api_platform.item_data_provider'] autowire: true - DBP\API\StarterBundle\Service\ExternalApi: + Dbp\Relay\TemplateBundle\Service\ExternalApi: autowire: true autoconfigure: true - DBP\API\StarterBundle\Service\MyCustomService: + Dbp\Relay\TemplateBundle\Service\MyCustomService: autowire: true autoconfigure: true - DBP\API\StarterBundle\Service\PlaceProviderInterface: - '@DBP\API\StarterBundle\Service\ExternalApi' \ No newline at end of file + Dbp\Relay\TemplateBundle\Service\PlaceProviderInterface: + '@Dbp\Relay\TemplateBundle\Service\ExternalApi' \ No newline at end of file diff --git a/src/Service/ExternalApi.php b/src/Service/ExternalApi.php index 6f5dd73..a5e0b10 100644 --- a/src/Service/ExternalApi.php +++ b/src/Service/ExternalApi.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace DBP\API\StarterBundle\Service; +namespace Dbp\Relay\TemplateBundle\Service; -use DBP\API\StarterBundle\Entity\Place; +use Dbp\Relay\TemplateBundle\Entity\Place; class ExternalApi implements PlaceProviderInterface { diff --git a/src/Service/MyCustomService.php b/src/Service/MyCustomService.php index 23c60e9..783a71c 100644 --- a/src/Service/MyCustomService.php +++ b/src/Service/MyCustomService.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DBP\API\StarterBundle\Service; +namespace Dbp\Relay\TemplateBundle\Service; class MyCustomService { diff --git a/src/Service/PlaceProviderInterface.php b/src/Service/PlaceProviderInterface.php index 2ff2aec..dc03399 100644 --- a/src/Service/PlaceProviderInterface.php +++ b/src/Service/PlaceProviderInterface.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace DBP\API\StarterBundle\Service; +namespace Dbp\Relay\TemplateBundle\Service; -use DBP\API\StarterBundle\Entity\Place; +use Dbp\Relay\TemplateBundle\Entity\Place; interface PlaceProviderInterface { diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 1fc411a..1cee1bf 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace DBP\API\StarterBundle\Tests; +namespace Dbp\Relay\TemplateBundle\Tests; use ApiPlatform\Core\Bridge\Symfony\Bundle\Test\ApiTestCase; use Symfony\Component\HttpFoundation\Response; @@ -12,16 +12,16 @@ class ApiTest extends ApiTestCase public function testBasics() { $client = self::createClient(); - $response = $client->request('GET', '/places'); + $response = $client->request('GET', '/template/places'); $this->assertSame(Response::HTTP_OK, $response->getStatusCode()); - $response = $client->request('GET', '/places/graz'); + $response = $client->request('GET', '/template/places/graz'); $this->assertSame(Response::HTTP_OK, $response->getStatusCode()); - $response = $client->request('DELETE', '/places/graz'); + $response = $client->request('DELETE', '/template/places/graz'); $this->assertSame(Response::HTTP_NO_CONTENT, $response->getStatusCode()); - $response = $client->request('PUT', '/places/graz', [ + $response = $client->request('PUT', '/template/places/graz', [ 'headers' => [ 'Content-Type' => 'application/json', ], @@ -34,7 +34,7 @@ class ApiTest extends ApiTestCase public function testNoAuth() { $client = self::createClient(); - $response = $client->request('GET', '/places/graz/loggedin-only'); + $response = $client->request('GET', '/template/places/graz/loggedin-only'); $this->assertSame(Response::HTTP_UNAUTHORIZED, $response->getStatusCode()); } } diff --git a/tests/Kernel.php b/tests/Kernel.php index 8594e3f..108c29d 100644 --- a/tests/Kernel.php +++ b/tests/Kernel.php @@ -2,11 +2,11 @@ declare(strict_types=1); -namespace DBP\API\StarterBundle\Tests; +namespace Dbp\Relay\TemplateBundle\Tests; use ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle; use DBP\API\CoreBundle\DbpCoreBundle; -use DBP\API\StarterBundle\DbpStarterBundle; +use Dbp\Relay\TemplateBundle\DbpRelayTemplateBundle; use Nelmio\CorsBundle\NelmioCorsBundle; use Symfony\Bundle\FrameworkBundle\FrameworkBundle; use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait; @@ -28,7 +28,7 @@ class Kernel extends BaseKernel yield new TwigBundle(); yield new NelmioCorsBundle(); yield new ApiPlatformBundle(); - yield new DbpStarterBundle(); + yield new DbpRelayTemplateBundle(); yield new DbpCoreBundle(); } @@ -44,7 +44,7 @@ class Kernel extends BaseKernel 'secret' => '', ]); - $c->loadFromExtension('dbp_starter', [ + $c->loadFromExtension('dbp_relay_template', [ 'secret_token' => 'secret-test', ]); } diff --git a/tests/Service/ExternalApiTest.php b/tests/Service/ExternalApiTest.php index c37060e..f1a85ac 100644 --- a/tests/Service/ExternalApiTest.php +++ b/tests/Service/ExternalApiTest.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace DBP\API\StarterBundle\Tests\Service; +namespace Dbp\Relay\TemplateBundle\Tests\Service; -use DBP\API\StarterBundle\Service\ExternalApi; -use DBP\API\StarterBundle\Service\MyCustomService; +use Dbp\Relay\TemplateBundle\Service\ExternalApi; +use Dbp\Relay\TemplateBundle\Service\MyCustomService; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class ExternalApiTest extends WebTestCase -- GitLab