A
A
ape3642016-02-03 09:17:25
PHP
ape364, 2016-02-03 09:17:25

The principle of using containers in Slim 3?

Why are containers needed in Slim v3? I reviewed/re-read a lot of documentation and slim-skeletons and still did not fully understand what it is and how it can be useful. So far, the understanding is:

1. To store some global variables/settings available from anywhere.
2. To override error handling notAllowedHandler, notFoundHandler, errorHandler, etc.

What other use cases for these containers can be? I also saw use in the form of middleware (for example, jsonResponse is used here), it is not clear why the middleware itself is not as it is. I would love to see real examples.

Thanks in advance :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Kudinov, 2016-02-12
@Frostealth

This is an IoC container. Read about IoC and DI .

D
dmitriy, 2016-02-12
@dmitriylanets

when refactoring, I used containers to be able to test the system
was:

function some (){
global $user;
}

became:
function some (){
$user = $this->getConteiner()->get('user');
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question