-
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.
- Loading branch information
Showing
22 changed files
with
330 additions
and
243 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ build | |
coverage | ||
composer.lock | ||
/.php_cs.cache | ||
.phpunit.cache/ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
<phpunit bootstrap="test/bootstrap.php" colors="true"> | ||
<testsuite name="all"> | ||
<directory>test</directory> | ||
</testsuite> | ||
<logging> | ||
<log type="coverage-clover" target="build/logs/clover.xml"/> | ||
<log type="coverage-html" target="build/logs/coverage"/> | ||
</logging> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
<directory suffix=".php">./src</directory> | ||
</whitelist> | ||
</filter> | ||
<?xml version="1.0"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="test/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" cacheDirectory=".phpunit.cache"> | ||
<coverage> | ||
<report> | ||
<clover outputFile="build/logs/clover.xml"/> | ||
<html outputDirectory="build/logs/coverage"/> | ||
</report> | ||
</coverage> | ||
<testsuite name="all"> | ||
<directory>test</directory> | ||
</testsuite> | ||
<logging/> | ||
<source> | ||
<include> | ||
<directory suffix=".php">./src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CultuurNet\SearchV3\Serializer\Handler; | ||
|
||
use CultuurNet\SearchV3\Serializer\Serializer; | ||
use CultuurNet\SearchV3\ValueObjects\Collection; | ||
use CultuurNet\SearchV3\ValueObjects\Event; | ||
use CultuurNet\SearchV3\ValueObjects\Place; | ||
use JMS\Serializer\Context; | ||
use JMS\Serializer\GraphNavigator; | ||
use JMS\Serializer\Handler\SubscribingHandlerInterface; | ||
use JMS\Serializer\JsonDeserializationVisitor; | ||
|
||
final class CollectionHandler implements SubscribingHandlerInterface | ||
{ | ||
private $contextMapping = [ | ||
'/contexts/event' => Event::class, | ||
'/contexts/place' => Place::class, | ||
]; | ||
|
||
private $typeMapping = [ | ||
'Event' => Event::class, | ||
'Place' => Place::class, | ||
]; | ||
|
||
public static function getSubscribingMethods(): array | ||
{ | ||
return [ | ||
[ | ||
'direction' => GraphNavigator::DIRECTION_DESERIALIZATION, | ||
'format' => 'json', | ||
'type' => Collection::class, | ||
'method' => 'deserializeCultuurCollectionFromJson', | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @param array<string, mixed> $values | ||
* @param array<string, mixed> $type | ||
*/ | ||
public function deserializeCultuurCollectionFromJson(JsonDeserializationVisitor $visitor, array $values, array $type, Context $context): ?Collection | ||
{ | ||
$collection = new Collection(); | ||
$items = []; | ||
$serializer = new Serializer(); | ||
|
||
$metadata = []; | ||
foreach ($values as $member) { | ||
|
||
if (!isset($member['@context']) && !isset($member['@type'])) { | ||
continue; | ||
} | ||
|
||
if (isset($member['@context'])) { | ||
$class = $this->contextMapping[$member['@context']]; | ||
} else { | ||
$class = $this->typeMapping[$member['@type']]; | ||
} | ||
|
||
$object = $serializer->deserialize(json_encode($member), $class); | ||
|
||
$collection->addItem($object); | ||
} | ||
|
||
return $collection; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CultuurNet\SearchV3\Serializer\Handler; | ||
|
||
use CultuurNet\SearchV3\ValueObjects\FacetResult; | ||
use CultuurNet\SearchV3\ValueObjects\FacetResultItem; | ||
use CultuurNet\SearchV3\ValueObjects\FacetResults; | ||
use CultuurNet\SearchV3\ValueObjects\TranslatedString; | ||
use JMS\Serializer\Context; | ||
use JMS\Serializer\GraphNavigator; | ||
use JMS\Serializer\Handler\SubscribingHandlerInterface; | ||
use JMS\Serializer\JsonDeserializationVisitor; | ||
|
||
final class FacetResultsHandler implements SubscribingHandlerInterface | ||
{ | ||
public static function getSubscribingMethods(): array | ||
{ | ||
return [ | ||
[ | ||
'direction' => GraphNavigator::DIRECTION_DESERIALIZATION, | ||
'format' => 'json', | ||
'type' => FacetResults::class, | ||
'method' => 'deserializeFacetResultsFromJson', | ||
], | ||
]; | ||
} | ||
|
||
public function deserializeFacetResultsFromJson(JsonDeserializationVisitor $visitor, array $values, array $type, Context $context): ?FacetResults | ||
{ | ||
$facetResults = new FacetResults(); | ||
|
||
foreach ($values as $facetType => $results) { | ||
$facetResults->addFacetResult($facetType, new FacetResult($facetType, $this->deserializeResults($results))); | ||
} | ||
|
||
return $facetResults; | ||
} | ||
|
||
private function deserializeResults($results): array | ||
{ | ||
$items = []; | ||
foreach ($results as $value => $result) { | ||
$children = isset($result['children']) ? $this->deserializeResults($result['children']) : []; | ||
$items[] = new FacetResultItem($value, new TranslatedString($result['name']), $result['count'], $children); | ||
} | ||
return $items; | ||
} | ||
} |
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,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CultuurNet\SearchV3\Serializer\Handler; | ||
|
||
use CultuurNet\SearchV3\ValueObjects\Address; | ||
use CultuurNet\SearchV3\ValueObjects\TranslatedAddress; | ||
use JMS\Serializer\Context; | ||
use JMS\Serializer\GraphNavigator; | ||
use JMS\Serializer\Handler\SubscribingHandlerInterface; | ||
use JMS\Serializer\JsonDeserializationVisitor; | ||
|
||
final class TranslatedAddressHandler implements SubscribingHandlerInterface | ||
{ | ||
public static function getSubscribingMethods(): array | ||
{ | ||
return [ | ||
[ | ||
'direction' => GraphNavigator::DIRECTION_DESERIALIZATION, | ||
'format' => 'json', | ||
'type' => TranslatedAddress::class, | ||
'method' => 'deserializeStringFromJson', | ||
], | ||
]; | ||
} | ||
|
||
public function deserializeStringFromJson(JsonDeserializationVisitor $visitor, $values, array $type, Context $context): TranslatedAddress | ||
{ | ||
$translatedAddress = new TranslatedAddress(); | ||
|
||
|
||
foreach ($values as $key => $value) { | ||
if (is_array($value)) { | ||
$address = new Address( | ||
$value['addressCountry'], | ||
$value['addressLocality'], | ||
$value['postalCode'], | ||
$value['streetAddress'] | ||
); | ||
$translatedAddress->addAddress($key, $address); | ||
} | ||
} | ||
|
||
// Some properties are not translated yet in the api. We save these as nl. | ||
if (empty($this->addresses) && !empty($values)) { | ||
$address = new Address( | ||
$values['addressCountry'] ?? null, | ||
$values['addressLocality'] ?? null, | ||
$values['postalCode'] ?? null, | ||
$values['streetAddress'] ?? null | ||
); | ||
$translatedAddress->addAddress('nl', $address); | ||
} | ||
|
||
return $translatedAddress; | ||
} | ||
} |
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,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace CultuurNet\SearchV3\Serializer\Handler; | ||
|
||
use CultuurNet\SearchV3\ValueObjects\TranslatedString; | ||
use JMS\Serializer\Context; | ||
use JMS\Serializer\GraphNavigator; | ||
use JMS\Serializer\Handler\SubscribingHandlerInterface; | ||
use JMS\Serializer\JsonDeserializationVisitor; | ||
|
||
final class TranslatedStringHandler implements SubscribingHandlerInterface | ||
{ | ||
public static function getSubscribingMethods(): array | ||
{ | ||
return [ | ||
[ | ||
'direction' => GraphNavigator::DIRECTION_DESERIALIZATION, | ||
'format' => 'json', | ||
'type' => TranslatedString::class, | ||
'method' => 'deserializeStringFromJson', | ||
], | ||
]; | ||
} | ||
|
||
public function deserializeStringFromJson(JsonDeserializationVisitor $visitor, $value, array $type, Context $context): ?TranslatedString | ||
{ | ||
$translatedString = new TranslatedString(); | ||
|
||
$translatedString->setValues(is_array($value) ? $value : ['nl' => $value]); | ||
return $translatedString; | ||
} | ||
} |
Oops, something went wrong.