diff --git a/README.md b/README.md index c2fa9770d60c23b5e42f34dae8c812bda6dd59c2..32b2c18436c499273192156c2c433d0a6ad419bf 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 cf4fb3b3292efdf4159bfa5bb10e35a2d13236c0..177463516c51f0211438ac0d11dd25cc99d01b45 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 c8117a0e3c572c076b80502205dc3ce8a670c458..ed9ccc15fed7a350a58de800d744bb98839099bf 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 61b7bf82ed60cd0d302c8120f8ef63a488ebc2ba..aae2a4c19920275b03917ffafe7122f2052511b2 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 18b5785470b474791f401999c0187c351dc1a1b8..16aee9cad7820f56438514b2a72f2782ccb527bb 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 c9b8631548c824b549f2e1afa62d2f0527ee9e44..2fd50959c319e87c71cbaf6c04843a453a99a917 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 f89871e18d330979e219c5c345233817e4d03a8e..ef8da3e5b07198a93738794023bba2c96c9794a3 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 e5b21c2a41b16451778120a2a9e69aa82f54319a..69a8b1b5a5d7d713cd505f22d76524747629283b 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 d6028598e93a32049fc72fd37c6cdbde44c0f094..e040da739dc6ff16c7fdf48812ea48a36b264d30 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 b1ac473f1fc2c2565e52edf43e28e2bac0d3ecd5..7416da89173f48e6a91d123c3da6d9033c72912e 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 8cfbf947f53ce30d41680e7aac21947d3520caa4..2d55a11f96a86487eefefc4509b6525dae4700c5 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 967145d3d33f2c478a692fac8ced34281b1806b8..1efa7c0c702dad77d4be174d62bfc69fe6613877 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 c326a10165c631bc8eef25cf472634c84afa2ac7..8a9e1738743077f5ea70bae3f86b2867df4e2da7 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 6f5dd7331aeb609134479efdaa2e7334f951554d..a5e0b1036b00af284af542e80b8de3b4550909b2 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 23c60e98ae62b3d23f26f3ffbfadcbdcf61f86c3..783a71c31728812e051f7d44cdbc18be2fa8f83a 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 2ff2aec799272ff0c5be2729d100c35428ace373..dc0339998df6ca0b3b4c791d3dd45e0571658fb4 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 1fc411a641606a21c1571c241014480ce3e9fb6a..1cee1bf49894cf5f0c2c7efe7fc164ab3325b0eb 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 8594e3f697be101584516fa172c287d70745f7dd..108c29dea8a4974ad0b18b2cee1f92567b4a4627 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 c37060e41ff96b66e21fcdd58181f7b1b866df9e..f1a85acc0f0a5452b9741a25212cd13e5bf44757 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