Resolve classes if callable has no object-context
Opened this issue · 0 comments
filecage commented
It is unsupported to pass a callable to invoke()
that is missing the object context:
creator/lib/InvokableClosure.php
Lines 21 to 25 in 6da60f9
Creator should resolve the object (if it's non-static) and then call the invokable instead of throwing an exception.
Example test case that should pass:
class Foo {
function __construct($bar) {
$this->bar = $bar;
}
}
class BarTransformer {
function transform ($bar) {
return strtoupper($bar);
}
}
class AnyClass {
static function bax (Foo $foo, BarTransformer $barTransformer) {
return $barTransformer->transform($foo->bar);
}
function __construct(Foo $foo) {
$this->foo = $foo;
}
function bar (BarTransformer $barTransformer) {
return $barTransformer->transform($this->foo->bar);
}
}
$creator = new Creator();
$creator->registerClassResource(new Foo('hello world'));
echo $creator->invoke(['AnyClass', 'bax']);
echo $creator->invoke(['AnyClass', 'bar']);
Should output
HELLO WORLD
twice, the first invocation should not register a class resource as the method is only called statically.