Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.31% |
24 / 26 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| GetResourceListFolder | |
92.31% |
24 / 26 |
|
50.00% |
2 / 4 |
10.05 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getChild | |
90.00% |
9 / 10 |
|
0.00% |
0 / 1 |
4.02 | |||
| getChildren | |
92.86% |
13 / 14 |
|
0.00% |
0 / 1 |
4.01 | |||
| 1 | <?php |
| 2 | namespace Apie\ApieFileSystem\Virtual; |
| 3 | |
| 4 | use Apie\ApieFileSystem\Lists\VirtualFileMap; |
| 5 | use Apie\Common\ActionDefinitions\GetResourceListActionDefinition; |
| 6 | use Apie\Core\BoundedContext\BoundedContextId; |
| 7 | use Apie\Core\Context\ApieContext; |
| 8 | use Apie\Core\ContextConstants; |
| 9 | use Apie\Core\Datalayers\ApieDatalayer; |
| 10 | use Apie\Serializer\Serializer; |
| 11 | |
| 12 | class GetResourceListFolder implements VirtualFolderInterface |
| 13 | { |
| 14 | public function __construct( |
| 15 | private readonly GetResourceListActionDefinition $actionDefinition, |
| 16 | private readonly ApieContext $apieContext |
| 17 | ) { |
| 18 | } |
| 19 | |
| 20 | public function getName(): string |
| 21 | { |
| 22 | return $this->actionDefinition->getResourceName()->getShortName(); |
| 23 | } |
| 24 | |
| 25 | public function getChild(string $name): VirtualFileInterface|VirtualFolderInterface|null |
| 26 | { |
| 27 | if (is_numeric($name)) { |
| 28 | $datalayer = $this->apieContext->getContext(ApieDatalayer::class, false); |
| 29 | $serializer = $this->apieContext->getContext(Serializer::class, false); |
| 30 | if ($datalayer instanceof ApieDatalayer && $serializer instanceof Serializer) { |
| 31 | $list = $datalayer->all( |
| 32 | $this->actionDefinition->getResourceName(), |
| 33 | $this->apieContext->getContext(BoundedContextId::class, false) |
| 34 | ); |
| 35 | return new GetResourceListPaginationFolder($list, (int) $name, $serializer, $this->apieContext); |
| 36 | } |
| 37 | } |
| 38 | return null; |
| 39 | } |
| 40 | |
| 41 | public function getChildren(): VirtualFileMap |
| 42 | { |
| 43 | $datalayer = $this->apieContext->getContext(ApieDatalayer::class, false); |
| 44 | $serializer = $this->apieContext->getContext(Serializer::class, false); |
| 45 | if ($datalayer instanceof ApieDatalayer && $serializer instanceof Serializer) { |
| 46 | $list = $datalayer->all( |
| 47 | $this->actionDefinition->getResourceName(), |
| 48 | $this->apieContext->getContext(BoundedContextId::class, false) |
| 49 | ); |
| 50 | $totalCount = $list->getTotalCount(); |
| 51 | $files = []; |
| 52 | for ($i = 0; $i < $totalCount; $i+= GetResourceListPaginationFolder::ITEMS_PER_PAGE) { |
| 53 | $page = (int) floor($i / GetResourceListPaginationFolder::ITEMS_PER_PAGE); |
| 54 | $files[$page] = new GetResourceListPaginationFolder($list, $page, $serializer, $this->apieContext); |
| 55 | } |
| 56 | return new VirtualFileMap($files); |
| 57 | } |
| 58 | |
| 59 | return new VirtualFileMap(); |
| 60 | } |
| 61 | } |