Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make ObjectIterator compatible with Doctrine Collections
Ensure Collection::get() hydrates a document Handle conversion in ObjectIterator::first() and ObjectIterator::last() Handle conversion for ObjectIterator methods that return values Add tests for ObjectCallbackIterator CS fixes for ObjectIterator
- Loading branch information
Showing
11 changed files
with
409 additions
and
128 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
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,57 @@ | ||
<?php | ||
|
||
namespace ONGR\ElasticsearchBundle\Result; | ||
|
||
class ObjectCallbackIterator extends \ArrayIterator | ||
{ | ||
/** | ||
* @var \Closure | ||
*/ | ||
private $callback; | ||
|
||
/** | ||
* Converts array data to document objects via the callback function. | ||
* | ||
* @param \Closure $callback | ||
* @param array $array | ||
*/ | ||
public function __construct(\Closure $callback, array $array = array()) | ||
{ | ||
$this->callback = $callback; | ||
|
||
parent::__construct($array); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function current() | ||
{ | ||
$value = parent::current(); | ||
|
||
// Generate objects on demand | ||
if ($value === null && $this->valid()) { | ||
$key = $this->key(); | ||
$callback = $this->callback; | ||
return $callback($key); | ||
} | ||
|
||
return $value; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function offsetGet($offset) | ||
{ | ||
$value = parent::offsetGet($offset); | ||
|
||
// Generate objects on demand | ||
if ($value === null && $this->valid()) { | ||
$callback = $this->callback; | ||
return $callback($offset); | ||
} | ||
|
||
return $value; | ||
} | ||
} |
Oops, something went wrong.