diff --git a/src/Command/TestCommand.php b/src/Command/TestCommand.php index 8d9005be5519d01f0d0406d95c134bd9f562a0e1..c894f0eb3ab26a56dbb173980e38906addd307b2 100644 --- a/src/Command/TestCommand.php +++ b/src/Command/TestCommand.php @@ -9,6 +9,11 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; +/** + * This is an example command. + * You can execute it with "php bin/console dbp:my-custom-command my-argument". + * Change "my-custom-command" to a more meaningful name in $defaultName. + */ class TestCommand extends Command { protected static $defaultName = 'dbp:my-custom-command'; diff --git a/src/Controller/LoggedInOnly.php b/src/Controller/LoggedInOnly.php index 7cfe4bd8bf59fa6c05503cfe89f1b6db9c7bf407..b10902f2351509374fc3ade492545a426aa5e3f2 100644 --- a/src/Controller/LoggedInOnly.php +++ b/src/Controller/LoggedInOnly.php @@ -8,6 +8,9 @@ use Dbp\Relay\ExampleBundle\Entity\Place; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; +/** + * This is an example controller that only allows logged-in users to access it. + */ class LoggedInOnly extends AbstractController { public function __invoke(Place $data, Request $request): Place diff --git a/src/DataPersister/PlaceDataPersister.php b/src/DataPersister/PlaceDataPersister.php index 8b90ff7a01c56046331c147a65a981363fbf0d2d..c98bee170ab6552e2ca7cc375eb7599d917c4eec 100644 --- a/src/DataPersister/PlaceDataPersister.php +++ b/src/DataPersister/PlaceDataPersister.php @@ -9,6 +9,9 @@ use Dbp\Relay\ExampleBundle\Entity\Place; use Dbp\Relay\ExampleBundle\Service\PlaceProviderInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +/** + * This is an example of a data persister where you can persist data for example with the help of a service that implements the PlaceProviderInterface. + */ class PlaceDataPersister extends AbstractController implements DataPersisterInterface { private $api; @@ -25,7 +28,13 @@ class PlaceDataPersister extends AbstractController implements DataPersisterInte public function persist($data): void { - // TODO + // TODO: Enable this if a user needs to be authenticated to persist data +// $this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY'); + + // TODO: Enable this if a user needs to have a specific role to persist data +// $this->denyAccessUnlessGranted('ROLE_SCOPE_EXAMPLE'); + + $this->api->storePlace($data); } public function remove($data) diff --git a/src/DataProvider/PlaceCollectionDataProvider.php b/src/DataProvider/PlaceCollectionDataProvider.php index a2537c7691c504f5094827116e5d826d59ee024f..ea307952f9f2e0d8a5a24be911949a0791e1dd4b 100644 --- a/src/DataProvider/PlaceCollectionDataProvider.php +++ b/src/DataProvider/PlaceCollectionDataProvider.php @@ -11,6 +11,9 @@ use Dbp\Relay\ExampleBundle\Entity\Place; use Dbp\Relay\ExampleBundle\Service\PlaceProviderInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +/** + * This is an example of a collection data provider that uses the PlaceProviderInterface to get the data for a collection of items. + */ final class PlaceCollectionDataProvider extends AbstractController implements CollectionDataProviderInterface, RestrictedDataProviderInterface { private $api; diff --git a/src/DataProvider/PlaceItemDataProvider.php b/src/DataProvider/PlaceItemDataProvider.php index dd0d633bf25e723cb7daa6f36a8beb3a839aba0f..49c0bcc50c424b11a9caeb93dcd97905b7b5447e 100644 --- a/src/DataProvider/PlaceItemDataProvider.php +++ b/src/DataProvider/PlaceItemDataProvider.php @@ -10,6 +10,9 @@ use Dbp\Relay\ExampleBundle\Entity\Place; use Dbp\Relay\ExampleBundle\Service\PlaceProviderInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; +/** + * This is an example of an item data provider that uses the PlaceProviderInterface to get the data for a single item. + */ final class PlaceItemDataProvider extends AbstractController implements ItemDataProviderInterface, RestrictedDataProviderInterface { private $api; diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 9a931b474d180d8ff027696329da7622bc02bec5..84bce7fedb6a78fb87694f987a052c8b086ba04f 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -9,6 +9,9 @@ use Symfony\Component\Config\Definition\ConfigurationInterface; class Configuration implements ConfigurationInterface { + /** + * You can setup your configuration here. + */ public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('dbp_relay_example'); diff --git a/src/Service/ExternalApi.php b/src/Service/ExternalApi.php index 791213a1073d290274a919538cabe164240ad5fc..29d93d22ad3ca33def9dcf497a69423e2035df69 100644 --- a/src/Service/ExternalApi.php +++ b/src/Service/ExternalApi.php @@ -6,6 +6,11 @@ namespace Dbp\Relay\ExampleBundle\Service; use Dbp\Relay\ExampleBundle\Entity\Place; +/** + * Class ExternalApi. + * + * This is an example of an external API that can be used to fetch data from an external service. + */ class ExternalApi implements PlaceProviderInterface { private $places; @@ -15,6 +20,7 @@ class ExternalApi implements PlaceProviderInterface // Make phpstan happy $service = $service; + // TODO: Fetch data from external service $this->places = []; $place1 = new Place(); $place1->setIdentifier('graz'); @@ -43,4 +49,9 @@ class ExternalApi implements PlaceProviderInterface { return $this->places; } + + public function storePlace(Place $place): void + { + // TODO: Store place in external service + } } diff --git a/src/Service/PlaceProviderInterface.php b/src/Service/PlaceProviderInterface.php index e7a25c9744abb9b5288a4fbac929c5aebcaa4359..2af0210a51b8e500beb21c270b3f69db2b64307d 100644 --- a/src/Service/PlaceProviderInterface.php +++ b/src/Service/PlaceProviderInterface.php @@ -11,4 +11,6 @@ interface PlaceProviderInterface public function getPlaceById(string $identifier): ?Place; public function getPlaces(): array; + + public function storePlace(Place $place): void; } diff --git a/tests/ApiTest.php b/tests/ApiTest.php index 957a1ac452d4bd123dba096276c0700745a88576..2c2e7df2ba61720d924895391d8e408819cb6a02 100644 --- a/tests/ApiTest.php +++ b/tests/ApiTest.php @@ -9,6 +9,16 @@ use Symfony\Component\HttpFoundation\Response; class ApiTest extends ApiTestCase { + /** + * You can test some basic api functionality here. + * + * @return void + * + * @throws \Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface + * @throws \Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface + * @throws \Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface + * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface + */ public function testBasics() { $client = self::createClient(); @@ -31,6 +41,11 @@ class ApiTest extends ApiTestCase $this->assertSame('foo', json_decode($response->getContent(), true)['name']); } + /** + * Test if you can access the api without a user. + * + * @throws \Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface + */ public function testNoAuth() { $client = self::createClient(); diff --git a/tests/Kernel.php b/tests/Kernel.php index 7c51a36a6cacf9001ac1fe10bf510a32ef41c3b9..924609daf38783668da341b2f1338e394952c8e0 100644 --- a/tests/Kernel.php +++ b/tests/Kernel.php @@ -47,6 +47,7 @@ class Kernel extends BaseKernel 'secret' => '', ]); + // TODO: Inject settings from dbp_relay_example.yaml $container->extension('dbp_relay_example', [ 'example_config' => 'test-42', ]);