slimphp / Slim

Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
http://slimframework.com
MIT License
11.94k stars 1.95k forks source link

Refactor app settings out of container #2099

Closed codeguy closed 7 years ago

codeguy commented 7 years ago

Largely affects the App class.

codeguy commented 7 years ago

The point of this issue is to move settings management into the App class and away from reliance on the container. Like other major objects, folks can still use an external DIC to resolve the settings, but the resolved settings must still be injected into the App instance either during construction or after construction via a setter method.

I'll leave the App constructor alone for now, but I am going to add a public interface to the App class to manage settings. Some proposed methods include:

Internally, settings will be a Collection instance.

akrabat commented 7 years ago

What settings do we have? i.e. Do we need a collection at all?

codeguy commented 7 years ago

Actually, it seems to be just a single-dimensional array. So yeah, we can probably avoid the Collection instance and just use an array. 👍

kminek commented 7 years ago

i'm against storing settings as plain array. storing settings (and referring to settings) via collection object is better idea as it implements collection interface and objects are passed by reference everywhere. this way i could implement custom settings object which for instance reads json, xml, whatever files and pass it to App.

geekish commented 7 years ago

Agreeing with @kminek here... I use an extended Collection class for the settings so I can use my container of choice to inject it where I need it (example).

kdubuc commented 7 years ago

https://github.com/slimphp/Slim/issues/1923 is related, no ?

Anyway, I copy paste my reply here :

What do you think about a Kernel which can be provided in the Slim constructor.

I build one : https://github.com/kdubuc/api/blob/master/src/Kernel.php

The code isn't finalized, it is under active development, but the foundations are here 😉

ghost commented 7 years ago

I'd go for the first class collection approach as @kminek said