diff --git a/src/Hydrator/Strategy/ParagraphsStrategy.php b/src/Hydrator/Strategy/ParagraphsStrategy.php index 7a08f77..9636b6d 100644 --- a/src/Hydrator/Strategy/ParagraphsStrategy.php +++ b/src/Hydrator/Strategy/ParagraphsStrategy.php @@ -36,10 +36,23 @@ public function __construct() public function extract($value) { return array_map(function(Paragraph $paragraphEntity) { + $textProperty = $paragraphEntity->getProperty() + ? $this->textPropertyStrategy->extract($paragraphEntity->getProperty()) + : null; + + $boundingBox = $paragraphEntity->getBoundingBox() + ? $this->boundingPolyStrategy->extract($paragraphEntity->getBoundingBox()) + : null; + + $words = $paragraphEntity->getWords() + ? $this->wordsStrategy->extract($paragraphEntity->getWords()) + : null; + + return array_filter([ - 'property' => $this->textPropertyStrategy->extract($paragraphEntity->getProperty()), - 'boundingBox' => $this->boundingPolyStrategy->extract($paragraphEntity->getBoundingBox()), - 'words' => $this->wordsStrategy->extract($paragraphEntity->getWords()), + 'property' => $textProperty, + 'boundingBox' => $boundingBox, + 'words' => $words, ]); }, $value); } @@ -51,13 +64,20 @@ public function extract($value) public function hydrate($value) { $paragraphEntities = []; - foreach ($value as $paragraphEntityInfo) { - $paragraphEntities[] = new Paragraph( - $this->textPropertyStrategy->hydrate($paragraphEntityInfo['property']), - $this->boundingPolyStrategy->hydrate($paragraphEntityInfo['boundingBox']), - $this->wordsStrategy->hydrate($paragraphEntityInfo['words']) - ); + $textProperty = isset($paragraphEntityInfo['property']) + ? $this->textPropertyStrategy->hydrate($paragraphEntityInfo['property']) + : null; + + $boundingBox = isset($paragraphEntityInfo['boundingBox']) + ? $this->boundingPolyStrategy->hydrate($paragraphEntityInfo['boundingBox']) + : null; + + $words = isset($paragraphEntityInfo['words']) + ? $this->wordsStrategy->hydrate($paragraphEntityInfo['words']) + : null; + + $paragraphEntities[] = new Paragraph($textProperty, $boundingBox, $words); } return $paragraphEntities; diff --git a/src/Hydrator/Strategy/SymbolsStrategy.php b/src/Hydrator/Strategy/SymbolsStrategy.php index 017520c..f3b605f 100644 --- a/src/Hydrator/Strategy/SymbolsStrategy.php +++ b/src/Hydrator/Strategy/SymbolsStrategy.php @@ -2,9 +2,7 @@ namespace Vision\Hydrator\Strategy; -use Vision\Annotation\Paragraph; use Vision\Annotation\Symbol; -use Vision\Annotation\Word; use Zend\Hydrator\Strategy\StrategyInterface; class SymbolsStrategy implements StrategyInterface @@ -32,9 +30,17 @@ public function __construct() public function extract($value) { return array_map(function(Symbol $symbolEntity) { + $textProperty = $symbolEntity->getProperty() + ? $this->textPropertyStrategy->extract($symbolEntity->getProperty()) + : null; + + $boundingBox = $symbolEntity->getBoundingBox() + ? $this->boundingPolyStrategy->extract($symbolEntity->getBoundingBox()) + : null; + return array_filter([ - 'property' => $this->textPropertyStrategy->extract($symbolEntity->getProperty()), - 'boundingBox' => $this->boundingPolyStrategy->extract($symbolEntity->getBoundingBox()), + 'property' => $textProperty, + 'boundingBox' => $boundingBox, 'text' => $symbolEntity->getText(), ]); }, $value); @@ -49,10 +55,18 @@ public function hydrate($value) $symbolEntities = []; foreach ($value as $symbolEntityInfo) { + $textProperty = isset($symbolEntityInfo['property']) + ? $this->textPropertyStrategy->hydrate($symbolEntityInfo['property']) + : null; + + $boundingBox = isset($symbolEntityInfo['boundingBox']) + ? $this->boundingPolyStrategy->hydrate($symbolEntityInfo['boundingBox']) + : null; + $symbolEntities[] = new Symbol( - $this->textPropertyStrategy->hydrate($symbolEntityInfo['property']), - $this->boundingPolyStrategy->hydrate($symbolEntityInfo['boundingBox']), - $symbolEntityInfo['text'] + $textProperty, + $boundingBox, + isset($symbolEntityInfo['text']) ? $symbolEntityInfo['text'] : null ); }