Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Configure the application via a container #2793
This is an implementation for what we discussed in #2778.
The idea is to simplify how to configure the application when using a PSR-11 container.
Here is an example with PHP-DI, using the default services from Slim:
$container = new DI\Container; $app = AppFactory::createFromContainer($container);
Here is an example when we want to overload one service:
$container = new DI\Container; $container->set(CallableResolverInterface::class, $customInstance); $app = AppFactory::createFromContainer($container);
(in reality I would recommend using a config file, but the example here is simpler)
instead of the current way of doing it:
$container = new DI\Container; AppFactory::setContainer($container); AppFactory::setCallableResolver($customResolver); $app = AppFactory::create($container);
The 2nd point is interesting for PHP-DI: the bridge could provide a pre-configured container for Slim. Users would just have to call