Symfony 6.4 - Refactor DataProviders into new StateProvider

This commit is contained in:
Clemente Raposo 2024-02-14 08:50:18 +00:00
parent 5e2a39c089
commit 03fc4ed9d1
19 changed files with 173 additions and 690 deletions

View file

@ -27,17 +27,16 @@
namespace App\Data\DataProvider; namespace App\Data\DataProvider;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Metadata\Operation;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use ApiPlatform\State\ProviderInterface;
use App\Data\LegacyHandler\RecordListHandler;
use App\Data\Entity\RecordList; use App\Data\Entity\RecordList;
use Exception; use App\Data\LegacyHandler\RecordListHandler;
/** /**
* Class RecordListItemDataProvider * Class RecordListStateProvider
* @package App\DataProvider * @package App\DataProvider
*/ */
class RecordListItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface class RecordListStateProvider implements ProviderInterface
{ {
/** /**
* @var RecordListHandler * @var RecordListHandler
@ -45,7 +44,7 @@ class RecordListItemDataProvider implements ItemDataProviderInterface, Restricte
protected $recordListHandler; protected $recordListHandler;
/** /**
* RecordListItemDataProvider constructor. * RecordListStateProvider constructor.
* @param RecordListHandler $recordListHandler * @param RecordListHandler $recordListHandler
*/ */
public function __construct(RecordListHandler $recordListHandler) public function __construct(RecordListHandler $recordListHandler)
@ -54,31 +53,13 @@ class RecordListItemDataProvider implements ItemDataProviderInterface, Restricte
} }
/** /**
* Define supported resources * @param Operation $operation
* @param string $resourceClass * @param array $uriVariables
* @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 array $context * @param array $context
* @return RecordList|null * @return RecordList|null
* @throws Exception
*/ */
public function getItem( public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?RecordList
string $resourceClass, {
$id, return $this->recordListHandler->getList($uriVariables['id'] ?? '');
string $operationName = null,
array $context = []
): ?RecordList {
return $this->recordListHandler->getList($id);
} }
} }

View file

@ -28,16 +28,16 @@
namespace App\Data\DataProvider; namespace App\Data\DataProvider;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Metadata\Operation;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use ApiPlatform\State\ProviderInterface;
use App\Data\Entity\Record; use App\Data\Entity\Record;
use App\Data\Service\RecordProviderInterface; use App\Data\Service\RecordProviderInterface;
use Exception; use Exception;
/** /**
* Class RecordItemDataProvider * Class RecordStateProvider
*/ */
final class RecordItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface final class RecordStateProvider implements ProviderInterface
{ {
/** /**
* @var RecordProviderInterface * @var RecordProviderInterface
@ -45,7 +45,7 @@ final class RecordItemDataProvider implements ItemDataProviderInterface, Restric
private $recordHandler; private $recordHandler;
/** /**
* RecordViewItemDataProvider constructor. * RecordStateProvider constructor.
* @param RecordProviderInterface $recordHandler * @param RecordProviderInterface $recordHandler
*/ */
public function __construct(RecordProviderInterface $recordHandler) public function __construct(RecordProviderInterface $recordHandler)
@ -54,32 +54,15 @@ final class RecordItemDataProvider implements ItemDataProviderInterface, Restric
} }
/** /**
* Defined supported resources * Get record by id
* @param string $resourceClass * @param Operation $operation
* @param string|null $operationName * @param array $uriVariables
* @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
* @param array $context * @param array $context
* @return Record|null * @return Record|null
* @throws Exception * @throws Exception
*/ */
public function getItem( public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?Record
string $resourceClass, {
$id,
string $operationName = null,
array $context = []
): ?Record {
$module = ''; $module = '';
if (!empty($context['args']['module'])) { if (!empty($context['args']['module'])) {
@ -88,6 +71,6 @@ final class RecordItemDataProvider implements ItemDataProviderInterface, Restric
$module = $context['filters']['module']; $module = $context['filters']['module'];
} }
return $this->recordHandler->getRecord($module, $id); return $this->recordHandler->getRecord($module, $uriVariables['id'] ?? '');
} }
} }

View file

@ -27,17 +27,17 @@
namespace App\FieldDefinitions\DataProvider; namespace App\FieldDefinitions\DataProvider;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Metadata\Operation;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use ApiPlatform\State\ProviderInterface;
use App\FieldDefinitions\Entity\FieldDefinition; use App\FieldDefinitions\Entity\FieldDefinition;
use App\FieldDefinitions\LegacyHandler\FieldDefinitionsHandler; use App\FieldDefinitions\LegacyHandler\FieldDefinitionsHandler;
use Exception; use Exception;
/** /**
* Class FieldDefinitionItemDataProvider * Class FieldDefinitionStateProvider
* @package App\DataProvider * @package App\DataProvider
*/ */
class FieldDefinitionItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface class FieldDefinitionStateProvider implements ProviderInterface
{ {
/** /**
* @var FieldDefinitionsHandler * @var FieldDefinitionsHandler
@ -45,7 +45,7 @@ class FieldDefinitionItemDataProvider implements ItemDataProviderInterface, Rest
protected $vardefHandler; protected $vardefHandler;
/** /**
* FieldDefinitionItemDataProvider constructor. * FieldDefinitionStateProvider constructor.
* @param FieldDefinitionsHandler $vardefHandler * @param FieldDefinitionsHandler $vardefHandler
*/ */
public function __construct(FieldDefinitionsHandler $vardefHandler) public function __construct(FieldDefinitionsHandler $vardefHandler)
@ -54,31 +54,14 @@ class FieldDefinitionItemDataProvider implements ItemDataProviderInterface, Rest
} }
/** /**
* Define supported resources * @param Operation $operation
* @param string $resourceClass * @param array $uriVariables
* @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 array $context * @param array $context
* @return FieldDefinition|null * @return FieldDefinition|null
* @throws Exception * @throws Exception
*/ */
public function getItem( public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?FieldDefinition
string $resourceClass, {
$id, return $this->vardefHandler->getVardef($uriVariables['id'] ?? '');
string $operationName = null,
array $context = []
): ?FieldDefinition {
return $this->vardefHandler->getVardef($id);
} }
} }

View file

@ -27,15 +27,15 @@
namespace App\Languages\DataProvider; namespace App\Languages\DataProvider;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Metadata\Operation;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use ApiPlatform\State\ProviderInterface;
use App\Languages\Entity\AppListStrings; use App\Languages\Entity\AppListStrings;
use App\Languages\LegacyHandler\AppListStringsHandler; use App\Languages\LegacyHandler\AppListStringsHandler;
/** /**
* Class AppListStringsItemDataProvider * Class AppListStringsStateProvider
*/ */
final class AppListStringsItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface final class AppListStringsStateProvider implements ProviderInterface
{ {
/** /**
* @var AppListStringsHandler * @var AppListStringsHandler
@ -43,7 +43,7 @@ final class AppListStringsItemDataProvider implements ItemDataProviderInterface,
private $appListStringsHandler; private $appListStringsHandler;
/** /**
* AppListStringsItemDataProvider constructor. * AppListStringsStateProvider constructor.
* @param AppListStringsHandler $appListStringsHandler * @param AppListStringsHandler $appListStringsHandler
*/ */
public function __construct(AppListStringsHandler $appListStringsHandler) public function __construct(AppListStringsHandler $appListStringsHandler)
@ -51,34 +51,15 @@ final class AppListStringsItemDataProvider implements ItemDataProviderInterface,
$this->appListStringsHandler = $appListStringsHandler; $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 * Get app list strings for given language id
* @param string $resourceClass * @param Operation $operation
* @param array|int|string $id * @param array $uriVariables
* @param string|null $operationName
* @param array $context * @param array $context
* @return AppListStrings|null * @return AppListStrings|null
*/ */
public function getItem( public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?AppListStrings
string $resourceClass, {
$id, return $this->appListStringsHandler->getAppListStrings($uriVariables['id'] ?? '');
string $operationName = null,
array $context = []
): ?AppListStrings {
return $this->appListStringsHandler->getAppListStrings($id);
} }
} }

View file

@ -27,15 +27,15 @@
namespace App\Languages\DataProvider; namespace App\Languages\DataProvider;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Metadata\Operation;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use ApiPlatform\State\ProviderInterface;
use App\Languages\Entity\AppStrings; use App\Languages\Entity\AppStrings;
use App\Languages\LegacyHandler\AppStringsHandler; 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; private $appStringsHandler;
/** /**
* AppStringsItemDataProvider constructor. * AppStringsStateProvider constructor.
* @param AppStringsHandler $appStringsHandler * @param AppStringsHandler $appStringsHandler
*/ */
public function __construct(AppStringsHandler $appStringsHandler) public function __construct(AppStringsHandler $appStringsHandler)
@ -52,33 +52,15 @@ final class AppStringsItemDataProvider implements ItemDataProviderInterface, Res
$this->appStringsHandler = $appStringsHandler; $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 * Get app strings for given language id
* @param string $resourceClass * @param Operation $operation
* @param array|int|string $id * @param array $uriVariables
* @param string|null $operationName
* @param array $context * @param array $context
* @return AppStrings|null * @return AppStrings|null
*/ */
public function getItem( public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?AppStrings
string $resourceClass, {
$id, return $this->appStringsHandler->getAppStrings($uriVariables['id'] ?? '');
string $operationName = null,
array $context = []
): ?AppStrings {
return $this->appStringsHandler->getAppStrings($id);
} }
} }

View file

@ -27,15 +27,15 @@
namespace App\Languages\DataProvider; namespace App\Languages\DataProvider;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Metadata\Operation;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use ApiPlatform\State\ProviderInterface;
use App\Languages\Entity\ModStrings; use App\Languages\Entity\ModStrings;
use App\Languages\LegacyHandler\ModStringsHandler; 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; private $modStringsHandler;
/** /**
* ModStringsItemDataProvider constructor. * ModStringsStateProvider constructor.
* @param ModStringsHandler $modStringsHandler * @param ModStringsHandler $modStringsHandler
*/ */
public function __construct(ModStringsHandler $modStringsHandler) public function __construct(ModStringsHandler $modStringsHandler)
@ -52,33 +52,15 @@ final class ModStringsItemDataProvider implements ItemDataProviderInterface, Res
$this->modStringsHandler = $modStringsHandler; $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 * Get mod strings for given language id
* @param string $resourceClass * @param Operation $operation
* @param array|int|string $id * @param array $uriVariables
* @param string|null $operationName
* @param array $context * @param array $context
* @return ModStrings|null * @return ModStrings|null
*/ */
public function getItem( public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?ModStrings
string $resourceClass, {
$id, return $this->modStringsHandler->getModStrings($uriVariables['id'] ?? '');
string $operationName = null,
array $context = []
): ?ModStrings {
return $this->modStringsHandler->getModStrings($id);
} }
} }

View file

@ -27,17 +27,16 @@
namespace App\Metadata\DataProvider; namespace App\Metadata\DataProvider;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Metadata\Operation;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use ApiPlatform\State\ProviderInterface;
use App\Metadata\Entity\AppMetadata; use App\Metadata\Entity\AppMetadata;
use App\Metadata\Service\AppMetadataProviderInterface; use App\Metadata\Service\AppMetadataProviderInterface;
use Exception;
/** /**
* Class AppMetaItemDataProvider * Class AppMetadataStateProvider
* @package App\Metatata\DataProvider * @package App\Metatata\DataProvider
*/ */
class AppMetadataItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface class AppMetadataStateProvider implements ProviderInterface
{ {
/** /**
* @var AppMetadataProviderInterface * @var AppMetadataProviderInterface
@ -45,7 +44,7 @@ class AppMetadataItemDataProvider implements ItemDataProviderInterface, Restrict
protected $metadata; protected $metadata;
/** /**
* AppMetaItemDataProvider constructor. * AppMetadataStateProvider constructor.
* @param AppMetadataProviderInterface $metadata * @param AppMetadataProviderInterface $metadata
*/ */
public function __construct(AppMetadataProviderInterface $metadata) public function __construct(AppMetadataProviderInterface $metadata)
@ -54,36 +53,18 @@ class AppMetadataItemDataProvider implements ItemDataProviderInterface, Restrict
} }
/** /**
* Define supported resources * @param Operation $operation
* @param string $resourceClass * @param array $uriVariables
* @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 array $context * @param array $context
* @return AppMetadata|null * @return AppMetadata|null
* @throws Exception
*/ */
public function getItem( public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?AppMetadata
string $resourceClass, {
$id,
string $operationName = null,
array $context = []
): ?AppMetadata {
$attributes = []; $attributes = [];
if (!empty($context['attributes'])) { if (!empty($context['attributes'])) {
$attributes = array_keys($context['attributes']); $attributes = array_keys($context['attributes']);
} }
return $this->metadata->getMetadata($id, $attributes); return $this->metadata->getMetadata($uriVariables['id'] ?? '', $attributes);
} }
} }

View file

@ -27,17 +27,16 @@
namespace App\Metadata\DataProvider; namespace App\Metadata\DataProvider;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Metadata\Operation;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use ApiPlatform\State\ProviderInterface;
use App\Metadata\Entity\ModuleMetadata; use App\Metadata\Entity\ModuleMetadata;
use App\Metadata\Service\ModuleMetadataProviderInterface; use App\Metadata\Service\ModuleMetadataProviderInterface;
use Exception;
/** /**
* Class ModuleMetaItemDataProvider * Class ModuleMetadataStateProvider
* @package App\Metatata\DataProvider * @package App\Metatata\DataProvider
*/ */
class ModuleMetadataItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface class ModuleMetadataStateProvider implements ProviderInterface
{ {
/** /**
* @var ModuleMetadataProviderInterface * @var ModuleMetadataProviderInterface
@ -45,7 +44,7 @@ class ModuleMetadataItemDataProvider implements ItemDataProviderInterface, Restr
protected $metadata; protected $metadata;
/** /**
* ModuleMetaItemDataProvider constructor. * ModuleMetadataStateProvider constructor.
* @param ModuleMetadataProviderInterface $metadata * @param ModuleMetadataProviderInterface $metadata
*/ */
public function __construct(ModuleMetadataProviderInterface $metadata) public function __construct(ModuleMetadataProviderInterface $metadata)
@ -54,36 +53,18 @@ class ModuleMetadataItemDataProvider implements ItemDataProviderInterface, Restr
} }
/** /**
* Define supported resources * @param Operation $operation
* @param string $resourceClass * @param array $uriVariables
* @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 array $context * @param array $context
* @return ModuleMetadata|null * @return ModuleMetadata|null
* @throws Exception
*/ */
public function getItem( public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?ModuleMetadata
string $resourceClass, {
$id,
string $operationName = null,
array $context = []
): ?ModuleMetadata {
$attributes = []; $attributes = [];
if (!empty($context['attributes'])) { if (!empty($context['attributes'])) {
$attributes = array_keys($context['attributes']); $attributes = array_keys($context['attributes']);
} }
return $this->metadata->getMetadata($id, $attributes); return $this->metadata->getMetadata($uriVariables['id'] ?? '', $attributes);
} }
} }

View file

@ -28,13 +28,13 @@
namespace App\Navbar\DataProvider; namespace App\Navbar\DataProvider;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Metadata\Operation;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use ApiPlatform\State\ProviderInterface;
use App\Navbar\Entity\Navbar; use App\Navbar\Entity\Navbar;
use App\Routes\Service\NavigationProviderInterface; 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 * @var NavigationProviderInterface
@ -47,7 +47,7 @@ final class NavbarItemDataProvider implements ItemDataProviderInterface, Restric
private $security; private $security;
/** /**
* NavbarItemDataProvider constructor. * NavbarStateProvider constructor.
* @param NavigationProviderInterface $navigationService * @param NavigationProviderInterface $navigationService
* @param Security $security * @param Security $security
*/ */
@ -57,27 +57,14 @@ final class NavbarItemDataProvider implements ItemDataProviderInterface, Restric
$this->security = $security; $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 * Get navbar
* @param string $resourceClass * @param Operation $operation
* @param array|int|string $id * @param array $uriVariables
* @param string|null $operationName
* @param array $context * @param array $context
* @return Navbar|null * @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(); $navbar = $this->navigationService->getNavbar();
$user = $this->security->getUser(); $user = $this->security->getUser();

View file

@ -1,68 +0,0 @@
<?php
/**
* SuiteCRM is a customer relationship management program developed by SalesAgility Ltd.
* Copyright (C) 2021 SalesAgility Ltd.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SALESAGILITY, SALESAGILITY DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* 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));
}
}

View file

@ -27,40 +27,26 @@
namespace App\Process\DataProvider; namespace App\Process\DataProvider;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Metadata\CollectionOperationInterface;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use ApiPlatform\Metadata\Operation;
use ApiPlatform\Core\Exception\ItemNotFoundException; use ApiPlatform\State\ProviderInterface;
use App\Process\Entity\Process; 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 * Get Process
* @param string $resourceClass * @param Operation $operation
* @param array|int|string $id * @param array $uriVariables
* @param string|null $operationName
* @param array $context * @param array $context
* @return Process|null * @return array|Process|null
*/ */
public function getItem( public function provide(Operation $operation, array $uriVariables = [], array $context = []): array|Process|null
string $resourceClass, {
$id, if ($operation instanceof CollectionOperationInterface) {
string $operationName = null, return [];
array $context = [] }
): ?Process {
//Async processes not implemented yet return null;
throw new ItemNotFoundException();
} }
} }

View file

@ -27,12 +27,12 @@
namespace App\Statistics\DataProvider; namespace App\Statistics\DataProvider;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Metadata\Operation;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use ApiPlatform\State\ProviderInterface;
use App\Statistics\Entity\BatchedStatistics; use App\Statistics\Entity\BatchedStatistics;
use App\Statistics\Service\StatisticsManagerInterface; use App\Statistics\Service\StatisticsManagerInterface;
class BatchedStatisticsItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface class BatchedStatisticsStateProvider implements ProviderInterface
{ {
/** /**
* @var StatisticsManagerInterface * @var StatisticsManagerInterface
@ -40,7 +40,7 @@ class BatchedStatisticsItemDataProvider implements ItemDataProviderInterface, Re
private $manager; private $manager;
/** /**
* BatchedStatisticsItemDataProvider constructor. * BatchedStatisticsStateProvider constructor.
* @param StatisticsManagerInterface $manager * @param StatisticsManagerInterface $manager
*/ */
public function __construct(StatisticsManagerInterface $manager) public function __construct(StatisticsManagerInterface $manager)
@ -48,37 +48,15 @@ class BatchedStatisticsItemDataProvider implements ItemDataProviderInterface, Re
$this->manager = $manager; $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 * Get batched statistics
* @param string $resourceClass * @param Operation $operation
* @param array|int|string $id * @param array $uriVariables
* @param string|null $operationName
* @param array $context * @param array $context
* @return BatchedStatistics|null * @return BatchedStatistics|null
*/ */
public function getItem( public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?BatchedStatistics
string $resourceClass, {
$id,
string $operationName = null,
array $context = []
): ?BatchedStatistics {
return null; return null;
} }
} }

View file

@ -27,12 +27,12 @@
namespace App\Statistics\DataProvider; namespace App\Statistics\DataProvider;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Metadata\Operation;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use ApiPlatform\State\ProviderInterface;
use App\Statistics\Entity\Statistic; use App\Statistics\Entity\Statistic;
use App\Statistics\Service\StatisticsProviderRegistry; use App\Statistics\Service\StatisticsProviderRegistry;
class StatisticsItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface class StatisticsStateProvider implements ProviderInterface
{ {
/** /**
* @var StatisticsProviderRegistry * @var StatisticsProviderRegistry
@ -40,7 +40,7 @@ class StatisticsItemDataProvider implements ItemDataProviderInterface, Restricte
private $registry; private $registry;
/** /**
* StatisticsItemDataProvider constructor. * StatisticsStateProvider constructor.
* @param StatisticsProviderRegistry $registry * @param StatisticsProviderRegistry $registry
*/ */
public function __construct(StatisticsProviderRegistry $registry) public function __construct(StatisticsProviderRegistry $registry)
@ -48,37 +48,15 @@ class StatisticsItemDataProvider implements ItemDataProviderInterface, Restricte
$this->registry = $registry; $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 * Get chart data for given chart id
* @param string $resourceClass * @param Operation $operation
* @param array|int|string $id * @param array $uriVariables
* @param string|null $operationName
* @param array $context * @param array $context
* @return Statistic|null * @return Statistic|null
*/ */
public function getItem( public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?Statistic
string $resourceClass, {
$id,
string $operationName = null,
array $context = []
): ?Statistic {
return null; return null;
} }
} }

View file

@ -1,84 +0,0 @@
<?php
/**
* SuiteCRM is a customer relationship management program developed by SalesAgility Ltd.
* Copyright (C) 2021 SalesAgility Ltd.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SALESAGILITY, SALESAGILITY DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* 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));
}
}

View file

@ -27,15 +27,16 @@
namespace App\SystemConfig\DataProvider; namespace App\SystemConfig\DataProvider;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Metadata\CollectionOperationInterface;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\SystemConfig\Entity\SystemConfig; use App\SystemConfig\Entity\SystemConfig;
use App\SystemConfig\Service\SystemConfigProviderInterface; 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; private $systemConfigProvider;
/** /**
* SystemConfigItemDataProvider constructor. * SystemConfigStateProvider constructor.
* @param SystemConfigProviderInterface $systemConfigProvider * @param SystemConfigProviderInterface $systemConfigProvider
*/ */
public function __construct(SystemConfigProviderInterface $systemConfigProvider) public function __construct(SystemConfigProviderInterface $systemConfigProvider)
@ -52,33 +53,19 @@ final class SystemConfigItemDataProvider implements ItemDataProviderInterface, R
$this->systemConfigProvider = $systemConfigProvider; $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 * Get system config
* @param string $resourceClass * @param Operation $operation
* @param array|int|string $id * @param array $uriVariables
* @param string|null $operationName
* @param array $context * @param array $context
* @return SystemConfig|null * @return array|SystemConfig|null
*/ */
public function getItem( public function provide(Operation $operation, array $uriVariables = [], array $context = []): array|SystemConfig|null
string $resourceClass, {
$id, if ($operation instanceof CollectionOperationInterface) {
string $operationName = null, return $this->systemConfigProvider->getAllSystemConfigs();
array $context = [] }
): ?SystemConfig {
return $this->systemConfigProvider->getSystemConfig($id); return $this->systemConfigProvider->getSystemConfig($uriVariables['id'] ?? '');
} }
} }

View file

@ -27,15 +27,15 @@
namespace App\Themes\DataProvider; namespace App\Themes\DataProvider;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Metadata\Operation;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use ApiPlatform\State\ProviderInterface;
use App\Themes\Entity\ThemeImages; use App\Themes\Entity\ThemeImages;
use App\Themes\Service\ThemeImageService; use App\Themes\Service\ThemeImageService;
/** /**
* Class ThemeImagesItemDataProvider * Class ThemeImagesStateProvider
*/ */
final class ThemeImagesItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface final class ThemeImagesStateProvider implements ProviderInterface
{ {
/** /**
* @var ThemeImageService * @var ThemeImageService
@ -44,7 +44,7 @@ final class ThemeImagesItemDataProvider implements ItemDataProviderInterface, Re
/** /**
* ThemeImagesItemDataProvider constructor. * ThemeImagesStateProvider constructor.
* @param ThemeImageService $themeImageService * @param ThemeImageService $themeImageService
*/ */
public function __construct(ThemeImageService $themeImageService) public function __construct(ThemeImageService $themeImageService)
@ -52,33 +52,15 @@ final class ThemeImagesItemDataProvider implements ItemDataProviderInterface, Re
$this->themeImageService = $themeImageService; $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 * Get theme image information for given theme
* @param string $resourceClass * @param Operation $operation
* @param array|int|string $id * @param array $uriVariables
* @param string|null $operationName
* @param array $context * @param array $context
* @return ThemeImages|null * @return ThemeImages|null
*/ */
public function getItem( public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?ThemeImages
string $resourceClass, {
$id, return $this->themeImageService->get($uriVariables['id'] ?? '');
string $operationName = null,
array $context = []
): ?ThemeImages {
return $this->themeImageService->get($id);
} }
} }

View file

@ -1,83 +0,0 @@
<?php
/**
* SuiteCRM is a customer relationship management program developed by SalesAgility Ltd.
* Copyright (C) 2021 SalesAgility Ltd.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SALESAGILITY, SALESAGILITY DISCLAIMS THE
* WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* 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));
}
}

View file

@ -24,17 +24,19 @@
* feasible for technical reasons, the Appropriate Legal Notices must display * feasible for technical reasons, the Appropriate Legal Notices must display
* the words "Supercharged by SuiteCRM". * the words "Supercharged by SuiteCRM".
*/ */
namespace App\UserPreferences\DataProvider; namespace App\UserPreferences\DataProvider;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Metadata\CollectionOperationInterface;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\UserPreferences\Entity\UserPreference; use App\UserPreferences\Entity\UserPreference;
use App\UserPreferences\Service\UserPreferencesProviderInterface; 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; private $userPreferenceService;
/** /**
* UserPreferenceItemDataProvider constructor. * UserPreferenceStateProvider constructor.
* @param UserPreferencesProviderInterface $userPreferenceService * @param UserPreferencesProviderInterface $userPreferenceService
*/ */
public function __construct(UserPreferencesProviderInterface $userPreferenceService) public function __construct(UserPreferencesProviderInterface $userPreferenceService)
@ -51,32 +53,19 @@ final class UserPreferenceItemDataProvider implements ItemDataProviderInterface,
$this->userPreferenceService = $userPreferenceService; $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 * Get user preference
* @param string $resourceClass * @param Operation $operation
* @param array|int|string $id * @param array $uriVariables
* @param string|null $operationName
* @param array $context * @param array $context
* @return UserPreference|null * @return iterable|UserPreference|null
*/ */
public function getItem( public function provide(Operation $operation, array $uriVariables = [], array $context = []): array|UserPreference|null
string $resourceClass, {
$id, if ($operation instanceof CollectionOperationInterface) {
string $operationName = null, return $this->userPreferenceService->getAllUserPreferences();
array $context = [] }
): ?UserPreference {
return $this->userPreferenceService->getUserPreference($id); return $this->userPreferenceService->getUserPreference($uriVariables['id'] ?? '');
} }
} }

View file

@ -27,64 +27,41 @@
namespace App\ViewDefinitions\DataProvider; namespace App\ViewDefinitions\DataProvider;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; use ApiPlatform\Metadata\Operation;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface; use ApiPlatform\State\ProviderInterface;
use App\ViewDefinitions\Entity\ViewDefinition; use App\ViewDefinitions\Entity\ViewDefinition;
use App\ViewDefinitions\Service\ViewDefinitionsProviderInterface; use App\ViewDefinitions\Service\ViewDefinitionsProviderInterface;
use Exception; use Exception;
/** /**
* Class ViewDefinitionItemDataProvider * Class ViewDefinitionProvider
* @package App\DataProvider * @package App\DataProvider
*/ */
class ViewDefinitionItemDataProvider implements ItemDataProviderInterface, RestrictedDataProviderInterface class ViewDefinitionStateProvider implements ProviderInterface
{ {
/**
* @var ViewDefinitionsProviderInterface
*/
protected $viewDefHandler;
/** /**
* ViewDefinitionItemDataProvider constructor. * ViewDefinitionProvider constructor.
* @param ViewDefinitionsProviderInterface $viewDefHandler * @param ViewDefinitionsProviderInterface $viewDefHandler
*/ */
public function __construct(ViewDefinitionsProviderInterface $viewDefHandler) public function __construct(protected readonly ViewDefinitionsProviderInterface $viewDefHandler)
{ {
$this->viewDefHandler = $viewDefHandler;
} }
/** /**
* Define supported resources * @param Operation $operation
* @param string $resourceClass * @param array $uriVariables
* @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 array $context * @param array $context
* @return ViewDefinition|null * @return ViewDefinition|null
* @throws Exception * @throws Exception
*/ */
public function getItem( public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?ViewDefinition
string $resourceClass, {
$id,
string $operationName = null,
array $context = []
): ?ViewDefinition {
$attributes = []; $attributes = [];
if (!empty($context['attributes'])) { if (!empty($context['attributes'])) {
$attributes = array_keys($context['attributes']); $attributes = array_keys($context['attributes']);
} }
return $this->viewDefHandler->getViewDefs($id, $attributes); return $this->viewDefHandler->getViewDefs($uriVariables['id'] ?? '', $attributes);
} }
} }