Created
July 10, 2013 13:41
-
-
Save bakura10/5966362 to your computer and use it in GitHub Desktop.
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
/** | |
* The task is to rewrite the Hydrator component using the RecursiveIteratorIterator stuff. This will allow us A LOT | |
* of nice stuff, while being able to still have speed thanks to the C implementation. The most important things of | |
* using RecursiveIteratorIterator is to allow the usage of setMaxDepth, as well as plug FilterIterator (current hydrator | |
* filters are slow) | |
* | |
* The idea is to allow the hydrators recursively hydrate other things. For instance, if we have: | |
*/ | |
class ObjectA | |
{ | |
public $varA = 'bar'; | |
public $varB = null; | |
public function __construct() | |
{ | |
$this->varB = new ObjectB(); | |
} | |
} | |
class ObjectB | |
{ | |
public $varC = 'foo'; | |
} | |
// We need to be able to do: | |
$hydrator = new ObjectPropertyHydrator(); | |
$extract = $hydrator->extract(new ObjectA(), true); // true for recursive. Also can specify a maxDepth | |
var_dump($extract); // Should output array('varA' => 'bar', 'varB' => array('varC' => 'foo')); | |
// Under the hood, everything will be using RecursiveIteratorIterator, even if the user does not want recursiveness. | |
// It will just automatically set setMaxDepth(0) if user does not want recursive. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment