From 3f97154ba51a5b823c035c614166db283acb6f88 Mon Sep 17 00:00:00 2001 From: Jordi Kroon Date: Fri, 29 Nov 2019 12:45:02 +0100 Subject: [PATCH 1/2] Make properties on WordStrategy optional fixes #36 --- src/Hydrator/Strategy/WordsStrategy.php | 36 ++++++++++++++++++++----- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/Hydrator/Strategy/WordsStrategy.php b/src/Hydrator/Strategy/WordsStrategy.php index 0b93c68..82970cf 100644 --- a/src/Hydrator/Strategy/WordsStrategy.php +++ b/src/Hydrator/Strategy/WordsStrategy.php @@ -37,10 +37,22 @@ public function __construct() public function extract($value) { return array_map(function(Word $wordEntity) { + $textProperty = $wordEntity->getProperty() + ? $this->textPropertyStrategy->extract($wordEntity->getProperty()) + : null; + + $boundingBox = $wordEntity->getBoundingBox() + ? $this->boundingPolyStrategy->extract($wordEntity->getBoundingBox()) + : null; + + $symbols = $wordEntity->getSymbols() + ? $this->symbolsStrategy->extract($wordEntity->getSymbols()) + : null; + return array_filter([ - 'property' => $this->textPropertyStrategy->extract($wordEntity->getProperty()), - 'boundingBox' => $this->boundingPolyStrategy->extract($wordEntity->getBoundingBox()), - 'symbols' => $this->symbolsStrategy->extract($wordEntity->getSymbols()), + 'property' => $textProperty, + 'boundingBox' => $boundingBox, + 'symbols' => $symbols, ]); }, $value); } @@ -54,10 +66,22 @@ public function hydrate($value) $wordEntities = []; foreach ($value as $wordEntityInfo) { + $textProperty = isset($wordEntityInfo['property']) + ? $this->textPropertyStrategy->hydrate($wordEntityInfo['property']) + : null; + + $boundingBox = isset($wordEntityInfo['boundingBox']) + ? $this->boundingPolyStrategy->hydrate($wordEntityInfo['boundingBox']) + : null; + + $symbols = isset($wordEntityInfo['symbols']) + ? $this->symbolsStrategy->hydrate($wordEntityInfo['symbols']) + : null; + $wordEntities[] = new Word( - $this->textPropertyStrategy->hydrate($wordEntityInfo['property']), - $this->boundingPolyStrategy->hydrate($wordEntityInfo['boundingBox']), - $this->symbolsStrategy->hydrate($wordEntityInfo['symbols']) + $textProperty, + $boundingBox, + $symbols ); } From 235bb71a46b3e45a7bdcc948a5738903dfe6b2fe Mon Sep 17 00:00:00 2001 From: Jordi Kroon Date: Fri, 29 Nov 2019 12:48:10 +0100 Subject: [PATCH 2/2] Remove PHP 8.0 early beta check --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a288590..84e8efa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,5 @@ php: - '7.0' - '7.1' - '7.2' - - nightly install: - composer install