DiscoveryManager::disableBindingDescriptor()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the puli/manager package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Puli\Manager\Api\Discovery;
13
14
use Puli\Manager\Api\Context\ProjectContext;
15
use Puli\Manager\Api\NonRootModuleExpectedException;
16
use Rhumsaa\Uuid\Uuid;
17
use Webmozart\Expression\Expression;
18
19
/**
20
 * Manages the resource discovery of a Puli project.
21
 *
22
 * @since  1.0
23
 *
24
 * @author Bernhard Schussek <[email protected]>
25
 */
26
interface DiscoveryManager
27
{
28
    /**
29
     * Flag: Don't check whether the type exists already in
30
     * {@link addRootTypeDescriptor()}.
31
     */
32
    const OVERRIDE = 1;
33
34
    /**
35
     * Flag: Ignore if the type is not found in {@link addBinding()}.
36
     */
37
    const IGNORE_TYPE_NOT_FOUND = 2;
38
39
    /**
40
     * Flag: Ignore if the type is not enabled in {@link addBinding()}.
41
     */
42
    const IGNORE_TYPE_NOT_ENABLED = 4;
43
44
    /**
45
     * Returns the manager's context.
46
     *
47
     * @return ProjectContext The project context.
48
     */
49
    public function getContext();
50
51
    /**
52
     * Adds a new binding type.
53
     *
54
     * The type definition is added to the root module file.
55
     *
56
     * @param BindingTypeDescriptor $typeDescriptor The type to add.
57
     * @param int                   $flags          A bitwise combination of the
58
     *                                              flag constants in this class.
59
     *
60
     * @throws DuplicateTypeException If the type is already defined.
61
     */
62
    public function addRootTypeDescriptor(BindingTypeDescriptor $typeDescriptor, $flags = 0);
63
64
    /**
65
     * Removes a binding type from the root module.
66
     *
67
     * The type definition is removed from the root module file. If the type
68
     * is not found, this method does nothing.
69
     *
70
     * @param string $typeName The name of the type to remove.
71
     */
72
    public function removeRootTypeDescriptor($typeName);
73
74
    /**
75
     * Removes all binding types matching the given expression.
76
     *
77
     * If no matching binding types are found, this method does nothing.
78
     *
79
     * @param Expression $expr The search criteria.
80
     */
81
    public function removeRootTypeDescriptors(Expression $expr);
82
83
    /**
84
     * Removes all binding types from the root module.
85
     */
86
    public function clearRootTypeDescriptors();
87
88
    /**
89
     * Returns the binding type with the given name from the root module.
90
     *
91
     * @param string $typeName The name of the type.
92
     *
93
     * @return BindingTypeDescriptor The binding type.
94
     *
95
     * @throws NoSuchTypeException If the type does not exist.
96
     */
97
    public function getRootTypeDescriptor($typeName);
98
99
    /**
100
     * Returns all binding types from the root module.
101
     *
102
     * @return BindingTypeDescriptor[] The binding types.
103
     */
104
    public function getRootTypeDescriptors();
105
106
    /**
107
     * Returns all binding types from the root module that match the given
108
     * expression.
109
     *
110
     * @param Expression $expr The search criteria.
111
     *
112
     * @return BindingTypeDescriptor[] The binding types matching the expression.
113
     */
114
    public function findRootTypeDescriptors(Expression $expr);
115
116
    /**
117
     * Returns whether the type with the given name exists in the root module.
118
     *
119
     * @param string $typeName The name of the type.
120
     *
121
     * @return bool Returns `true` if the type exists and `false` otherwise.
122
     */
123
    public function hasRootTypeDescriptor($typeName);
124
125
    /**
126
     * Returns whether the manager has any binding types in the root module.
127
     *
128
     * You can optionally pass an expression to check whether the manager has
129
     * types matching the expression.
130
     *
131
     * @param Expression|null $expr The search criteria.
132
     *
133
     * @return bool Returns `true` if the manager has binding types in the root
134
     *              module and `false` otherwise. If an expression was passed,
135
     *              this method only returns `true` if the manager has binding
136
     *              types matching the expression.
137
     */
138
    public function hasRootTypeDescriptors(Expression $expr = null);
139
140
    /**
141
     * Returns the binding type with the given name.
142
     *
143
     * @param string $typeName   The name of the type.
144
     * @param string $moduleName The name of the module to check.
145
     *
146
     * @return BindingTypeDescriptor The binding type.
147
     *
148
     * @throws NoSuchTypeException If the type does not exist.
149
     */
150
    public function getTypeDescriptor($typeName, $moduleName);
151
152
    /**
153
     * Returns all binding types.
154
     *
155
     * @return BindingTypeDescriptor[] The binding types.
156
     */
157
    public function getTypeDescriptors();
158
159
    /**
160
     * Returns all binding types matching the given expression.
161
     *
162
     * @param Expression $expr The search criteria.
163
     *
164
     * @return BindingTypeDescriptor[] The binding types matching the expression.
165
     */
166
    public function findTypeDescriptors(Expression $expr);
167
168
    /**
169
     * Returns whether the type with the given name exists.
170
     *
171
     * @param string      $typeName   The name of the type.
172
     * @param string|null $moduleName The name of the module to check. Useful
173
     *                                if types with the same name exist in
174
     *                                multiple modules.
175
     *
176
     * @return bool Returns `true` if the type exists and `false` otherwise.
177
     */
178
    public function hasTypeDescriptor($typeName, $moduleName = null);
179
180
    /**
181
     * Returns whether the manager has any binding types.
182
     *
183
     * You can optionally pass an expression to check whether the manager has
184
     * types matching the expression.
185
     *
186
     * @param Expression $expr The search criteria.
0 ignored issues
show
Documentation introduced by
Should the type for parameter $expr not be null|Expression?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
187
     *
188
     * @return bool Returns `true` if the manager has binding types and `false`
189
     *              otherwise. If an expression was passed, this method only
190
     *              returns `true` if the manager has binding types matching the
191
     *              expression.
192
     */
193
    public function hasTypeDescriptors(Expression $expr = null);
194
195
    /**
196
     * Adds a new binding.
197
     *
198
     * The binding descriptor is added to the root module file.
199
     *
200
     * @param BindingDescriptor $bindingDescriptor The binding to add.
201
     * @param int               $flags             A bitwise combination of the
202
     *                                             flag constants in this class.
203
     *
204
     * @throws NoSuchTypeException       If the type referenced by the descriptor does
205
     *                                   not exist.
206
     * @throws TypeNotEnabledException   If the type referenced by the descriptor
207
     *                                   is not enabled.
208
     * @throws DuplicateBindingException If a binding with the same UUID exists
209
     *                                   already.
210
     */
211
    public function addRootBindingDescriptor(BindingDescriptor $bindingDescriptor, $flags = 0);
212
213
    /**
214
     * Removes a binding from the root module.
215
     *
216
     * The binding descriptor is removed from the root module file. If the
217
     * binding is not found, this method does nothing.
218
     *
219
     * @param Uuid $uuid The UUID of the binding.
220
     */
221
    public function removeRootBindingDescriptor(Uuid $uuid);
222
223
    /**
224
     * Removes all bindings matching the given expression.
225
     *
226
     * If no matching bindings are found, this method does nothing.
227
     *
228
     * @param Expression $expr The search criteria.
229
     */
230
    public function removeRootBindingDescriptors(Expression $expr);
231
232
    /**
233
     * Removes all bindings from the root module.
234
     *
235
     * If no bindings are found, this method does nothing.
236
     */
237
    public function clearRootBindingDescriptors();
238
239
    /**
240
     * Returns the binding with the given UUID in the root module.
241
     *
242
     * @param Uuid $uuid The UUID of the binding.
243
     *
244
     * @return BindingDescriptor The binding.
245
     *
246
     * @throws NoSuchBindingException If the binding does not exist.
247
     */
248
    public function getRootBindingDescriptor(Uuid $uuid);
249
250
    /**
251
     * Returns all bindings in the root module.
252
     *
253
     * @return BindingDescriptor[] The bindings.
254
     */
255
    public function getRootBindingDescriptors();
256
257
    /**
258
     * Returns all bindings from the root module that match the given expression.
259
     *
260
     * @param Expression $expr The search criteria.
261
     *
262
     * @return BindingDescriptor[] The bindings matching the expression.
263
     */
264
    public function findRootBindingDescriptors(Expression $expr);
265
266
    /**
267
     * Returns whether the binding with the given UUID exists in the root
268
     * module.
269
     *
270
     * @param Uuid $uuid The UUID of the binding.
271
     *
272
     * @return bool Returns `true` if the binding exists in the root module and
273
     *              `false` otherwise.
274
     */
275
    public function hasRootBindingDescriptor(Uuid $uuid);
276
277
    /**
278
     * Returns whether the manager has any bindings in the root module.
279
     *
280
     * You can optionally pass an expression to check whether the manager has
281
     * bindings matching the expression.
282
     *
283
     * @param Expression|null $expr The search criteria.
284
     *
285
     * @return bool Returns `true` if the manager has bindings in the root
286
     *              module and `false` otherwise. If an expression was passed,
287
     *              this method only returns `true` if the manager has bindings
288
     *              matching the expression.
289
     */
290
    public function hasRootBindingDescriptors(Expression $expr = null);
291
292
    /**
293
     * Enables a binding.
294
     *
295
     * @param Uuid $uuid The UUID of the binding.
296
     *
297
     * @throws NoSuchBindingException         If the binding does not exist.
298
     * @throws NoSuchTypeException            If the type referenced by the descriptor does
299
     *                                        not exist.
300
     * @throws TypeNotEnabledException        If the type referenced by the descriptor
301
     *                                        is not enabled.
302
     * @throws NonRootModuleExpectedException If the binding is in the root
303
     *                                        module. Can only enable bindings
304
     *                                        in non-root modules, because the
305
     *                                        bindings in the root module are
306
     *                                        implicitly enabled.
307
     */
308
    public function enableBindingDescriptor(Uuid $uuid);
309
310
    /**
311
     * Disables a binding.
312
     *
313
     * @param Uuid $uuid The UUID of the binding.
314
     *
315
     * @throws NoSuchBindingException         If the binding does not exist.
316
     * @throws NoSuchTypeException            If the type referenced by the descriptor does
317
     *                                        not exist.
318
     * @throws TypeNotEnabledException        If the type referenced by the descriptor
319
     *                                        is not enabled.
320
     * @throws NonRootModuleExpectedException If the binding is in the root
321
     *                                        module. Can only disable bindings
322
     *                                        in non-root modules, because the
323
     *                                        bindings in the root module are
324
     *                                        implicitly enabled.
325
     */
326
    public function disableBindingDescriptor(Uuid $uuid);
327
328
    /**
329
     * Removes disabled binding UUIDs that were not found in any module.
330
     */
331
    public function removeObsoleteDisabledBindingDescriptors();
332
333
    /**
334
     * Returns the binding with the given UUID.
335
     *
336
     * @param Uuid $uuid The UUID of the binding.
337
     *
338
     * @return BindingDescriptor The binding.
339
     *
340
     * @throws NoSuchBindingException If the binding does not exist.
341
     */
342
    public function getBindingDescriptor(Uuid $uuid);
343
344
    /**
345
     * Returns all bindings.
346
     *
347
     * @return BindingDescriptor[] The bindings.
348
     */
349
    public function getBindingDescriptors();
350
351
    /**
352
     * Returns all bindings matching the given expression.
353
     *
354
     * @param Expression $expr The search criteria.
355
     *
356
     * @return BindingDescriptor[] The bindings matching the expression.
357
     */
358
    public function findBindingDescriptors(Expression $expr);
359
360
    /**
361
     * Returns whether the binding with the given UUID exists.
362
     *
363
     * @param Uuid $uuid The UUID of the binding.
364
     *
365
     * @return bool Returns `true` if the binding exists and `false` otherwise.
366
     */
367
    public function hasBindingDescriptor(Uuid $uuid);
368
369
    /**
370
     * Returns whether the manager has any bindings.
371
     *
372
     * You can optionally pass an expression to check whether the manager has
373
     * bindings matching the expression.
374
     *
375
     * @param Expression|null $expr The search criteria.
376
     *
377
     * @return bool Returns `true` if the manager has bindings and `false`
378
     *              otherwise. If an expression was passed, this method only
379
     *              returns `true` if the manager has bindings matching the
380
     *              expression.
381
     */
382
    public function hasBindingDescriptors(Expression $expr = null);
383
384
    /**
385
     * Builds the resource discovery.
386
     *
387
     * @throws DiscoveryNotEmptyException If the discovery is not empty.
388
     */
389
    public function buildDiscovery();
390
391
    /**
392
     * Clears all contents of the resource discovery.
393
     */
394
    public function clearDiscovery();
395
}
396