Skip to content

Commit

Permalink
Merge pull request #37 from jordikroon/fix-word-strategy-indexes
Browse files Browse the repository at this point in the history
Make properties on WordStrategy optional fixes #36
  • Loading branch information
jordikroon authored Nov 29, 2019
2 parents 06e456e + 235bb71 commit 59077c1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ php:
- '7.0'
- '7.1'
- '7.2'
- nightly
install:
- composer install
36 changes: 30 additions & 6 deletions src/Hydrator/Strategy/WordsStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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
);
}

Expand Down

0 comments on commit 59077c1

Please sign in to comment.