-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into III-6396-title-translated
# Conflicts: # tests/BackwardsCompatiblePayloadSerializerFactoryTest.php
- Loading branch information
Showing
25 changed files
with
557 additions
and
362 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,6 @@ end_of_line = lf | |
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[*.feature] | ||
indent_size = 2 |
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
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
33 changes: 33 additions & 0 deletions
33
src/Model/Serializer/ValueObject/Price/TariffDenormalizer.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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CultuurNet\UDB3\Model\Serializer\ValueObject\Price; | ||
|
||
use CultuurNet\UDB3\Model\ValueObject\Price\Tariff; | ||
use CultuurNet\UDB3\Model\ValueObject\Price\TranslatedTariffName; | ||
use CultuurNet\UDB3\MoneyFactory; | ||
use Money\Currency; | ||
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface; | ||
|
||
final class TariffDenormalizer implements DenormalizerInterface | ||
{ | ||
public function denormalize($data, $class, $format = null, array $context = []): Tariff | ||
{ | ||
/** @var TranslatedTariffName $tariffName */ | ||
$tariffName = (new TranslatedTariffNameDenormalizer())->denormalize( | ||
$data['name'], | ||
TranslatedTariffName::class | ||
); | ||
|
||
return new Tariff( | ||
$tariffName, | ||
MoneyFactory::createFromCents($data['price'], new Currency($data['currency'])) | ||
); | ||
} | ||
|
||
public function supportsDenormalization($data, $type, $format = null): bool | ||
{ | ||
return $type === Tariff::class; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Model/Serializer/ValueObject/Price/TariffNormalizer.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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CultuurNet\UDB3\Model\Serializer\ValueObject\Price; | ||
|
||
use CultuurNet\UDB3\Model\ValueObject\Price\Tariff; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
final class TariffNormalizer implements NormalizerInterface | ||
{ | ||
/** | ||
* @param Tariff $tariff | ||
*/ | ||
public function normalize($tariff, $format = null, array $context = []): array | ||
{ | ||
return [ | ||
'name' => (new TranslatedTariffNameNormalizer())->normalize($tariff->getName()), | ||
'price' => $tariff->getPrice()->getAmount(), | ||
'currency' => $tariff->getPrice()->getCurrency()->getName(), | ||
]; | ||
} | ||
|
||
public function supportsNormalization($data, $format = null): bool | ||
{ | ||
return $data === Tariff::class; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Model/Serializer/ValueObject/Price/TranslatedTariffNameNormalizer.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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CultuurNet\UDB3\Model\Serializer\ValueObject\Price; | ||
|
||
use CultuurNet\UDB3\Model\Serializer\ValueObject\Translation\TranslatedValueObjectNormalizer; | ||
use CultuurNet\UDB3\Model\ValueObject\Price\TranslatedTariffName; | ||
|
||
final class TranslatedTariffNameNormalizer extends TranslatedValueObjectNormalizer | ||
{ | ||
public function supportsNormalization($data, $format = null): bool | ||
{ | ||
return $data === TranslatedTariffName::class; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/Model/Serializer/ValueObject/Translation/TranslatedValueObjectNormalizer.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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CultuurNet\UDB3\Model\Serializer\ValueObject\Translation; | ||
|
||
use CultuurNet\UDB3\Model\ValueObject\Translation\Language; | ||
use CultuurNet\UDB3\Model\ValueObject\Translation\TranslatedValueObject; | ||
use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
|
||
abstract class TranslatedValueObjectNormalizer implements NormalizerInterface | ||
{ | ||
/** | ||
* @param TranslatedValueObject $object | ||
*/ | ||
public function normalize($object, $format = null, array $context = []): array | ||
{ | ||
$data = []; | ||
|
||
/** @var Language $language */ | ||
foreach ($object->getLanguages() as $language) { | ||
$data[$language->toString()] = $object->getTranslation($language)->toString(); | ||
} | ||
|
||
return $data; | ||
} | ||
} |
Oops, something went wrong.