Skip to content

Instantly share code, notes, and snippets.

@bakura10
Created July 10, 2013 13:41
Show Gist options
  • Save bakura10/5966362 to your computer and use it in GitHub Desktop.
Save bakura10/5966362 to your computer and use it in GitHub Desktop.
/**
* 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