1: | <?php declare(strict_types=1); |
2: | |
3: | namespace Salient\Container; |
4: | |
5: | use Salient\Contract\Container\ContainerInterface; |
6: | |
7: | |
8: | |
9: | |
10: | trait RequiresContainer |
11: | { |
12: | |
13: | |
14: | |
15: | |
16: | protected static function requireContainer( |
17: | ?ContainerInterface $container = null, |
18: | bool $getGlobalContainer = true, |
19: | bool $createGlobalContainer = false |
20: | ): ContainerInterface { |
21: | return $container |
22: | ?? ($createGlobalContainer || ($getGlobalContainer && Container::hasGlobalContainer()) |
23: | ? Container::getGlobalContainer() |
24: | : new Container()); |
25: | } |
26: | } |
27: | |