Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 7 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| Base64Blob | |
0.00% |
0 / 7 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
| convertToDatabaseValue | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| convertToPHPValue | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Satag\AmicronEntityBundle\Doctrine; |
| 6 | |
| 7 | use Doctrine\DBAL\Platforms\AbstractPlatform; |
| 8 | use Doctrine\DBAL\Types\BlobType; |
| 9 | use Doctrine\DBAL\Types\ConversionException; |
| 10 | |
| 11 | class Base64Blob extends BlobType |
| 12 | { |
| 13 | /** |
| 14 | * @return false|string|null |
| 15 | */ |
| 16 | #[\Override] |
| 17 | public function convertToDatabaseValue($value, AbstractPlatform $platform): mixed |
| 18 | { |
| 19 | if ($value !== null) { |
| 20 | return base64_decode((string) $value, true); |
| 21 | } |
| 22 | |
| 23 | return null; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * @return string|null |
| 28 | * |
| 29 | * @throws ConversionException |
| 30 | * @throws ConversionException |
| 31 | */ |
| 32 | #[\Override] |
| 33 | public function convertToPHPValue($value, AbstractPlatform $platform): mixed |
| 34 | { |
| 35 | $stream = parent::convertToPHPValue($value, $platform); |
| 36 | if (\is_resource($stream)) { |
| 37 | return base64_encode((string) stream_get_contents($stream)); |
| 38 | } |
| 39 | |
| 40 | return null; |
| 41 | } |
| 42 | } |