mirror of
https://github.com/SuiteCRM/SuiteCRM-Core.git
synced 2025-09-02 08:09:19 +08:00
Symfony 6.4 - Refactor DataProviders into new StateProvider
This commit is contained in:
parent
5e2a39c089
commit
03fc4ed9d1
19 changed files with 173 additions and 690 deletions
|
@ -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'] ?? '');
|
||||
}
|
||||
}
|
|
@ -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'] ?? '');
|
||||
}
|
||||
}
|
|
@ -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'] ?? '');
|
||||
}
|
||||
}
|
|
@ -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'] ?? '');
|
||||
}
|
||||
}
|
|
@ -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'] ?? '');
|
||||
}
|
||||
}
|
|
@ -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'] ?? '');
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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();
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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'] ?? '');
|
||||
}
|
||||
}
|
|
@ -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'] ?? '');
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
@ -52,31 +54,18 @@ final class UserPreferenceItemDataProvider implements ItemDataProviderInterface,
|
|||
}
|
||||
|
||||
/**
|
||||
* Defined supported resources
|
||||
* @param string $resourceClass
|
||||
* @param string|null $operationName
|
||||
* Get user preference
|
||||
* @param Operation $operation
|
||||
* @param array $uriVariables
|
||||
* @param array $context
|
||||
* @return bool
|
||||
* @return iterable|UserPreference|null
|
||||
*/
|
||||
public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): array|UserPreference|null
|
||||
{
|
||||
return UserPreference::class === $resourceClass;
|
||||
if ($operation instanceof CollectionOperationInterface) {
|
||||
return $this->userPreferenceService->getAllUserPreferences();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get user preference
|
||||
* @param string $resourceClass
|
||||
* @param array|int|string $id
|
||||
* @param string|null $operationName
|
||||
* @param array $context
|
||||
* @return UserPreference|null
|
||||
*/
|
||||
public function getItem(
|
||||
string $resourceClass,
|
||||
$id,
|
||||
string $operationName = null,
|
||||
array $context = []
|
||||
): ?UserPreference {
|
||||
return $this->userPreferenceService->getUserPreference($id);
|
||||
return $this->userPreferenceService->getUserPreference($uriVariables['id'] ?? '');
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue