Skip to content
Commits on Source (4)
......@@ -7436,16 +7436,16 @@
},
{
"name": "phpstan/phpstan",
"version": "1.9.1",
"version": "1.9.2",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "a59c8b5bfd4a236f27efc8b5ce72c313c2b54b5f"
"reference": "d6fdf01c53978b6429f1393ba4afeca39cc68afa"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/a59c8b5bfd4a236f27efc8b5ce72c313c2b54b5f",
"reference": "a59c8b5bfd4a236f27efc8b5ce72c313c2b54b5f",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/d6fdf01c53978b6429f1393ba4afeca39cc68afa",
"reference": "d6fdf01c53978b6429f1393ba4afeca39cc68afa",
"shasum": ""
},
"require": {
......@@ -7475,7 +7475,7 @@
],
"support": {
"issues": "https://github.com/phpstan/phpstan/issues",
"source": "https://github.com/phpstan/phpstan/tree/1.9.1"
"source": "https://github.com/phpstan/phpstan/tree/1.9.2"
},
"funding": [
{
......@@ -7491,7 +7491,7 @@
"type": "tidelift"
}
],
"time": "2022-11-04T13:35:59+00:00"
"time": "2022-11-10T09:56:11+00:00"
},
{
"name": "phpstan/phpstan-phpunit",
......
......@@ -7,12 +7,13 @@ namespace Dbp\Relay\CoreBundle\DataProvider;
use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
use Dbp\Relay\CoreBundle\Helpers\Locale;
use Dbp\Relay\CoreBundle\LocalData\LocalData;
use Dbp\Relay\CoreBundle\Locale\Locale;
use Dbp\Relay\CoreBundle\Pagination\Pagination;
use Dbp\Relay\CoreBundle\Pagination\PartialPaginator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
abstract class AbstractDataProvider extends AbstractController implements RestrictedDataProviderInterface, ItemDataProviderInterface, CollectionDataProviderInterface
{
......@@ -24,9 +25,19 @@ abstract class AbstractDataProvider extends AbstractController implements Restri
/** @var Locale */
private $locale;
public function __construct(RequestStack $requestStack)
/**
* @deprecated Use default constructor
*/
public function __construct(RequestStack $requestStack) /** @phpstan-ignore-line */
{
$this->locale = new Locale($requestStack);
}
/**
* @required
*/
public function setLocale(Locale $locale): void
{
$this->locale = $locale;
}
public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
......@@ -43,11 +54,9 @@ abstract class AbstractDataProvider extends AbstractController implements Restri
$currentPageNumber = Pagination::getCurrentPageNumber($filters);
$maxNumItemsPerPage = Pagination::getMaxNumItemsPerPage($filters);
$options = [];
LocalData::addOptions($options, $filters);
$this->locale->addLanguageOption($options);
return new PartialPaginator($this->getPage($currentPageNumber, $maxNumItemsPerPage, $filters, $options), $currentPageNumber, $maxNumItemsPerPage);
return new PartialPaginator(
$this->getPage($currentPageNumber, $maxNumItemsPerPage, $filters, $this->getOptions($filters)),
$currentPageNumber, $maxNumItemsPerPage);
}
public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []): ?object
......@@ -56,13 +65,12 @@ abstract class AbstractDataProvider extends AbstractController implements Restri
$filters = $context[self::FILTERS_KEY] ?? [];
$options = [];
LocalData::addOptions($options, $filters);
$this->locale->addLanguageOption($options);
return $this->getItemById($id, $options);
return $this->getItemById($id, $this->getOptions($filters));
}
/**
* @throws AccessDeniedException
*/
protected function onOperationStart(int $operation)
{
$this->denyAccessUnlessGranted('IS_AUTHENTICATED_FULLY');
......@@ -73,4 +81,13 @@ abstract class AbstractDataProvider extends AbstractController implements Restri
abstract protected function getItemById($id, array $options = []): object;
abstract protected function getPage(int $currentPageNumber, int $maxNumItemsPerPage, array $filters = [], array $options = []): array;
private function getOptions(array $filters): array
{
$options = [];
$options[Locale::LANGUAGE_OPTION] = $this->locale->getCurrentPrimaryLanguage();
LocalData::addOptions($options, $filters);
return $options;
}
}
......@@ -16,6 +16,8 @@ use Symfony\Component\HttpFoundation\RequestStack;
*/
class Locale
{
public const LANGUAGE_OPTION = 'lang';
/** @var RequestStack */
private $requestStack;
......
......@@ -108,3 +108,8 @@ services:
Dbp\Relay\CoreBundle\Locale\Locale:
autowire: true
autoconfigure: true
Dbp\Relay\CoreBundle\DataProvider\AbstractDataProvider:
abstract: true
calls:
- setLocale: ['@locale']