Skip to content
Commits on Source (15)
......@@ -12,10 +12,16 @@
},
"packageRules": [
{
"matchPackagePrefixes": [
"symfony/"
],
"matchPackagePrefixes": ["symfony/"],
"allowedVersions": "<6"
},
{
"matchPackageNames": ["api-platform/core"],
"allowedVersions": "<3"
},
{
"matchPackageNames": ["friendsofphp/php-cs-fixer"],
"allowedVersions": "<3.5"
}
],
"js": {
......
This diff is collapsed.
......@@ -6,29 +6,30 @@ namespace Dbp\Relay\BasePersonBundle\API;
use Dbp\Relay\BasePersonBundle\Entity\Person;
use Dbp\Relay\CoreBundle\Exception\ApiError;
use Dbp\Relay\CoreBundle\Pagination\Paginator;
interface PersonProviderInterface
{
/**
* Throws an HTTP_NOT_FOUND exception if no person with the given ID can be found.
*
* @param array $options Available options:
* * Person::SEARCH_PARAMETER_NAME (whitespace separated list of search terms to perform a partial case-insensitive text search on person's full name)
* * LocalData::INCLUDE_PARAMETER_NAME
* * LocalData::QUERY_PARAMETER_NAME
*
* @throws ApiError
*/
public function getPersons(array $options): Paginator;
public function getPerson(string $id, array $options = []): Person;
/**
* Throws an HTTP_NOT_FOUND exception if no person with the given ID can be found.
*
* @param array $options Available options:
* * Person::SEARCH_PARAMETER_NAME (whitespace separated list of search terms to perform a partial case-insensitive text search on person's full name)
* * LocalData::INCLUDE_PARAMETER_NAME
* * LocalData::QUERY_PARAMETER_NAME
*
* @return Person[]
*
* @throws ApiError
*/
public function getPerson(string $id, array $options = []): Person;
public function getPersons(int $currentPageNumber, int $maxNumItemsPerPage, array $options = []): array;
/**
* Returns the Person matching the current user. Or null if there is no associated person
......
......@@ -4,19 +4,12 @@ declare(strict_types=1);
namespace Dbp\Relay\BasePersonBundle\DataProvider;
use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
use Dbp\Relay\BasePersonBundle\API\PersonProviderInterface;
use Dbp\Relay\BasePersonBundle\Entity\Person;
use Dbp\Relay\CoreBundle\LocalData\LocalData;
use Dbp\Relay\CoreBundle\Pagination\Pagination;
use Dbp\Relay\CoreBundle\Pagination\Paginator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Dbp\Relay\CoreBundle\DataProvider\AbstractDataProvider;
final class PersonCollectionDataProvider extends AbstractController implements CollectionDataProviderInterface, RestrictedDataProviderInterface
class PersonDataProvider extends AbstractDataProvider
{
public const MAX_NUM_ITEMS_PER_PAGE_DEFAULT = 50;
/** @var PersonProviderInterface */
private $personProvider;
......@@ -25,25 +18,22 @@ final class PersonCollectionDataProvider extends AbstractController implements C
$this->personProvider = $personProvider;
}
public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
protected function getResourceClass(): string
{
return Person::class === $resourceClass;
return Person::class;
}
public function getCollection(string $resourceClass, string $operationName = null, array $context = []): Paginator
protected function getItemById($id, array $options = []): object
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$filters = $context['filters'] ?? [];
$options = [];
return $this->personProvider->getPerson($id, $options);
}
protected function getPage(int $currentPageNumber, int $maxNumItemsPerPage, array $filters = [], array $options = []): array
{
if ($search = ($filters['search'] ?? null)) {
$options[Person::SEARCH_PARAMETER_NAME] = $search;
}
LocalData::addOptions($options, $filters);
Pagination::addOptions($options, $filters, self::MAX_NUM_ITEMS_PER_PAGE_DEFAULT);
return $this->personProvider->getPersons($options);
return $this->personProvider->getPersons($currentPageNumber, $maxNumItemsPerPage, $options);
}
}
<?php
declare(strict_types=1);
namespace Dbp\Relay\BasePersonBundle\DataProvider;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
use Dbp\Relay\BasePersonBundle\API\PersonProviderInterface;
use Dbp\Relay\BasePersonBundle\Entity\Person;
use Dbp\Relay\CoreBundle\LocalData\LocalData;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
final class PersonItemDataProvider extends AbstractController implements ItemDataProviderInterface, RestrictedDataProviderInterface
{
private $api;
public function __construct(PersonProviderInterface $api)
{
$this->api = $api;
}
public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
{
return Person::class === $resourceClass;
}
public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []): ?Person
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
$filters = $context['filters'] ?? [];
$options = [];
LocalData::addOptions($options, $filters);
return $this->api->getPerson($id, $options);
}
}
......@@ -6,8 +6,7 @@ services:
Dbp\Relay\BasePersonBundle\API\PersonProviderInterface:
'@Dbp\Relay\BasePersonBundle\Service\DummyPersonProvider'
Dbp\Relay\BasePersonBundle\DataProvider\:
resource: '../../DataProvider'
Dbp\Relay\BasePersonBundle\DataProvider\PersonDataProvider:
autowire: true
autoconfigure: true
......
......@@ -6,9 +6,6 @@ namespace Dbp\Relay\BasePersonBundle\Service;
use Dbp\Relay\BasePersonBundle\API\PersonProviderInterface;
use Dbp\Relay\BasePersonBundle\Entity\Person;
use Dbp\Relay\CoreBundle\Pagination\FullPaginator;
use Dbp\Relay\CoreBundle\Pagination\Pagination;
use Dbp\Relay\CoreBundle\Pagination\Paginator;
class DummyPersonProvider implements PersonProviderInterface
{
......@@ -22,7 +19,7 @@ class DummyPersonProvider implements PersonProviderInterface
$this->currentIdentifier = null;
}
public function getPersons(array $options): Paginator
public function getPersons(int $currentPageNumber, int $maxNumItemsPerPage, array $options = []): array
{
$persons = [];
$currentPerson = $this->getCurrentPerson();
......@@ -30,7 +27,7 @@ class DummyPersonProvider implements PersonProviderInterface
$persons[] = $currentPerson;
}
return new FullPaginator($persons, 1, Pagination::MAX_NUM_ITEMS_PER_PAGE_DEFAULT, count($persons));
return $persons;
}
public function getPerson(string $id, array $options = []): Person
......
......@@ -6,9 +6,6 @@ namespace Dbp\Relay\BasePersonBundle\TestUtils;
use Dbp\Relay\BasePersonBundle\API\PersonProviderInterface;
use Dbp\Relay\BasePersonBundle\Entity\Person;
use Dbp\Relay\CoreBundle\Pagination\FullPaginator;
use Dbp\Relay\CoreBundle\Pagination\Pagination;
use Dbp\Relay\CoreBundle\Pagination\Paginator;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class DummyPersonProvider implements PersonProviderInterface
......@@ -21,11 +18,9 @@ class DummyPersonProvider implements PersonProviderInterface
$this->person = $person;
}
public function getPersons(array $options): Paginator
public function getPersons(int $currentPageNumber, int $maxNumItemsPerPage, array $options = []): array
{
$persons = [$this->person];
return new FullPaginator($persons, 1, Pagination::MAX_NUM_ITEMS_PER_PAGE_DEFAULT, count($persons));
return [$this->person];
}
public function getPerson(string $id, array $options = []): Person
......