Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| DateTimeComponentProvider | |
100.00% |
13 / 13 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
| supports | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
5 | |||
| createComponentFor | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\HtmlBuilders\Factories\Concrete; |
| 3 | |
| 4 | use Apie\Core\Attributes\CmsSingleInput; |
| 5 | use Apie\HtmlBuilders\Components\Forms\SingleInput; |
| 6 | use Apie\HtmlBuilders\FormBuildContext; |
| 7 | use Apie\HtmlBuilders\Interfaces\ComponentInterface; |
| 8 | use Apie\HtmlBuilders\Interfaces\FormComponentProviderInterface; |
| 9 | use DateTimeInterface; |
| 10 | use ReflectionClass; |
| 11 | use ReflectionNamedType; |
| 12 | use ReflectionType; |
| 13 | |
| 14 | /** |
| 15 | * Renders a date field. |
| 16 | */ |
| 17 | class DateTimeComponentProvider implements FormComponentProviderInterface |
| 18 | { |
| 19 | public function supports(ReflectionType $type, FormBuildContext $context): bool |
| 20 | { |
| 21 | if ($type instanceof ReflectionNamedType && !$type->isBuiltin()) { |
| 22 | if (class_exists($type->getName()) || interface_exists($type->getName())) { |
| 23 | $refl = new ReflectionClass($type->getName()); |
| 24 | return $refl->implementsInterface(DateTimeInterface::class); |
| 25 | } |
| 26 | } |
| 27 | return false; |
| 28 | } |
| 29 | public function createComponentFor(ReflectionType $type, FormBuildContext $context): ComponentInterface |
| 30 | { |
| 31 | return new SingleInput( |
| 32 | $context->getFormName(), |
| 33 | $context->getFilledInValue(), |
| 34 | $context->createTranslationLabel(), |
| 35 | $type->allowsNull(), |
| 36 | $type, |
| 37 | new CmsSingleInput(['datetime']) |
| 38 | ); |
| 39 | } |
| 40 | } |