diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 30a0caf..ce975a1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: - php: ['8.1'] + php: ['8.3'] steps: - name: Checkout Code diff --git a/CHANGELOG.md b/CHANGELOG.md index 76e95dd..f344995 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ===== * (feature) Add `SimpleNormalizer::normalizeMap()`. +* (feature) Add helper VO `ValueWithContext`. 1.1.1 diff --git a/composer.json b/composer.json index 79d2458..c908e93 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ ], "homepage": "https://github.com/21TORR/simple-normalizer", "require": { - "php": ">= 8.1", + "php": ">= 8.3", "21torr/bundle-helpers": "^2.1", "symfony/dependency-injection": "^6.1", "symfony/http-kernel": "^6.1" diff --git a/src/Data/ValueWithContext.php b/src/Data/ValueWithContext.php new file mode 100644 index 0000000..bf81786 --- /dev/null +++ b/src/Data/ValueWithContext.php @@ -0,0 +1,13 @@ +normalize( + $value->value, + \array_replace($context, $value->context), + ); + } + + + /** + * @inheritDoc + */ + public static function getNormalizedType () : string + { + return ValueWithContext::class; + } +} diff --git a/tests/Normalizer/ObjectNormalizer/ValueWithContextNormalizerTest.php b/tests/Normalizer/ObjectNormalizer/ValueWithContextNormalizerTest.php new file mode 100644 index 0000000..d27a351 --- /dev/null +++ b/tests/Normalizer/ObjectNormalizer/ValueWithContextNormalizerTest.php @@ -0,0 +1,49 @@ + "hai", + ], + ); + + $dummyNormalizer = $this->createMock(SimpleObjectNormalizerInterface::class); + $dummyNormalizer + ->expects(self::once()) + ->method("normalize") + ->with( + $value->value, + [ + "test" => 123, + "o" => "hai", + ], + ); + + $normalizer = new SimpleNormalizer(new ServiceLocator([ + ValueWithContext::class => fn () => new ValueWithContextNormalizer(), + DummyVO::class => fn () => $dummyNormalizer, + ])); + + $normalizer->normalize($value, [ + "test" => 123, + "o" => 5, + ]); + } +}