Skip to content
Snippets Groups Projects
Commit efdc5ece authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Adjust to new naming schema everywhere

parent bc8c2ba5
No related branches found
No related tags found
No related merge requests found
Pipeline #105732 passed
Showing
with 97 additions and 73 deletions
# 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
```
{
"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": {
......
......@@ -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">
......
......@@ -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;
......
......@@ -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;
......
......@@ -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
{
......
......@@ -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
{
......
......@@ -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
{
......
......@@ -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)
{
......
......@@ -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()
......
......@@ -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']);
}
......
......@@ -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
*/
......
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
......@@ -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
{
......
......@@ -2,7 +2,7 @@
declare(strict_types=1);
namespace DBP\API\StarterBundle\Service;
namespace Dbp\Relay\TemplateBundle\Service;
class MyCustomService
{
......
......@@ -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
{
......
......@@ -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());
}
}
......@@ -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',
]);
}
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment