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

Fix container setting closure #42

Closed filhodanuvem closed 9 years ago

filhodanuvem commented 10 years ago

Hi again! I think that a feature documented on README is not working. I wrote the same example found in the doc:

conf.ini:

db_driver = "mysql"
db_host   = "localhost"
db_name   = "my_database"
db_user   = "my_user"
db_pass   = "my_pass"
db_dsn    = "[db_driver]:host=[db_host];dbname=[db_name]"

index.php:

<?php

require __DIR__.'/vendor/autoload.php';

$c = new Respect\Config\Container(__DIR__.'/conf.ini');
$c->connection = function() use($c) {
    return new PDO($c->db_dsn, $c->db_user, $c->db_pass);
};
echo get_class($c->connection); 

And I had...

PHP Warning:  trim() expects parameter 1 to be string, object given in library/Respect/Config/Container.php on line 272

... 
PHP Fatal error:  Uncaught exception 'InvalidArgumentException' with message 'Item connection not found' in library/Respect/Config/Container.php:103

If you create a container object without pass a file/string on constructor, it works.

well, I created a test case (use it to break tests of version 1.0.1) and a possible fix.

:cloud:

henriquemoody commented 9 years ago

Thanks for that and I'm sorry by our late.