Skip to content

Commit

Permalink
Merge pull request #32 from jordikroon/fix/31
Browse files Browse the repository at this point in the history
Fix Undefined index in ParagraphsStrategy
  • Loading branch information
jordikroon authored Aug 20, 2018
2 parents 513c51d + a6027d3 commit 7adfec6
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 16 deletions.
38 changes: 29 additions & 9 deletions src/Hydrator/Strategy/ParagraphsStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down
28 changes: 21 additions & 7 deletions src/Hydrator/Strategy/SymbolsStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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
);
}

Expand Down

0 comments on commit 7adfec6

Please sign in to comment.