Closed designermonkey closed 9 years ago
I can however see one benefit to this method, and that is that I can define my services within the $values
array.
Hmmm, I can't decide which I prefer.
The functionality was changed a few weeks ago to allow slim users to define container services at the root level.
I think you hinted on this... it is not possible to define container services \o/ during construction of the container
before the change
new Container(include "../containerConfig.php");
would place everything into a key 'settings' not allowing for MyClass::class resolution without marking the service ['setting'] in front of it... Making you either access the settings for your app's services (Silly) or define the services after container construction.
After the change you can define services in your config file like... You can even set your own settings by just placing them into the settings key
return [
"settings" => [
//... your settings
],
MyClass::class => function ($c) {
return new MyClass();
}
];
Regarding your setting changes... you can see what would happen here. https://github.com/slimphp/Slim/blob/3.x/Slim/Container.php#L96-L98
$this['settings'] = function ($c) use ($userSettings, $defaultSettings) {
return array_merge($defaultSettings, $userSettings);
};
I believe the precedence is right to left so your defaults override the slim defaults.
I'll leave this alone then, as I missed the change. It's fine to have it this way. Thanks for the info!
Looking at the
Container
code, I see the followingI was under the impression that any settings we need to provide to Slim are just an array, not an array with a key of
settings
, which this container code is expecting?In @akrabat's example repository here, settings is as I would expect, a simple array.
Shouldn't the
$values
not be passed through to Pimple, and the$userSettings
be declared as suchOtherwise, as I add keys to my settings array to match my services, like
logger
for example, when I come to declare mylogger
service, the key already exists in the container, and I will overwrite the settings with a service?