Add to container


#1

Good afternoon.
Prompt please, in what the basic difference, at container addition
This method

container = $app->getContainer()
// monolog
$container['logger'] = function ($c) {
    $settings = $c->get('settings')['logger'];
    $logger = new Monolog\Logger($settings['name']);
    $logger->pushProcessor(new Monolog\Processor\UidProcessor());
    $logger->pushHandler(new Monolog\Handler\StreamHandler($settings['path'], $settings['level']));

    return $logger;
};

and this method

$container->register(new \Auth\AuthServiceProvider());

When is it better to use this or that method.


#2

I think the register method is just a Pimple specific function to extend the container.

There is an official FIG standard (PSR-11) to get container entries, but no standard to register container services. This means that the best way depends on which container implementation you use. Also note that in Slim 4.x the Pimple Container is no longer included.

I would follow the Slim (3.x) way: Slim Dependency Container

$container = $app->getContainer();

$container['myService'] = function ($container) {
    $myService = new MyService();
    return $myService;
};

#3

Many thanks for the comment.
You have dispelled my doubts about how to use the container prettier.
I saw many examples of mixed use.
Now I will safely use the right approaches.

p.s. tell me where i can read about innovations and prospects in Slim 4


#4

p.s. tell me where i can read about innovations and prospects in Slim 4

Here are some links: