From 03fc4ed9d160742f8fe91beec0a07fa70aa190e8 Mon Sep 17 00:00:00 2001 From: Clemente Raposo Date: Wed, 14 Feb 2024 08:50:18 +0000 Subject: [PATCH] Symfony 6.4 - Refactor DataProviders into new StateProvider --- ...ovider.php => RecordListStateProvider.php} | 41 +++------ ...taProvider.php => RecordStateProvider.php} | 39 +++------ ...r.php => FieldDefinitionStateProvider.php} | 37 +++----- ...er.php => AppListStringsStateProvider.php} | 39 +++------ ...ovider.php => AppStringsStateProvider.php} | 38 +++------ ...ovider.php => ModStringsStateProvider.php} | 38 +++------ ...vider.php => AppMetadataStateProvider.php} | 39 +++------ ...er.php => ModuleMetadataStateProvider.php} | 39 +++------ ...taProvider.php => NavbarStateProvider.php} | 29 ++----- .../ProcessCollectionDataProvider.php | 68 --------------- ...aProvider.php => ProcessStateProvider.php} | 42 ++++------ ...php => BatchedStatisticsStateProvider.php} | 38 ++------- ...ovider.php => StatisticsStateProvider.php} | 38 ++------- .../SystemConfigCollectionDataProvider.php | 84 ------------------- ...ider.php => SystemConfigStateProvider.php} | 43 ++++------ ...vider.php => ThemeImagesStateProvider.php} | 38 +++------ .../UserPreferenceCollectionDataProvider.php | 83 ------------------ ...er.php => UserPreferenceStateProvider.php} | 45 ++++------ ...er.php => ViewDefinitionStateProvider.php} | 45 +++------- 19 files changed, 173 insertions(+), 690 deletions(-) rename core/backend/Data/DataProvider/{RecordListItemDataProvider.php => RecordListStateProvider.php} (64%) rename core/backend/Data/DataProvider/{RecordItemDataProvider.php => RecordStateProvider.php} (67%) rename core/backend/FieldDefinitions/DataProvider/{FieldDefinitionItemDataProvider.php => FieldDefinitionStateProvider.php} (66%) rename core/backend/Languages/DataProvider/{AppListStringsItemDataProvider.php => AppListStringsStateProvider.php} (67%) rename core/backend/Languages/DataProvider/{AppStringsItemDataProvider.php => AppStringsStateProvider.php} (65%) rename core/backend/Languages/DataProvider/{ModStringsItemDataProvider.php => ModStringsStateProvider.php} (65%) rename core/backend/Metadata/DataProvider/{AppMetadataItemDataProvider.php => AppMetadataStateProvider.php} (66%) rename core/backend/Metadata/DataProvider/{ModuleMetadataItemDataProvider.php => ModuleMetadataStateProvider.php} (66%) rename core/backend/Navbar/DataProvider/{NavbarItemDataProvider.php => NavbarStateProvider.php} (71%) delete mode 100644 core/backend/Process/DataProvider/ProcessCollectionDataProvider.php rename core/backend/Process/DataProvider/{ProcessItemDataProvider.php => ProcessStateProvider.php} (60%) rename core/backend/Statistics/DataProvider/{BatchedStatisticsItemDataProvider.php => BatchedStatisticsStateProvider.php} (66%) rename core/backend/Statistics/DataProvider/{StatisticsItemDataProvider.php => StatisticsStateProvider.php} (67%) delete mode 100644 core/backend/SystemConfig/DataProvider/SystemConfigCollectionDataProvider.php rename core/backend/SystemConfig/DataProvider/{SystemConfigItemDataProvider.php => SystemConfigStateProvider.php} (65%) rename core/backend/Themes/DataProvider/{ThemeImagesItemDataProvider.php => ThemeImagesStateProvider.php} (65%) delete mode 100644 core/backend/UserPreferences/DataProvider/UserPreferenceCollectionDataProvider.php rename core/backend/UserPreferences/DataProvider/{UserPreferenceItemDataProvider.php => UserPreferenceStateProvider.php} (67%) rename core/backend/ViewDefinitions/DataProvider/{ViewDefinitionItemDataProvider.php => ViewDefinitionStateProvider.php} (60%) diff --git a/core/backend/Data/DataProvider/RecordListItemDataProvider.php b/core/backend/Data/DataProvider/RecordListStateProvider.php similarity index 64% rename from core/backend/Data/DataProvider/RecordListItemDataProvider.php rename to core/backend/Data/DataProvider/RecordListStateProvider.php index 42177885c..66db5aa0c 100644 --- a/core/backend/Data/DataProvider/RecordListItemDataProvider.php +++ b/core/backend/Data/DataProvider/RecordListStateProvider.php @@ -27,17 +27,16 @@ namespace App\Data\DataProvider; -use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; -use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; -use App\Data\LegacyHandler\RecordListHandler; +use ApiPlatform\Metadata\Operation; +use ApiPlatform\State\ProviderInterface; use App\Data\Entity\RecordList; -use Exception; +use App\Data\LegacyHandler\RecordListHandler; /** - * Class RecordListItemDataProvider + * Class RecordListStateProvider * @package App\DataProvider */ -class RecordListItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface +class RecordListStateProvider implements ProviderInterface { /** * @var RecordListHandler @@ -45,7 +44,7 @@ class RecordListItemDataProvider implements ItemDataProviderInterface, Restricte protected $recordListHandler; /** - * RecordListItemDataProvider constructor. + * RecordListStateProvider constructor. * @param RecordListHandler $recordListHandler */ public function __construct(RecordListHandler $recordListHandler) @@ -54,31 +53,13 @@ class RecordListItemDataProvider implements ItemDataProviderInterface, Restricte } /** - * Define supported resources - * @param string $resourceClass - * @param string|null $operationName - * @param array $context - * @return bool - */ - public function supports(string $resourceClass, string $operationName = null, array $context = []): bool - { - return RecordList::class === $resourceClass; - } - - /** - * @param string $resourceClass - * @param array|int|string $id - * @param string|null $operationName + * @param Operation $operation + * @param array $uriVariables * @param array $context * @return RecordList|null - * @throws Exception */ - public function getItem( - string $resourceClass, - $id, - string $operationName = null, - array $context = [] - ): ?RecordList { - return $this->recordListHandler->getList($id); + public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?RecordList + { + return $this->recordListHandler->getList($uriVariables['id'] ?? ''); } } diff --git a/core/backend/Data/DataProvider/RecordItemDataProvider.php b/core/backend/Data/DataProvider/RecordStateProvider.php similarity index 67% rename from core/backend/Data/DataProvider/RecordItemDataProvider.php rename to core/backend/Data/DataProvider/RecordStateProvider.php index 888b2018b..4d008712b 100644 --- a/core/backend/Data/DataProvider/RecordItemDataProvider.php +++ b/core/backend/Data/DataProvider/RecordStateProvider.php @@ -28,16 +28,16 @@ namespace App\Data\DataProvider; -use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; -use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; +use ApiPlatform\Metadata\Operation; +use ApiPlatform\State\ProviderInterface; use App\Data\Entity\Record; use App\Data\Service\RecordProviderInterface; use Exception; /** - * Class RecordItemDataProvider + * Class RecordStateProvider */ -final class RecordItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface +final class RecordStateProvider implements ProviderInterface { /** * @var RecordProviderInterface @@ -45,7 +45,7 @@ final class RecordItemDataProvider implements ItemDataProviderInterface, Restric private $recordHandler; /** - * RecordViewItemDataProvider constructor. + * RecordStateProvider constructor. * @param RecordProviderInterface $recordHandler */ public function __construct(RecordProviderInterface $recordHandler) @@ -54,32 +54,15 @@ final class RecordItemDataProvider implements ItemDataProviderInterface, Restric } /** - * Defined supported resources - * @param string $resourceClass - * @param string|null $operationName - * @param array $context - * @return bool - */ - public function supports(string $resourceClass, string $operationName = null, array $context = []): bool - { - return Record::class === $resourceClass; - } - - /** - * Get get record by id - * @param string $resourceClass - * @param array|int|string $id - * @param string|null $operationName + * Get record by id + * @param Operation $operation + * @param array $uriVariables * @param array $context * @return Record|null * @throws Exception */ - public function getItem( - string $resourceClass, - $id, - string $operationName = null, - array $context = [] - ): ?Record { + public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?Record + { $module = ''; if (!empty($context['args']['module'])) { @@ -88,6 +71,6 @@ final class RecordItemDataProvider implements ItemDataProviderInterface, Restric $module = $context['filters']['module']; } - return $this->recordHandler->getRecord($module, $id); + return $this->recordHandler->getRecord($module, $uriVariables['id'] ?? ''); } } diff --git a/core/backend/FieldDefinitions/DataProvider/FieldDefinitionItemDataProvider.php b/core/backend/FieldDefinitions/DataProvider/FieldDefinitionStateProvider.php similarity index 66% rename from core/backend/FieldDefinitions/DataProvider/FieldDefinitionItemDataProvider.php rename to core/backend/FieldDefinitions/DataProvider/FieldDefinitionStateProvider.php index 24132cf4b..6046e388f 100644 --- a/core/backend/FieldDefinitions/DataProvider/FieldDefinitionItemDataProvider.php +++ b/core/backend/FieldDefinitions/DataProvider/FieldDefinitionStateProvider.php @@ -27,17 +27,17 @@ namespace App\FieldDefinitions\DataProvider; -use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; -use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; +use ApiPlatform\Metadata\Operation; +use ApiPlatform\State\ProviderInterface; use App\FieldDefinitions\Entity\FieldDefinition; use App\FieldDefinitions\LegacyHandler\FieldDefinitionsHandler; use Exception; /** - * Class FieldDefinitionItemDataProvider + * Class FieldDefinitionStateProvider * @package App\DataProvider */ -class FieldDefinitionItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface +class FieldDefinitionStateProvider implements ProviderInterface { /** * @var FieldDefinitionsHandler @@ -45,7 +45,7 @@ class FieldDefinitionItemDataProvider implements ItemDataProviderInterface, Rest protected $vardefHandler; /** - * FieldDefinitionItemDataProvider constructor. + * FieldDefinitionStateProvider constructor. * @param FieldDefinitionsHandler $vardefHandler */ public function __construct(FieldDefinitionsHandler $vardefHandler) @@ -54,31 +54,14 @@ class FieldDefinitionItemDataProvider implements ItemDataProviderInterface, Rest } /** - * Define supported resources - * @param string $resourceClass - * @param string|null $operationName - * @param array $context - * @return bool - */ - public function supports(string $resourceClass, string $operationName = null, array $context = []): bool - { - return FieldDefinition::class === $resourceClass; - } - - /** - * @param string $resourceClass - * @param array|int|string $id - * @param string|null $operationName + * @param Operation $operation + * @param array $uriVariables * @param array $context * @return FieldDefinition|null * @throws Exception */ - public function getItem( - string $resourceClass, - $id, - string $operationName = null, - array $context = [] - ): ?FieldDefinition { - return $this->vardefHandler->getVardef($id); + public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?FieldDefinition + { + return $this->vardefHandler->getVardef($uriVariables['id'] ?? ''); } } diff --git a/core/backend/Languages/DataProvider/AppListStringsItemDataProvider.php b/core/backend/Languages/DataProvider/AppListStringsStateProvider.php similarity index 67% rename from core/backend/Languages/DataProvider/AppListStringsItemDataProvider.php rename to core/backend/Languages/DataProvider/AppListStringsStateProvider.php index 84d1f6d9c..a2675928d 100644 --- a/core/backend/Languages/DataProvider/AppListStringsItemDataProvider.php +++ b/core/backend/Languages/DataProvider/AppListStringsStateProvider.php @@ -27,15 +27,15 @@ namespace App\Languages\DataProvider; -use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; -use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; +use ApiPlatform\Metadata\Operation; +use ApiPlatform\State\ProviderInterface; use App\Languages\Entity\AppListStrings; use App\Languages\LegacyHandler\AppListStringsHandler; /** - * Class AppListStringsItemDataProvider + * Class AppListStringsStateProvider */ -final class AppListStringsItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface +final class AppListStringsStateProvider implements ProviderInterface { /** * @var AppListStringsHandler @@ -43,7 +43,7 @@ final class AppListStringsItemDataProvider implements ItemDataProviderInterface, private $appListStringsHandler; /** - * AppListStringsItemDataProvider constructor. + * AppListStringsStateProvider constructor. * @param AppListStringsHandler $appListStringsHandler */ public function __construct(AppListStringsHandler $appListStringsHandler) @@ -51,34 +51,15 @@ final class AppListStringsItemDataProvider implements ItemDataProviderInterface, $this->appListStringsHandler = $appListStringsHandler; } - - /** - * Defined supported resources - * @param string $resourceClass - * @param string|null $operationName - * @param array $context - * @return bool - */ - public function supports(string $resourceClass, string $operationName = null, array $context = []): bool - { - return AppListStrings::class === $resourceClass; - } - /** * Get app list strings for given language id - * @param string $resourceClass - * @param array|int|string $id - * @param string|null $operationName + * @param Operation $operation + * @param array $uriVariables * @param array $context * @return AppListStrings|null */ - public function getItem( - string $resourceClass, - $id, - string $operationName = null, - array $context = [] - ): ?AppListStrings { - - return $this->appListStringsHandler->getAppListStrings($id); + public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?AppListStrings + { + return $this->appListStringsHandler->getAppListStrings($uriVariables['id'] ?? ''); } } diff --git a/core/backend/Languages/DataProvider/AppStringsItemDataProvider.php b/core/backend/Languages/DataProvider/AppStringsStateProvider.php similarity index 65% rename from core/backend/Languages/DataProvider/AppStringsItemDataProvider.php rename to core/backend/Languages/DataProvider/AppStringsStateProvider.php index b9adba54b..35df630f7 100644 --- a/core/backend/Languages/DataProvider/AppStringsItemDataProvider.php +++ b/core/backend/Languages/DataProvider/AppStringsStateProvider.php @@ -27,15 +27,15 @@ namespace App\Languages\DataProvider; -use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; -use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; +use ApiPlatform\Metadata\Operation; +use ApiPlatform\State\ProviderInterface; use App\Languages\Entity\AppStrings; use App\Languages\LegacyHandler\AppStringsHandler; /** - * Class AppStringsItemDataProvider + * Class AppStringsStateProvider */ -final class AppStringsItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface +final class AppStringsStateProvider implements ProviderInterface { /** @@ -44,7 +44,7 @@ final class AppStringsItemDataProvider implements ItemDataProviderInterface, Res private $appStringsHandler; /** - * AppStringsItemDataProvider constructor. + * AppStringsStateProvider constructor. * @param AppStringsHandler $appStringsHandler */ public function __construct(AppStringsHandler $appStringsHandler) @@ -52,33 +52,15 @@ final class AppStringsItemDataProvider implements ItemDataProviderInterface, Res $this->appStringsHandler = $appStringsHandler; } - /** - * Defined supported resources - * @param string $resourceClass - * @param string|null $operationName - * @param array $context - * @return bool - */ - public function supports(string $resourceClass, string $operationName = null, array $context = []): bool - { - return AppStrings::class === $resourceClass; - } - /** * Get app strings for given language id - * @param string $resourceClass - * @param array|int|string $id - * @param string|null $operationName + * @param Operation $operation + * @param array $uriVariables * @param array $context * @return AppStrings|null */ - public function getItem( - string $resourceClass, - $id, - string $operationName = null, - array $context = [] - ): ?AppStrings { - - return $this->appStringsHandler->getAppStrings($id); + public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?AppStrings + { + return $this->appStringsHandler->getAppStrings($uriVariables['id'] ?? ''); } } diff --git a/core/backend/Languages/DataProvider/ModStringsItemDataProvider.php b/core/backend/Languages/DataProvider/ModStringsStateProvider.php similarity index 65% rename from core/backend/Languages/DataProvider/ModStringsItemDataProvider.php rename to core/backend/Languages/DataProvider/ModStringsStateProvider.php index fac5b5c7e..b3ee2c562 100644 --- a/core/backend/Languages/DataProvider/ModStringsItemDataProvider.php +++ b/core/backend/Languages/DataProvider/ModStringsStateProvider.php @@ -27,15 +27,15 @@ namespace App\Languages\DataProvider; -use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; -use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; +use ApiPlatform\Metadata\Operation; +use ApiPlatform\State\ProviderInterface; use App\Languages\Entity\ModStrings; use App\Languages\LegacyHandler\ModStringsHandler; /** - * Class ModStringsItemDataProvider + * Class ModStringsStateProvider */ -final class ModStringsItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface +final class ModStringsStateProvider implements ProviderInterface { /** @@ -44,7 +44,7 @@ final class ModStringsItemDataProvider implements ItemDataProviderInterface, Res private $modStringsHandler; /** - * ModStringsItemDataProvider constructor. + * ModStringsStateProvider constructor. * @param ModStringsHandler $modStringsHandler */ public function __construct(ModStringsHandler $modStringsHandler) @@ -52,33 +52,15 @@ final class ModStringsItemDataProvider implements ItemDataProviderInterface, Res $this->modStringsHandler = $modStringsHandler; } - /** - * Defined supported resources - * @param string $resourceClass - * @param string|null $operationName - * @param array $context - * @return bool - */ - public function supports(string $resourceClass, string $operationName = null, array $context = []): bool - { - return ModStrings::class === $resourceClass; - } - /** * Get mod strings for given language id - * @param string $resourceClass - * @param array|int|string $id - * @param string|null $operationName + * @param Operation $operation + * @param array $uriVariables * @param array $context * @return ModStrings|null */ - public function getItem( - string $resourceClass, - $id, - string $operationName = null, - array $context = [] - ): ?ModStrings { - - return $this->modStringsHandler->getModStrings($id); + public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?ModStrings + { + return $this->modStringsHandler->getModStrings($uriVariables['id'] ?? ''); } } diff --git a/core/backend/Metadata/DataProvider/AppMetadataItemDataProvider.php b/core/backend/Metadata/DataProvider/AppMetadataStateProvider.php similarity index 66% rename from core/backend/Metadata/DataProvider/AppMetadataItemDataProvider.php rename to core/backend/Metadata/DataProvider/AppMetadataStateProvider.php index 4b2cf7834..bbbb0c985 100644 --- a/core/backend/Metadata/DataProvider/AppMetadataItemDataProvider.php +++ b/core/backend/Metadata/DataProvider/AppMetadataStateProvider.php @@ -27,17 +27,16 @@ namespace App\Metadata\DataProvider; -use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; -use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; +use ApiPlatform\Metadata\Operation; +use ApiPlatform\State\ProviderInterface; use App\Metadata\Entity\AppMetadata; use App\Metadata\Service\AppMetadataProviderInterface; -use Exception; /** - * Class AppMetaItemDataProvider + * Class AppMetadataStateProvider * @package App\Metatata\DataProvider */ -class AppMetadataItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface +class AppMetadataStateProvider implements ProviderInterface { /** * @var AppMetadataProviderInterface @@ -45,7 +44,7 @@ class AppMetadataItemDataProvider implements ItemDataProviderInterface, Restrict protected $metadata; /** - * AppMetaItemDataProvider constructor. + * AppMetadataStateProvider constructor. * @param AppMetadataProviderInterface $metadata */ public function __construct(AppMetadataProviderInterface $metadata) @@ -54,36 +53,18 @@ class AppMetadataItemDataProvider implements ItemDataProviderInterface, Restrict } /** - * Define supported resources - * @param string $resourceClass - * @param string|null $operationName - * @param array $context - * @return bool - */ - public function supports(string $resourceClass, string $operationName = null, array $context = []): bool - { - return AppMetadata::class === $resourceClass; - } - - /** - * @param string $resourceClass - * @param array|int|string $id - * @param string|null $operationName + * @param Operation $operation + * @param array $uriVariables * @param array $context * @return AppMetadata|null - * @throws Exception */ - public function getItem( - string $resourceClass, - $id, - string $operationName = null, - array $context = [] - ): ?AppMetadata { + public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?AppMetadata + { $attributes = []; if (!empty($context['attributes'])) { $attributes = array_keys($context['attributes']); } - return $this->metadata->getMetadata($id, $attributes); + return $this->metadata->getMetadata($uriVariables['id'] ?? '', $attributes); } } diff --git a/core/backend/Metadata/DataProvider/ModuleMetadataItemDataProvider.php b/core/backend/Metadata/DataProvider/ModuleMetadataStateProvider.php similarity index 66% rename from core/backend/Metadata/DataProvider/ModuleMetadataItemDataProvider.php rename to core/backend/Metadata/DataProvider/ModuleMetadataStateProvider.php index 8fbd7d6c6..c3e10ff55 100644 --- a/core/backend/Metadata/DataProvider/ModuleMetadataItemDataProvider.php +++ b/core/backend/Metadata/DataProvider/ModuleMetadataStateProvider.php @@ -27,17 +27,16 @@ namespace App\Metadata\DataProvider; -use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; -use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; +use ApiPlatform\Metadata\Operation; +use ApiPlatform\State\ProviderInterface; use App\Metadata\Entity\ModuleMetadata; use App\Metadata\Service\ModuleMetadataProviderInterface; -use Exception; /** - * Class ModuleMetaItemDataProvider + * Class ModuleMetadataStateProvider * @package App\Metatata\DataProvider */ -class ModuleMetadataItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface +class ModuleMetadataStateProvider implements ProviderInterface { /** * @var ModuleMetadataProviderInterface @@ -45,7 +44,7 @@ class ModuleMetadataItemDataProvider implements ItemDataProviderInterface, Restr protected $metadata; /** - * ModuleMetaItemDataProvider constructor. + * ModuleMetadataStateProvider constructor. * @param ModuleMetadataProviderInterface $metadata */ public function __construct(ModuleMetadataProviderInterface $metadata) @@ -54,36 +53,18 @@ class ModuleMetadataItemDataProvider implements ItemDataProviderInterface, Restr } /** - * Define supported resources - * @param string $resourceClass - * @param string|null $operationName - * @param array $context - * @return bool - */ - public function supports(string $resourceClass, string $operationName = null, array $context = []): bool - { - return ModuleMetadata::class === $resourceClass; - } - - /** - * @param string $resourceClass - * @param array|int|string $id - * @param string|null $operationName + * @param Operation $operation + * @param array $uriVariables * @param array $context * @return ModuleMetadata|null - * @throws Exception */ - public function getItem( - string $resourceClass, - $id, - string $operationName = null, - array $context = [] - ): ?ModuleMetadata { + public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?ModuleMetadata + { $attributes = []; if (!empty($context['attributes'])) { $attributes = array_keys($context['attributes']); } - return $this->metadata->getMetadata($id, $attributes); + return $this->metadata->getMetadata($uriVariables['id'] ?? '', $attributes); } } diff --git a/core/backend/Navbar/DataProvider/NavbarItemDataProvider.php b/core/backend/Navbar/DataProvider/NavbarStateProvider.php similarity index 71% rename from core/backend/Navbar/DataProvider/NavbarItemDataProvider.php rename to core/backend/Navbar/DataProvider/NavbarStateProvider.php index c55de0ed5..e1a2d729f 100644 --- a/core/backend/Navbar/DataProvider/NavbarItemDataProvider.php +++ b/core/backend/Navbar/DataProvider/NavbarStateProvider.php @@ -28,13 +28,13 @@ namespace App\Navbar\DataProvider; -use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; -use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; +use ApiPlatform\Metadata\Operation; +use ApiPlatform\State\ProviderInterface; use App\Navbar\Entity\Navbar; use App\Routes\Service\NavigationProviderInterface; -use Symfony\Component\Security\Core\Security; +use Symfony\Bundle\SecurityBundle\Security; -final class NavbarItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface +final class NavbarStateProvider implements ProviderInterface { /** * @var NavigationProviderInterface @@ -47,7 +47,7 @@ final class NavbarItemDataProvider implements ItemDataProviderInterface, Restric private $security; /** - * NavbarItemDataProvider constructor. + * NavbarStateProvider constructor. * @param NavigationProviderInterface $navigationService * @param Security $security */ @@ -57,27 +57,14 @@ final class NavbarItemDataProvider implements ItemDataProviderInterface, Restric $this->security = $security; } - /** - * Define supported resources - * @param string $resourceClass - * @param string|null $operationName - * @param array $context - * @return bool - */ - public function supports(string $resourceClass, string $operationName = null, array $context = []): bool - { - return Navbar::class === $resourceClass; - } - /** * Get navbar - * @param string $resourceClass - * @param array|int|string $id - * @param string|null $operationName + * @param Operation $operation + * @param array $uriVariables * @param array $context * @return Navbar|null */ - public function getItem(string $resourceClass, $id, string $operationName = null, array $context = []): ?Navbar + public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?Navbar { $navbar = $this->navigationService->getNavbar(); $user = $this->security->getUser(); diff --git a/core/backend/Process/DataProvider/ProcessCollectionDataProvider.php b/core/backend/Process/DataProvider/ProcessCollectionDataProvider.php deleted file mode 100644 index e3de108d0..000000000 --- a/core/backend/Process/DataProvider/ProcessCollectionDataProvider.php +++ /dev/null @@ -1,68 +0,0 @@ -. - * - * In accordance with Section 7(b) of the GNU Affero General Public License - * version 3, these Appropriate Legal Notices must retain the display of the - * "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably - * feasible for technical reasons, the Appropriate Legal Notices must display - * the words "Supercharged by SuiteCRM". - */ - - -namespace App\Process\DataProvider; - - -use ApiPlatform\Core\DataProvider\ArrayPaginator; -use ApiPlatform\Core\DataProvider\ContextAwareCollectionDataProviderInterface; -use ApiPlatform\Core\DataProvider\PaginatorInterface; -use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; -use App\Process\Entity\Process; - -class ProcessCollectionDataProvider implements ContextAwareCollectionDataProviderInterface, RestrictedDataProviderInterface -{ - - /** - * Define supported Resource Classes - * @param string $resourceClass - * @param string|null $operationName - * @param array $context - * @return bool - */ - public function supports(string $resourceClass, string $operationName = null, array $context = []): bool - { - return Process::class === $resourceClass; - } - - - /** - * {@inheritdoc} - */ - public function getCollection( - string $resourceClass, - string $operationName = null, - array $context = [] - ): PaginatorInterface { - - //Async processes not implemented yet - $processes = []; - - return new ArrayPaginator($processes, 0, count($processes)); - } -} diff --git a/core/backend/Process/DataProvider/ProcessItemDataProvider.php b/core/backend/Process/DataProvider/ProcessStateProvider.php similarity index 60% rename from core/backend/Process/DataProvider/ProcessItemDataProvider.php rename to core/backend/Process/DataProvider/ProcessStateProvider.php index 71d717c1f..9435e9d85 100644 --- a/core/backend/Process/DataProvider/ProcessItemDataProvider.php +++ b/core/backend/Process/DataProvider/ProcessStateProvider.php @@ -27,40 +27,26 @@ namespace App\Process\DataProvider; -use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; -use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; -use ApiPlatform\Core\Exception\ItemNotFoundException; +use ApiPlatform\Metadata\CollectionOperationInterface; +use ApiPlatform\Metadata\Operation; +use ApiPlatform\State\ProviderInterface; use App\Process\Entity\Process; -class ProcessItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface +class ProcessStateProvider implements ProviderInterface { - /** - * Defined supported resources - * @param string $resourceClass - * @param string|null $operationName - * @param array $context - * @return bool - */ - public function supports(string $resourceClass, string $operationName = null, array $context = []): bool - { - return Process::class === $resourceClass; - } - /** * Get Process - * @param string $resourceClass - * @param array|int|string $id - * @param string|null $operationName + * @param Operation $operation + * @param array $uriVariables * @param array $context - * @return Process|null + * @return array|Process|null */ - public function getItem( - string $resourceClass, - $id, - string $operationName = null, - array $context = [] - ): ?Process { - //Async processes not implemented yet - throw new ItemNotFoundException(); + public function provide(Operation $operation, array $uriVariables = [], array $context = []): array|Process|null + { + if ($operation instanceof CollectionOperationInterface) { + return []; + } + + return null; } } diff --git a/core/backend/Statistics/DataProvider/BatchedStatisticsItemDataProvider.php b/core/backend/Statistics/DataProvider/BatchedStatisticsStateProvider.php similarity index 66% rename from core/backend/Statistics/DataProvider/BatchedStatisticsItemDataProvider.php rename to core/backend/Statistics/DataProvider/BatchedStatisticsStateProvider.php index 7643ec7e5..7f7901878 100644 --- a/core/backend/Statistics/DataProvider/BatchedStatisticsItemDataProvider.php +++ b/core/backend/Statistics/DataProvider/BatchedStatisticsStateProvider.php @@ -27,12 +27,12 @@ namespace App\Statistics\DataProvider; -use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; -use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; +use ApiPlatform\Metadata\Operation; +use ApiPlatform\State\ProviderInterface; use App\Statistics\Entity\BatchedStatistics; use App\Statistics\Service\StatisticsManagerInterface; -class BatchedStatisticsItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface +class BatchedStatisticsStateProvider implements ProviderInterface { /** * @var StatisticsManagerInterface @@ -40,7 +40,7 @@ class BatchedStatisticsItemDataProvider implements ItemDataProviderInterface, Re private $manager; /** - * BatchedStatisticsItemDataProvider constructor. + * BatchedStatisticsStateProvider constructor. * @param StatisticsManagerInterface $manager */ public function __construct(StatisticsManagerInterface $manager) @@ -48,37 +48,15 @@ class BatchedStatisticsItemDataProvider implements ItemDataProviderInterface, Re $this->manager = $manager; } - - /** - * Defined supported resources - * @param string $resourceClass - * @param string|null $operationName - * @param array $context - * @return bool - */ - public function supports( - string $resourceClass, - string $operationName = null, - array $context = [] - ): bool { - return BatchedStatistics::class === $resourceClass; - } - /** * Get batched statistics - * @param string $resourceClass - * @param array|int|string $id - * @param string|null $operationName + * @param Operation $operation + * @param array $uriVariables * @param array $context * @return BatchedStatistics|null */ - public function getItem( - string $resourceClass, - $id, - string $operationName = null, - array $context = [] - ): ?BatchedStatistics { - + public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?BatchedStatistics + { return null; } } diff --git a/core/backend/Statistics/DataProvider/StatisticsItemDataProvider.php b/core/backend/Statistics/DataProvider/StatisticsStateProvider.php similarity index 67% rename from core/backend/Statistics/DataProvider/StatisticsItemDataProvider.php rename to core/backend/Statistics/DataProvider/StatisticsStateProvider.php index 2afef735f..a1ee010e7 100644 --- a/core/backend/Statistics/DataProvider/StatisticsItemDataProvider.php +++ b/core/backend/Statistics/DataProvider/StatisticsStateProvider.php @@ -27,12 +27,12 @@ namespace App\Statistics\DataProvider; -use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; -use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; +use ApiPlatform\Metadata\Operation; +use ApiPlatform\State\ProviderInterface; use App\Statistics\Entity\Statistic; use App\Statistics\Service\StatisticsProviderRegistry; -class StatisticsItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface +class StatisticsStateProvider implements ProviderInterface { /** * @var StatisticsProviderRegistry @@ -40,7 +40,7 @@ class StatisticsItemDataProvider implements ItemDataProviderInterface, Restricte private $registry; /** - * StatisticsItemDataProvider constructor. + * StatisticsStateProvider constructor. * @param StatisticsProviderRegistry $registry */ public function __construct(StatisticsProviderRegistry $registry) @@ -48,37 +48,15 @@ class StatisticsItemDataProvider implements ItemDataProviderInterface, Restricte $this->registry = $registry; } - - /** - * Defined supported resources - * @param string $resourceClass - * @param string|null $operationName - * @param array $context - * @return bool - */ - public - function supports( - string $resourceClass, - string $operationName = null, - array $context = [] - ): bool { - return Statistic::class === $resourceClass; - } - /** * Get chart data for given chart id - * @param string $resourceClass - * @param array|int|string $id - * @param string|null $operationName + * @param Operation $operation + * @param array $uriVariables * @param array $context * @return Statistic|null */ - public function getItem( - string $resourceClass, - $id, - string $operationName = null, - array $context = [] - ): ?Statistic { + public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?Statistic + { return null; } } diff --git a/core/backend/SystemConfig/DataProvider/SystemConfigCollectionDataProvider.php b/core/backend/SystemConfig/DataProvider/SystemConfigCollectionDataProvider.php deleted file mode 100644 index 62bf422a4..000000000 --- a/core/backend/SystemConfig/DataProvider/SystemConfigCollectionDataProvider.php +++ /dev/null @@ -1,84 +0,0 @@ -. - * - * In accordance with Section 7(b) of the GNU Affero General Public License - * version 3, these Appropriate Legal Notices must retain the display of the - * "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably - * feasible for technical reasons, the Appropriate Legal Notices must display - * the words "Supercharged by SuiteCRM". - */ - - -namespace App\SystemConfig\DataProvider; - -use ApiPlatform\Core\DataProvider\ArrayPaginator; -use ApiPlatform\Core\DataProvider\ContextAwareCollectionDataProviderInterface; -use ApiPlatform\Core\DataProvider\PaginatorInterface; -use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; -use App\SystemConfig\Entity\SystemConfig; -use App\SystemConfig\Service\SystemConfigProviderInterface; - -/** - * Class SystemConfigCollectionDataProvider - */ -class SystemConfigCollectionDataProvider implements ContextAwareCollectionDataProviderInterface, - RestrictedDataProviderInterface -{ - - /** - * @var SystemConfigProviderInterface - */ - private $systemConfigProvider; - - /** - * SystemConfigCollectionDataProvider constructor. - * @param SystemConfigProviderInterface $systemConfigProvider - */ - public function __construct(SystemConfigProviderInterface $systemConfigProvider) - { - $this->systemConfigProvider = $systemConfigProvider; - } - - /** - * Define supported Resource Classes - * @param string $resourceClass - * @param string|null $operationName - * @param array $context - * @return bool - */ - public function supports(string $resourceClass, string $operationName = null, array $context = []): bool - { - return SystemConfig::class === $resourceClass; - } - - - /** - * {@inheritdoc} - */ - public function getCollection( - string $resourceClass, - string $operationName = null, - array $context = [] - ): PaginatorInterface { - $systemConfigs = $this->systemConfigProvider->getAllSystemConfigs(); - - return new ArrayPaginator($systemConfigs, 0, count($systemConfigs)); - } -} diff --git a/core/backend/SystemConfig/DataProvider/SystemConfigItemDataProvider.php b/core/backend/SystemConfig/DataProvider/SystemConfigStateProvider.php similarity index 65% rename from core/backend/SystemConfig/DataProvider/SystemConfigItemDataProvider.php rename to core/backend/SystemConfig/DataProvider/SystemConfigStateProvider.php index 63324eb34..4f558f0df 100644 --- a/core/backend/SystemConfig/DataProvider/SystemConfigItemDataProvider.php +++ b/core/backend/SystemConfig/DataProvider/SystemConfigStateProvider.php @@ -27,15 +27,16 @@ namespace App\SystemConfig\DataProvider; -use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; -use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; +use ApiPlatform\Metadata\CollectionOperationInterface; +use ApiPlatform\Metadata\Operation; +use ApiPlatform\State\ProviderInterface; use App\SystemConfig\Entity\SystemConfig; use App\SystemConfig\Service\SystemConfigProviderInterface; /** - * Class SystemConfigItemDataProvider + * Class SystemConfigStateProvider */ -final class SystemConfigItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface +final class SystemConfigStateProvider implements ProviderInterface { /** @@ -44,7 +45,7 @@ final class SystemConfigItemDataProvider implements ItemDataProviderInterface, R private $systemConfigProvider; /** - * SystemConfigItemDataProvider constructor. + * SystemConfigStateProvider constructor. * @param SystemConfigProviderInterface $systemConfigProvider */ public function __construct(SystemConfigProviderInterface $systemConfigProvider) @@ -52,33 +53,19 @@ final class SystemConfigItemDataProvider implements ItemDataProviderInterface, R $this->systemConfigProvider = $systemConfigProvider; } - /** - * Defined supported resources - * @param string $resourceClass - * @param string|null $operationName - * @param array $context - * @return bool - */ - public function supports(string $resourceClass, string $operationName = null, array $context = []): bool - { - return SystemConfig::class === $resourceClass; - } - /** * Get system config - * @param string $resourceClass - * @param array|int|string $id - * @param string|null $operationName + * @param Operation $operation + * @param array $uriVariables * @param array $context - * @return SystemConfig|null + * @return array|SystemConfig|null */ - public function getItem( - string $resourceClass, - $id, - string $operationName = null, - array $context = [] - ): ?SystemConfig { + public function provide(Operation $operation, array $uriVariables = [], array $context = []): array|SystemConfig|null + { + if ($operation instanceof CollectionOperationInterface) { + return $this->systemConfigProvider->getAllSystemConfigs(); + } - return $this->systemConfigProvider->getSystemConfig($id); + return $this->systemConfigProvider->getSystemConfig($uriVariables['id'] ?? ''); } } diff --git a/core/backend/Themes/DataProvider/ThemeImagesItemDataProvider.php b/core/backend/Themes/DataProvider/ThemeImagesStateProvider.php similarity index 65% rename from core/backend/Themes/DataProvider/ThemeImagesItemDataProvider.php rename to core/backend/Themes/DataProvider/ThemeImagesStateProvider.php index 6e82579b1..44e02b6fe 100644 --- a/core/backend/Themes/DataProvider/ThemeImagesItemDataProvider.php +++ b/core/backend/Themes/DataProvider/ThemeImagesStateProvider.php @@ -27,15 +27,15 @@ namespace App\Themes\DataProvider; -use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; -use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; +use ApiPlatform\Metadata\Operation; +use ApiPlatform\State\ProviderInterface; use App\Themes\Entity\ThemeImages; use App\Themes\Service\ThemeImageService; /** - * Class ThemeImagesItemDataProvider + * Class ThemeImagesStateProvider */ -final class ThemeImagesItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface +final class ThemeImagesStateProvider implements ProviderInterface { /** * @var ThemeImageService @@ -44,7 +44,7 @@ final class ThemeImagesItemDataProvider implements ItemDataProviderInterface, Re /** - * ThemeImagesItemDataProvider constructor. + * ThemeImagesStateProvider constructor. * @param ThemeImageService $themeImageService */ public function __construct(ThemeImageService $themeImageService) @@ -52,33 +52,15 @@ final class ThemeImagesItemDataProvider implements ItemDataProviderInterface, Re $this->themeImageService = $themeImageService; } - /** - * Defined supported resources - * @param string $resourceClass - * @param string|null $operationName - * @param array $context - * @return bool - */ - public function supports(string $resourceClass, string $operationName = null, array $context = []): bool - { - return ThemeImages::class === $resourceClass; - } - /** * Get theme image information for given theme - * @param string $resourceClass - * @param array|int|string $id - * @param string|null $operationName + * @param Operation $operation + * @param array $uriVariables * @param array $context * @return ThemeImages|null */ - public function getItem( - string $resourceClass, - $id, - string $operationName = null, - array $context = [] - ): ?ThemeImages { - - return $this->themeImageService->get($id); + public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?ThemeImages + { + return $this->themeImageService->get($uriVariables['id'] ?? ''); } } diff --git a/core/backend/UserPreferences/DataProvider/UserPreferenceCollectionDataProvider.php b/core/backend/UserPreferences/DataProvider/UserPreferenceCollectionDataProvider.php deleted file mode 100644 index 3c9f4c469..000000000 --- a/core/backend/UserPreferences/DataProvider/UserPreferenceCollectionDataProvider.php +++ /dev/null @@ -1,83 +0,0 @@ -. - * - * In accordance with Section 7(b) of the GNU Affero General Public License - * version 3, these Appropriate Legal Notices must retain the display of the - * "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably - * feasible for technical reasons, the Appropriate Legal Notices must display - * the words "Supercharged by SuiteCRM". - */ - -namespace App\UserPreferences\DataProvider; - -use ApiPlatform\Core\DataProvider\ArrayPaginator; -use ApiPlatform\Core\DataProvider\ContextAwareCollectionDataProviderInterface; -use ApiPlatform\Core\DataProvider\PaginatorInterface; -use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; -use App\UserPreferences\Entity\UserPreference; -use App\UserPreferences\Service\UserPreferencesProviderInterface; - -/** - * Class UserPreferenceCollectionDataProvider - */ -class UserPreferenceCollectionDataProvider implements ContextAwareCollectionDataProviderInterface, - RestrictedDataProviderInterface -{ - - /** - * @var UserPreferencesProviderInterface - */ - private $userPreferencesService; - - /** - * UserPreferenceCollectionDataProvider constructor. - * @param UserPreferencesProviderInterface $userPreferenceService - */ - public function __construct(UserPreferencesProviderInterface $userPreferenceService) - { - $this->userPreferencesService = $userPreferenceService; - } - - /** - * Define supported Resource Classes - * @param string $resourceClass - * @param string|null $operationName - * @param array $context - * @return bool - */ - public function supports(string $resourceClass, string $operationName = null, array $context = []): bool - { - return UserPreference::class === $resourceClass; - } - - - /** - * {@inheritdoc} - */ - public function getCollection( - string $resourceClass, - string $operationName = null, - array $context = [] - ): PaginatorInterface { - $userPreferences = $this->userPreferencesService->getAllUserPreferences(); - - return new ArrayPaginator($userPreferences, 0, count($userPreferences)); - } -} diff --git a/core/backend/UserPreferences/DataProvider/UserPreferenceItemDataProvider.php b/core/backend/UserPreferences/DataProvider/UserPreferenceStateProvider.php similarity index 67% rename from core/backend/UserPreferences/DataProvider/UserPreferenceItemDataProvider.php rename to core/backend/UserPreferences/DataProvider/UserPreferenceStateProvider.php index fc3177acf..7254fb849 100644 --- a/core/backend/UserPreferences/DataProvider/UserPreferenceItemDataProvider.php +++ b/core/backend/UserPreferences/DataProvider/UserPreferenceStateProvider.php @@ -24,17 +24,19 @@ * feasible for technical reasons, the Appropriate Legal Notices must display * the words "Supercharged by SuiteCRM". */ + namespace App\UserPreferences\DataProvider; -use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; -use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; +use ApiPlatform\Metadata\CollectionOperationInterface; +use ApiPlatform\Metadata\Operation; +use ApiPlatform\State\ProviderInterface; use App\UserPreferences\Entity\UserPreference; use App\UserPreferences\Service\UserPreferencesProviderInterface; /** - * Class UserPreferenceItemDataProvider + * Class UserPreferenceProvider */ -final class UserPreferenceItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface +final class UserPreferenceStateProvider implements ProviderInterface { /** @@ -43,7 +45,7 @@ final class UserPreferenceItemDataProvider implements ItemDataProviderInterface, private $userPreferenceService; /** - * UserPreferenceItemDataProvider constructor. + * UserPreferenceStateProvider constructor. * @param UserPreferencesProviderInterface $userPreferenceService */ public function __construct(UserPreferencesProviderInterface $userPreferenceService) @@ -51,32 +53,19 @@ final class UserPreferenceItemDataProvider implements ItemDataProviderInterface, $this->userPreferenceService = $userPreferenceService; } - /** - * Defined supported resources - * @param string $resourceClass - * @param string|null $operationName - * @param array $context - * @return bool - */ - public function supports(string $resourceClass, string $operationName = null, array $context = []): bool - { - return UserPreference::class === $resourceClass; - } - /** * Get user preference - * @param string $resourceClass - * @param array|int|string $id - * @param string|null $operationName + * @param Operation $operation + * @param array $uriVariables * @param array $context - * @return UserPreference|null + * @return iterable|UserPreference|null */ - public function getItem( - string $resourceClass, - $id, - string $operationName = null, - array $context = [] - ): ?UserPreference { - return $this->userPreferenceService->getUserPreference($id); + public function provide(Operation $operation, array $uriVariables = [], array $context = []): array|UserPreference|null + { + if ($operation instanceof CollectionOperationInterface) { + return $this->userPreferenceService->getAllUserPreferences(); + } + + return $this->userPreferenceService->getUserPreference($uriVariables['id'] ?? ''); } } diff --git a/core/backend/ViewDefinitions/DataProvider/ViewDefinitionItemDataProvider.php b/core/backend/ViewDefinitions/DataProvider/ViewDefinitionStateProvider.php similarity index 60% rename from core/backend/ViewDefinitions/DataProvider/ViewDefinitionItemDataProvider.php rename to core/backend/ViewDefinitions/DataProvider/ViewDefinitionStateProvider.php index b541b2d00..be4166133 100644 --- a/core/backend/ViewDefinitions/DataProvider/ViewDefinitionItemDataProvider.php +++ b/core/backend/ViewDefinitions/DataProvider/ViewDefinitionStateProvider.php @@ -27,64 +27,41 @@ namespace App\ViewDefinitions\DataProvider; -use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; -use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; +use ApiPlatform\Metadata\Operation; +use ApiPlatform\State\ProviderInterface; use App\ViewDefinitions\Entity\ViewDefinition; use App\ViewDefinitions\Service\ViewDefinitionsProviderInterface; use Exception; /** - * Class ViewDefinitionItemDataProvider + * Class ViewDefinitionProvider * @package App\DataProvider */ -class ViewDefinitionItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface +class ViewDefinitionStateProvider implements ProviderInterface { - /** - * @var ViewDefinitionsProviderInterface - */ - protected $viewDefHandler; /** - * ViewDefinitionItemDataProvider constructor. + * ViewDefinitionProvider constructor. * @param ViewDefinitionsProviderInterface $viewDefHandler */ - public function __construct(ViewDefinitionsProviderInterface $viewDefHandler) + public function __construct(protected readonly ViewDefinitionsProviderInterface $viewDefHandler) { - $this->viewDefHandler = $viewDefHandler; } /** - * Define supported resources - * @param string $resourceClass - * @param string|null $operationName - * @param array $context - * @return bool - */ - public function supports(string $resourceClass, string $operationName = null, array $context = []): bool - { - return ViewDefinition::class === $resourceClass; - } - - /** - * @param string $resourceClass - * @param array|int|string $id - * @param string|null $operationName + * @param Operation $operation + * @param array $uriVariables * @param array $context * @return ViewDefinition|null * @throws Exception */ - public function getItem( - string $resourceClass, - $id, - string $operationName = null, - array $context = [] - ): ?ViewDefinition { - + public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?ViewDefinition + { $attributes = []; if (!empty($context['attributes'])) { $attributes = array_keys($context['attributes']); } - return $this->viewDefHandler->getViewDefs($id, $attributes); + return $this->viewDefHandler->getViewDefs($uriVariables['id'] ?? '', $attributes); } }