Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
OptionsComponentProvider
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 supports
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 createComponentFor
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2namespace Apie\HtmlBuilders\Factories\Concrete;
3
4use Apie\Core\Attributes\CmsSingleInput;
5use Apie\Core\Dto\CmsInputOption;
6use Apie\Core\Metadata\MetadataFactory;
7use Apie\HtmlBuilders\Components\Forms\SingleInput;
8use Apie\HtmlBuilders\FormBuildContext;
9use Apie\HtmlBuilders\Interfaces\ComponentInterface;
10use Apie\HtmlBuilders\Interfaces\FormComponentProviderInterface;
11use ReflectionType;
12
13class OptionsComponentProvider implements FormComponentProviderInterface
14{
15    public function supports(ReflectionType $type, FormBuildContext $context): bool
16    {
17        $metadata = MetadataFactory::getCreationMetadata($type, $context->getApieContext());
18        return !empty($metadata->getValueOptions($context->getApieContext(), true)?->toArray());
19    }
20
21    public function createComponentFor(ReflectionType $type, FormBuildContext $context): ComponentInterface
22    {
23        $options = MetadataFactory::getCreationMetadata($type, $context->getApieContext())
24            ->getValueOptions($context->getApieContext(), true);
25        return new SingleInput(
26            $context->getFormName(),
27            $context->getFilledInValue(),
28            $context->createTranslationLabel(),
29            $type->allowsNull(),
30            $type,
31            new CmsSingleInput(
32                ['select'],
33                new CmsInputOption(
34                    options: $options
35                )
36            )
37        );
38    }
39}