| 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: | |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | protected static function requireContainer( |
| 22: | ?ContainerInterface $container = null, |
| 23: | bool $getGlobalContainer = true, |
| 24: | bool $createGlobalContainer = false |
| 25: | ): ContainerInterface { |
| 26: | return $container |
| 27: | ?? ($createGlobalContainer || ($getGlobalContainer && Container::hasGlobalContainer()) |
| 28: | ? Container::getGlobalContainer() |
| 29: | : new Container()); |
| 30: | } |
| 31: | } |
| 32: | |