Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| HtmlContainer | |
100.00% |
11 / 11 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| has | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @author: Doug Wilbourne (dougwilbourne@gmail.com) |
| 5 | */ |
| 6 | |
| 7 | declare(strict_types=1); |
| 8 | |
| 9 | namespace pvc\html\factory; |
| 10 | |
| 11 | use League\Container\Container; |
| 12 | use League\Container\Definition\Definition; |
| 13 | use League\Container\Definition\DefinitionAggregate; |
| 14 | use League\Container\ReflectionContainer; |
| 15 | use Psr\Container\ContainerExceptionInterface; |
| 16 | use Psr\Container\ContainerInterface; |
| 17 | use Psr\Container\NotFoundExceptionInterface; |
| 18 | use pvc\frmtr\msg\MsgFrmtr; |
| 19 | use pvc\html\content_model\ContentModelNothing; |
| 20 | use pvc\interfaces\struct\tree\node\TreenodeInterface; |
| 21 | |
| 22 | /** |
| 23 | * Class HtmlContainer |
| 24 | */ |
| 25 | class HtmlContainer implements ContainerInterface |
| 26 | { |
| 27 | /** |
| 28 | * @var Container |
| 29 | */ |
| 30 | protected Container $leagueContainer; |
| 31 | |
| 32 | protected string $definitionsFile = __DIR__ . '/' . 'LeagueDefinitions.php'; |
| 33 | |
| 34 | public function __construct(?string $leagueDefinitionFile = null) |
| 35 | { |
| 36 | /** @var array<Definition> $defs */ |
| 37 | $defs = include($leagueDefinitionFile ?? $this->definitionsFile); |
| 38 | $aggregate = new DefinitionAggregate($defs); |
| 39 | $this->leagueContainer = new Container($aggregate); |
| 40 | |
| 41 | /** |
| 42 | * in addition to being able to make Elements (and their component objects), |
| 43 | * the container also needs to be able to make a DomNode of type text |
| 44 | */ |
| 45 | $textNodeDef = (new Definition('pvc\html\text_node\TextElement')) |
| 46 | ->addArgument(MsgFrmtr::class); |
| 47 | $this->leagueContainer->add($textNodeDef->getAlias(), $textNodeDef); |
| 48 | |
| 49 | |
| 50 | /** |
| 51 | * add the html factory definition |
| 52 | */ |
| 53 | $this->leagueContainer->add(HtmlFactory::class) |
| 54 | ->addArgument(Container::class); |
| 55 | |
| 56 | /** |
| 57 | * enable autowiring |
| 58 | */ |
| 59 | $this->leagueContainer->delegate(new ReflectionContainer()); |
| 60 | |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * has |
| 65 | * @param string $id |
| 66 | * @return bool |
| 67 | */ |
| 68 | public function has(string $id): bool |
| 69 | { |
| 70 | return $this->leagueContainer->has($id); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * get |
| 75 | * @param string $id |
| 76 | * @return mixed |
| 77 | * @throws ContainerExceptionInterface |
| 78 | * @throws NotFoundExceptionInterface |
| 79 | */ |
| 80 | public function get(string $id): mixed |
| 81 | { |
| 82 | return $this->leagueContainer->get($id); |
| 83 | } |
| 84 | } |