Skip to content

Commit

Permalink
Remove static closure workaround (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
andig committed Mar 6, 2019
1 parent 7a778a5 commit b25639a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
20 changes: 0 additions & 20 deletions src/ClosureHelper.php

This file was deleted.

5 changes: 3 additions & 2 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public static function bindAndCall(callable $fn, $newThis, $args = [], $bindClas
*/
public static function hijackProperty($object, $propertyName, $newValue)
{
$closure = (new ClosureHelper())->getPropertyAccessor($propertyName, $newValue);
Utils::bindAndCall($closure, $object);
Utils::bindAndCall(function () use ($object, $propertyName, $newValue) {
$object->$propertyName = $newValue;
}, $object);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions tests/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,15 @@ public function testParseQueryPath($path, $expected)
{
$this->assertEquals($expected, Utils::parseQueryPath($path));
}

public function testHijackProperty()
{
$object = new \PHPPM\SlavePool();
Utils::hijackProperty($object, 'slaves', ['SOME VALUE']);

$r = new \ReflectionObject($object);
$p = $r->getProperty('slaves');
$p->setAccessible(true);
$this->assertEquals(['SOME VALUE'], $p->getValue($object));
}
}

0 comments on commit b25639a

Please sign in to comment.