-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
ModelManagerInterface.php
168 lines (147 loc) · 4.42 KB
/
ModelManagerInterface.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\AdminBundle\Model;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\AdminBundle\Exception\ModelManagerThrowable;
/**
* A model manager is a bridge between the model classes and the admin functionality.
*
* @phpstan-template T of object
*/
interface ModelManagerInterface
{
/**
* @throws ModelManagerThrowable
*
* @phpstan-param T $object
*/
public function create(object $object): void;
/**
* @throws ModelManagerThrowable
*
* @phpstan-param T $object
*/
public function update(object $object): void;
/**
* @throws ModelManagerThrowable
*
* @phpstan-param T $object
*/
public function delete(object $object): void;
/**
* @param array<string, mixed> $criteria
*
* @return object[] all objects matching the criteria
*
* @phpstan-param class-string<T> $class
* @phpstan-return T[]
*/
public function findBy(string $class, array $criteria = []): array;
/**
* @param array<string, mixed> $criteria
*
* @return object|null an object matching the criteria or null if none match
*
* @phpstan-param class-string<T> $class
* @phpstan-return T|null
*/
public function findOneBy(string $class, array $criteria = []): ?object;
/**
* @param int|string $id
*
* @return object|null the object with id or null if not found
*
* @phpstan-param class-string<T> $class
* @phpstan-return T|null
*/
public function find(string $class, $id): ?object;
/**
* @throws ModelManagerThrowable
*
* @phpstan-param class-string<T> $class
* @phpstan-param ProxyQueryInterface<T> $query
*/
public function batchDelete(string $class, ProxyQueryInterface $query): void;
/**
* @phpstan-param class-string<T> $class
* @phpstan-return ProxyQueryInterface<T>
*/
public function createQuery(string $class): ProxyQueryInterface;
/**
* NEXT_MAJOR: Remove this method.
*
* Get the identifiers of this model class.
*
* This returns an array to handle cases like a primary key that is
* composed of multiple columns. If you need a string representation,
* use getNormalizedIdentifier resp. getUrlSafeIdentifier
*
* @return array<int|string> list of all identifiers of this model
*
* @phpstan-param T $model
*/
public function getIdentifierValues(object $model): array;
/**
* NEXT_MAJOR: Remove this method.
*
* Get a list of the field names models of the specified fully qualified
* class name used to store the identifier.
*
* @return string[]
*
* @phpstan-param class-string<T> $class
*/
public function getIdentifierFieldNames(string $class): array;
/**
* Get the identifiers for this model class as a string.
*
* @phpstan-param T $model
*/
public function getNormalizedIdentifier(object $model): ?string;
/**
* Get the identifiers as a string that is safe to use in a url.
*
* This is similar to getNormalizedIdentifier but guarantees an id that can
* be used in a URL.
*
* @phpstan-param T $model
*/
public function getUrlSafeIdentifier(object $model): ?string;
/**
* @param array<string, mixed> $array
*
* @phpstan-param T $object
*/
public function reverseTransform(object $object, array $array = []): void;
public function supportsQuery(object $query): bool;
/**
* NEXT_MAJOR: Add typehint.
*
* @return iterable<object>
*
* @phpstan-return iterable<T>
*/
public function executeQuery(object $query);
/**
* @return string[]
*
* @phpstan-param class-string<T> $class
*/
public function getExportFields(string $class): array;
/**
* @param array<int|string> $idx
*
* @phpstan-param class-string<T> $class
* @phpstan-param ProxyQueryInterface<T> $query
* @phpstan-param non-empty-array<string|int> $idx
*/
public function addIdentifiersToQuery(string $class, ProxyQueryInterface $query, array $idx): void;
}