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

Lazy loading not working for parameters #26

Closed alganet closed 11 years ago

alganet commented 12 years ago

When an instantiator is passed to another instance by parameter (and possibly by other ways) it isn't being instantiated. This was introduced after 0.3.1.

nickl- commented 11 years ago

I think this is the fix you are looking for:

Given config

my_string = 'Hey you!'

[hello Respect\Config\MyLazyLoadedHelloWorld]
string = [my_string]

[consumer Respect\Config\MyLazyLoadedHelloWorldConsumer]
hello = [hello]

The following lazy load manipulation can be performed. (referred to internally as the overriding of configuration by container state)

        $expected  = 'Hello World!';
        $container = new Container($config);
        $container->my_string = $expected;
        $this->assertEquals($expected, (string) $container->hello);
        $container = new Container($config);
        $container->{"hello Respect\\Config\\MyLazyLoadedHelloWorld"} = array('string' => $expected);
        $this->assertEquals($expected, (string) $container->hello);
        $container = new Container($config);
        $container->hello = new MyLazyLoadedHelloWorld($expected);
        $this->assertEquals($expected, (string) $container->hello);

I think these are useful none the less but @alganet please confirm if it also addresses this issue.

alganet commented 11 years ago

Nice! It addresses =)

nickl- commented 11 years ago

Closed on confirmed success