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