silexphp / Silex-Skeleton

A skeleton to get started with Silex
MIT License
780 stars 197 forks source link

what's the intended way to configure service providers? #81

Open jdmcalee opened 7 years ago

jdmcalee commented 7 years ago

I just started moving a prototype app from Slim to Silex, and I started with this skeleton. It seems strange to load config after initializing the app, though. How are you supposed to configure service providers, Monolog for example, with this layout?

patrick-fls commented 7 years ago

Special cases like monolog or the web debug toolbar can are configured in the config file themselves as they are part of the environment. You can see it in the skeleton, the dev.php contains monolog, but not the prod.php file

Usually, none of the environment logic is required to register a service, however, and since the providers are lazy loaded in the service container, they will only be instantiated when you call them for the first time (and the config file will then be available to you).

bezin commented 7 years ago

Since exactly the same question led me here and to #65 eventually, I'll just leave this here as a reference for future Silex beginners ;)