Skip to content

Commit

Permalink
Using byref passing of the hydrated object
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocramius committed Jun 27, 2013
1 parent 711c58a commit 69b459c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public function __construct(array $propertyAccessors)
$this->setDocblock("@param \\ReflectionProperty[] \$propertyAccessors to hydrate private properties");
//$this->setParameter(new ParameterGenerator('propertyAccessors', 'array'));

$body = empty($propertyAccessors) ? '' : '$this->foobarbaztab = null; $values = & $this->foobarbaztab; ';
$body = empty($propertyAccessors) ? '' : '$values = & $this->foobarbaztab; $object = & $this->blargh;';

foreach ($propertyAccessors as $propertyAccessor) {
$originalProperty = $propertyAccessor->getOriginalProperty();

$body .= '$this->' . $propertyAccessor->getName()
. ' = \Closure::bind(function ($object) use ($values) { $object->'
. ' = \Closure::bind(function () use (& $values, & $object) { $object->'
. $originalProperty->getName() . ' = $values['
. var_export($originalProperty->getName(), true) . ']; }, null, '
. var_export($originalProperty->getDeclaringClass()->getName(), true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,11 @@ public function __construct(array $accessibleProperties, array $propertyAccessor
}

if (! empty($propertyAccessors)) {
$body .= "\n\$this->foobarbaztab = \$data;\n\n";
$body .= "\n\$this->foobarbaztab = \$data;\n\$this->blargh = \$object;\n\n";
}

foreach ($propertyAccessors as $propertyAccessor) {
// @todo object by reference?
$body .= '$this->'
. $propertyAccessor->getName()
. "->__invoke(\$object);\n";
$body .= '$this->' . $propertyAccessor->getName() . "->__invoke();\n";
}

$body .= "\nreturn \$object;";
Expand Down
1 change: 1 addition & 0 deletions src/ProxyManager/ProxyGenerator/HydratorGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ function (ReflectionMethod $method) use ($excluded) {
$classGenerator->addProperties($propertyAccessors);
if (! empty($propertyAccessors)) {
$classGenerator->addProperties(array('foobarbaztab'));
$classGenerator->addProperties(array('blargh'));
}
$classGenerator->addMethodFromGenerator(new Constructor($propertyAccessors));
$classGenerator->addMethodFromGenerator(new Hydrate($accessibleProperties, $propertyAccessors));
Expand Down

0 comments on commit 69b459c

Please sign in to comment.