Respect / Config

A powerful, small, deadly simple configurator and dependency injection container DSL made to be easy
http://respect.github.io/Config
Other
98 stars 7 forks source link

Instantiator should not implement __invoke() #24

Closed augustohp closed 11 years ago

augustohp commented 12 years ago

Because if it encapsulates an object that implements it, this prevents the __invoke() be runned into the object.

alganet commented 12 years ago

$votes++;

Maybe this will fix an issue I had with Symfony HttpKernel and route callbacks.

nickl- commented 11 years ago

I am not following, perhaps a use case or example of the problem.

__invoke will continue to be inherited by subclasses.

php> class ABC {
 ...     function __invoke() {
 ...         echo "I am invoked ".get_class($this);
 ...     }
 ... }
php> class DEF extends ABC {}
php> $a = new ABC;
php> $b = new DEF;
php> $a();
I am invoked ABC
php> $b();
I am invoked DEF
alganet commented 11 years ago

That's because Instantiator doesn't extend the class he is supposed to instantiate. The testcase is something like:

<?php
class Foo {
public $hello;
function __invoke() { return $this->hello; }
function setHello($hello) {$this->hello = $hello;}
}
$c = new Container(parse_ini_string('
[foo Foo]
setHello[] = [Hello Pandas]
'));
$helloCallable = $c->foo;
print $helloCallable(); //Hello Pandas