-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathDataProviderInterface.php
110 lines (99 loc) · 3.51 KB
/
DataProviderInterface.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
declare(strict_types=1);
namespace Cundd\Rest\DataProvider;
use Cundd\Rest\Domain\Model\ResourceType;
use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;
use TYPO3\CMS\Extbase\Persistence\QueryResultInterface;
interface DataProviderInterface
{
/**
* Return all Domain Models for the given API resource type
*
* @param ResourceType $resourceType API resource type to get the repository for
* @return object[]|DomainObjectInterface[]|QueryResultInterface
*/
public function fetchAllModels(ResourceType $resourceType);
/**
* Return the number of all Domain Models for the given API resource type
*
* @param ResourceType $resourceType API resource type to get the repository for
* @return int
*/
public function countAllModels(ResourceType $resourceType): int;
/**
* Return a Domain Model for the given API resource type and data
*
* This method will load existing models
*
* @param array|string|int $identifier Data of the new model or it's UID
* @param ResourceType $resourceType API resource type to get the repository for
* @return object|DomainObjectInterface|null Returns the Domain Model or NULL if it was not found
*/
public function fetchModel($identifier, ResourceType $resourceType);
/**
* Create a new Domain Model with the given data
*
* Implementations are free to decide if identifiers are accepted (e.g. an exception will be thrown for Extbase
* Models if the property `uid` or `__identity` is given. `Virtual Objects` on the other hand accept identifier
* properties)
*
* @param array $data Data of the new model
* @param ResourceType $resourceType API resource type to get the repository for
* @return object|DomainObjectInterface|\Exception Return the created Model on success otherwise an Exception
*/
public function createModel(array $data, ResourceType $resourceType);
/**
* Converts the data into an instance of the Domain Model for the Resource Type
*
* @param array $data
* @param ResourceType $resourceType
* @return object|DomainObjectInterface
*/
public function convertIntoModel(array $data, ResourceType $resourceType);
/**
* Extract the data from the given Model
*
* @param object|DomainObjectInterface $model
* @return array|null|int|bool|string|float
*/
public function getModelData(
/*(?object)*/
$model
);
/**
* Return the property data from the given Model
*
* @param object|DomainObjectInterface $model
* @param string $propertyParameter
* @return mixed
*/
public function getModelProperty(
/*(object)*/
$model,
string $propertyParameter
);
/**
* Add or update the given Model in the repository
*
* @param object|DomainObjectInterface $model
* @param ResourceType $resourceType The API resource type
* @return void
*/
public function saveModel(
/*(?object)*/
$model,
ResourceType $resourceType
): void;
/**
* Remove the given model from the repository for the given API resource type
*
* @param object|DomainObjectInterface $model
* @param ResourceType $resourceType The API resource type
* @return void
*/
public function removeModel(
/*(?object)*/
$model,
ResourceType $resourceType
): void;
}