-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: custom bundle / normalizers (#176)
* docs: cleanup * docs: example of using a custom bundle / normalizers * docs: example of using a custom bundle / normalizers * docs: example of using a custom bundle / normalizers * docs: example of using a custom bundle / normalizers * docs: example of using a custom bundle / normalizers * docs: example of using a custom bundle / normalizers * fix: mark ArrayReference annotation as used * fix: mark ArrayReference annotation as used
- Loading branch information
Showing
13 changed files
with
133 additions
and
49 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
60 changes: 60 additions & 0 deletions
60
src/Xezilaires/Test/ExampleBundle/Serializer/ProductNormalizer.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,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the xezilaires 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 Xezilaires\Test\ExampleBundle\Serializer; | ||
|
||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; | ||
use Xezilaires\Test\Model\Product; | ||
|
||
final class ProductNormalizer implements DenormalizerInterface | ||
{ | ||
public function denormalize(mixed $data, string $type, string $format = null, array $context = []): object | ||
{ | ||
/** | ||
* @phpstan-ignore-next-line | ||
* | ||
* @psalm-suppress MixedArrayAccess | ||
*/ | ||
if (isset($data['all'][1])) { | ||
/** | ||
* @phpstan-ignore-next-line | ||
* | ||
* @psalm-suppress MixedArgument | ||
* @psalm-suppress MixedArrayAccess | ||
* @psalm-suppress MixedArrayAssignment | ||
*/ | ||
$data['all'][1] = $this->cast($data['all'][1]); | ||
} | ||
|
||
/** | ||
* @phpstan-ignore-next-line | ||
* | ||
* @psalm-suppress MixedArgument | ||
* @psalm-suppress MixedArrayAccess | ||
* @psalm-suppress MixedArrayAssignment | ||
*/ | ||
$data['price'] = $this->cast($data['price']); | ||
|
||
return (object) $data; | ||
} | ||
|
||
public function supportsDenormalization(mixed $data, string $type, string $format = null): bool | ||
{ | ||
return $type === Product::class; | ||
} | ||
|
||
private function cast(string $price): float | ||
{ | ||
return (float) filter_var($price, \FILTER_SANITIZE_NUMBER_FLOAT, \FILTER_FLAG_ALLOW_FRACTION); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/Xezilaires/Test/ExampleBundle/XezilairesExampleBundle.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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the xezilaires 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 Xezilaires\Test\ExampleBundle; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
use Symfony\Component\HttpKernel\Bundle\AbstractBundle; | ||
|
||
final class XezilairesExampleBundle extends AbstractBundle | ||
{ | ||
public function loadExtension(array $config, ContainerConfigurator $container, ContainerBuilder $builder): void | ||
{ | ||
$services = $container->services(); | ||
$services | ||
->defaults() | ||
->autoconfigure() | ||
->autowire() | ||
; | ||
$services->load(__NAMESPACE__.'\\', __DIR__); | ||
} | ||
} |
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