Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
16.67% |
2 / 12 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| FileUploadComponentProvider | |
16.67% |
2 / 12 |
|
50.00% |
1 / 2 |
13.26 | |
0.00% |
0 / 1 |
| supports | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
3 | |||
| createComponentFor | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | namespace Apie\HtmlBuilders\Factories\Concrete; |
| 3 | |
| 4 | use Apie\Core\Attributes\CmsSingleInput; |
| 5 | use Apie\Core\Utils\ConverterUtils; |
| 6 | use Apie\HtmlBuilders\Components\Forms\SingleInput; |
| 7 | use Apie\HtmlBuilders\FormBuildContext; |
| 8 | use Apie\HtmlBuilders\Interfaces\ComponentInterface; |
| 9 | use Apie\HtmlBuilders\Interfaces\FormComponentProviderInterface; |
| 10 | use Psr\Http\Message\UploadedFileInterface; |
| 11 | use ReflectionType; |
| 12 | |
| 13 | final class FileUploadComponentProvider implements FormComponentProviderInterface |
| 14 | { |
| 15 | public function supports(ReflectionType $type, FormBuildContext $context): bool |
| 16 | { |
| 17 | $class = ConverterUtils::toReflectionClass($type); |
| 18 | return $class && ($class->name === UploadedFileInterface::class || in_array(UploadedFileInterface::class, $class->getInterfaceNames())); |
| 19 | } |
| 20 | public function createComponentFor(ReflectionType $type, FormBuildContext $context): ComponentInterface |
| 21 | { |
| 22 | return new SingleInput( |
| 23 | $context->getFormName(), |
| 24 | $context->getFilledInValue(), |
| 25 | $context->createTranslationLabel(), |
| 26 | $type->allowsNull(), |
| 27 | $type, |
| 28 | new CmsSingleInput( |
| 29 | ['file'] |
| 30 | ) |
| 31 | ); |
| 32 | } |
| 33 | } |