Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| ResourcesFolder | |
100.00% |
10 / 10 |
|
100.00% |
4 / 4 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getChild | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getChildren | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | namespace Apie\ApieFileSystem\Virtual; |
| 3 | |
| 4 | use Apie\ApieFileSystem\Lists\VirtualFileMap; |
| 5 | use Apie\Common\ActionDefinitionProvider; |
| 6 | use Apie\Common\ActionDefinitions\GetResourceListActionDefinition; |
| 7 | use Apie\Core\BoundedContext\BoundedContext; |
| 8 | use Apie\Core\Context\ApieContext; |
| 9 | |
| 10 | /** |
| 11 | * A folder representing the resources in a bounded context in the virtual file system. |
| 12 | * |
| 13 | * @see BoundedContextFolder parent folder |
| 14 | */ |
| 15 | class ResourcesFolder implements VirtualFolderInterface |
| 16 | { |
| 17 | private VirtualFileMap $children; |
| 18 | |
| 19 | public function __construct( |
| 20 | private readonly BoundedContext $boundedContext, |
| 21 | private readonly ActionDefinitionProvider $actionDefinitionProvider, |
| 22 | private readonly ApieContext $apieContext |
| 23 | ) { |
| 24 | |
| 25 | } |
| 26 | |
| 27 | public function getName(): string |
| 28 | { |
| 29 | return 'resources'; |
| 30 | } |
| 31 | |
| 32 | public function getChild(string $name): VirtualFileInterface|VirtualFolderInterface|null |
| 33 | { |
| 34 | return $this->getChildren()[$name] ?? null; |
| 35 | } |
| 36 | |
| 37 | public function getChildren(): VirtualFileMap |
| 38 | { |
| 39 | if (!isset($this->children)) { |
| 40 | $files = []; |
| 41 | foreach ($this->actionDefinitionProvider->provideActionDefinitions($this->boundedContext, $this->apieContext, true) as $actionDefinition) { |
| 42 | if ($actionDefinition instanceof GetResourceListActionDefinition) { |
| 43 | $files[$actionDefinition->getResourceName()->getShortName()] = new GetResourceListFolder($actionDefinition, $this->apieContext); |
| 44 | } |
| 45 | } |
| 46 | $this->children = new VirtualFileMap($files); |
| 47 | } |
| 48 | return $this->children; |
| 49 | } |
| 50 | } |