-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
279 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/Bridge/Symfony/Serializer/Normalizer/ExpressionNormalizer.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the yassg project. | ||
* | ||
* (c) sigwin.hr | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Sigwin\YASSG\Bridge\Symfony\Serializer\Normalizer; | ||
|
||
use Sigwin\YASSG\DatabaseProvider; | ||
use Symfony\Component\ExpressionLanguage\ExpressionLanguage; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; | ||
|
||
final class ExpressionNormalizer implements DenormalizerInterface | ||
{ | ||
private ExpressionLanguage $expressionLanguage; | ||
private DatabaseProvider $databaseProvider; | ||
|
||
public function __construct(ExpressionLanguage $expressionLanguage, DatabaseProvider $databaseProvider) | ||
{ | ||
$this->expressionLanguage = $expressionLanguage; | ||
$this->databaseProvider = $databaseProvider; | ||
} | ||
|
||
public function denormalize(mixed $data, string $type, string $format = null, array $context = []) | ||
{ | ||
/** @var string $data */ | ||
$value = $this->expressionLanguage->evaluate(mb_substr($data, 2), [ | ||
'provider' => $this->databaseProvider, | ||
]); | ||
|
||
/** | ||
* @var class-string $type | ||
* @phpstan-ignore-next-line | ||
*/ | ||
if (is_a($value, $type, false) === false) { | ||
throw new \LogicException(sprintf('Invalid value denormalized, %1$s expected, %2$s received', $type, get_debug_type($value))); | ||
} | ||
|
||
return $value; | ||
} | ||
|
||
public function supportsDenormalization(mixed $data, string $type, string $format = null): bool | ||
{ | ||
return \is_string($data) && str_starts_with($data, '@='); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.