1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Contract\Core\Provider; |
4: | |
5: | use Salient\Contract\Container\ContainerInterface; |
6: | use Salient\Contract\Container\HasContainer; |
7: | use Salient\Contract\Core\Entity\Treeable; |
8: | use Salient\Contract\Core\Immutable; |
9: | use Salient\Contract\Core\ListConformity; |
10: | |
11: | /** |
12: | * @api |
13: | * |
14: | * @template TProvider of ProviderInterface |
15: | * @template TEntity of Providable |
16: | * |
17: | * @extends HasProvider<TProvider> |
18: | */ |
19: | interface ProviderContextInterface extends |
20: | Immutable, |
21: | HasContainer, |
22: | HasProvider |
23: | { |
24: | /** |
25: | * Get the context's provider |
26: | * |
27: | * @return TProvider |
28: | */ |
29: | public function getProvider(): ProviderInterface; |
30: | |
31: | /** |
32: | * Get an instance with the given container |
33: | * |
34: | * @return static |
35: | */ |
36: | public function withContainer(ContainerInterface $container); |
37: | |
38: | /** |
39: | * Get the entity type applied to the context |
40: | * |
41: | * @return class-string<TEntity>|null |
42: | */ |
43: | public function getEntityType(): ?string; |
44: | |
45: | /** |
46: | * Get an instance with the given entity type |
47: | * |
48: | * @param class-string<TEntity> $entityType |
49: | * @return static |
50: | */ |
51: | public function withEntityType(string $entityType); |
52: | |
53: | /** |
54: | * Get the array key conformity applied to the context |
55: | * |
56: | * @return ListConformity::* |
57: | */ |
58: | public function getConformity(): int; |
59: | |
60: | /** |
61: | * Get an instance with the given array key conformity |
62: | * |
63: | * @param ListConformity::* $conformity Use {@see ListConformity::COMPLETE} |
64: | * wherever possible to improve performance. |
65: | * @return static |
66: | */ |
67: | public function withConformity(int $conformity); |
68: | |
69: | /** |
70: | * Get entities for which the context has been propagated |
71: | * |
72: | * @return TEntity[] |
73: | */ |
74: | public function getEntities(): array; |
75: | |
76: | /** |
77: | * Get the entity for which the context was most recently propagated |
78: | * |
79: | * @return TEntity|null |
80: | */ |
81: | public function getLastEntity(): ?Providable; |
82: | |
83: | /** |
84: | * Add the entity for which the context is being propagated |
85: | * |
86: | * If `$entity` implements {@see HasId} and the return value of |
87: | * {@see HasId::getId()} is not `null`, it is applied to the context as a |
88: | * value with name `<entity_basename>_id`. |
89: | * |
90: | * @param TEntity $entity |
91: | * @return static |
92: | */ |
93: | public function pushEntity($entity); |
94: | |
95: | /** |
96: | * Get the parent entity applied to the context |
97: | * |
98: | * @return (TEntity&Treeable)|null |
99: | */ |
100: | public function getParent(): ?Providable; |
101: | |
102: | /** |
103: | * Get an instance with the given parent entity |
104: | * |
105: | * @param (TEntity&Treeable)|null $parent |
106: | * @return static |
107: | */ |
108: | public function withParent(?Treeable $parent); |
109: | |
110: | /** |
111: | * Check if a value has been applied to the context |
112: | */ |
113: | public function hasValue(string $name): bool; |
114: | |
115: | /** |
116: | * Get a value applied to the context, or null if it has not been applied |
117: | * |
118: | * @return (int|string|float|bool|null)[]|int|string|float|bool|null |
119: | */ |
120: | public function getValue(string $name); |
121: | |
122: | /** |
123: | * Get an instance with the given value applied |
124: | * |
125: | * @param (int|string|float|bool|null)[]|int|string|float|bool|null $value |
126: | * @return static |
127: | */ |
128: | public function withValue(string $name, $value); |
129: | } |
130: |