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

Treat unset variables as parameters + Cross-container communication #28

Closed alganet closed 11 years ago

alganet commented 12 years ago

Given a config like:

[conn Pdo]

The current behavior of config is throw an Exception if we try to $container->conn. This proposal is to add a __callable interface to Config and allow things like $container->conn(array('dsn'=>'sqlite::memory:'));'for the above ini to work properly.

This would also be the primary way of cross-container communication:

[conn_params]
dsn = sqlite::memory: 

[conn Respect\Config\Container]
loadFile[] = pdo.ini
conn[]     = [conn_params]      

Maybe eds could use this as well to declare inter-dependencies between files.

nickl- commented 11 years ago

Sounds awesome but unfortunately I am not following completely.

We can now do

$container->{"conn Pdo"} = array(
    'dsn' => 'sqlite::memory:', 
);
/** to overwrite any configurations before calling */

$container->conn;

We can also overwrite the configuration and bypass the Instantiator completely with something like:

$container->conn = new \PDO('sqlite::memory:');

Does this satisfy the requirement here?

alganet commented 11 years ago

I've implemented something similar as Locked Containers (undocumented I believe), but tested:

https://github.com/Respect/Config/blob/develop/tests/library/Respect/Config/ContainerTest.php#L311

As usual with older issues, I forgot to close this.

nickl- commented 11 years ago

sweet... :panda_face: another one dusted!