Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
19 / 19 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| ResourcesFolder | |
100.00% |
19 / 19 |
|
100.00% |
4 / 4 |
9 | |
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% |
16 / 16 |
|
100.00% |
1 / 1 |
6 | |||
| 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 | use Apie\Export\EntityExport; |
| 10 | |
| 11 | /** |
| 12 | * A folder representing the resources in a bounded context in the virtual file system. |
| 13 | * |
| 14 | * @see BoundedContextFolder parent folder |
| 15 | */ |
| 16 | class ResourcesFolder implements VirtualFolderInterface |
| 17 | { |
| 18 | private VirtualFileMap $children; |
| 19 | |
| 20 | public function __construct( |
| 21 | private readonly BoundedContext $boundedContext, |
| 22 | private readonly ActionDefinitionProvider $actionDefinitionProvider, |
| 23 | private readonly ApieContext $apieContext |
| 24 | ) { |
| 25 | |
| 26 | } |
| 27 | |
| 28 | public function getName(): string |
| 29 | { |
| 30 | return 'resources'; |
| 31 | } |
| 32 | |
| 33 | public function getChild(string $name): VirtualFileInterface|VirtualFolderInterface|null |
| 34 | { |
| 35 | return $this->getChildren()[$name] ?? null; |
| 36 | } |
| 37 | |
| 38 | public function getChildren(): VirtualFileMap |
| 39 | { |
| 40 | $exporter = $this->apieContext->getContext(EntityExport::class, false); |
| 41 | if (!isset($this->children)) { |
| 42 | $files = []; |
| 43 | foreach ($this->actionDefinitionProvider->provideActionDefinitions($this->boundedContext, $this->apieContext, true) as $actionDefinition) { |
| 44 | if ($actionDefinition instanceof GetResourceListActionDefinition) { |
| 45 | $files[$actionDefinition->getResourceName()->getShortName()] = new GetResourceListFolder($actionDefinition, $this->apieContext); |
| 46 | if ($exporter) { |
| 47 | foreach ($exporter->getSupportedExtensions() as $fileExtension) { |
| 48 | $files[$actionDefinition->getResourceName()->getShortName() . '.' . $fileExtension->toNative()] = new ExportResourceFile( |
| 49 | $this->apieContext, |
| 50 | $actionDefinition->getResourceName(), |
| 51 | $fileExtension, |
| 52 | $exporter |
| 53 | ); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | $this->children = new VirtualFileMap($files); |
| 59 | } |
| 60 | return $this->children; |
| 61 | } |
| 62 | } |