1 | <?php |
||
32 | trait StaticAccessTrait |
||
33 | { |
||
34 | /** |
||
35 | * @var Container[] |
||
36 | */ |
||
37 | protected static $containers = []; |
||
38 | |||
39 | /** |
||
40 | * Mostly for getting an anonymous object by its classname. |
||
41 | * |
||
42 | * - dependency in constructor is resolved automatically |
||
43 | * - 'di.before' & 'di.after' methods executed on this object |
||
44 | * |
||
45 | * @param string|callable|object $className object or classname |
||
46 | * @param array $arguments constructor arguments if any |
||
47 | * @return object |
||
48 | */ |
||
49 | public static function create($className, array $arguments = []): object |
||
55 | |||
56 | /** |
||
57 | * Get object by its id in a STATIC way |
||
58 | * |
||
59 | * ```php |
||
60 | * $cache = Container::cache(); |
||
61 | * $logger = Container::logger(); |
||
62 | * ``` |
||
63 | * |
||
64 | * @param string $name service id |
||
65 | * @param array $arguments if object is an invokable |
||
66 | * @return object |
||
67 | * @throws NotFoundExceptionInterface No entry was found for **this** identifier. |
||
68 | * @throws LogicException if container not instantiated |
||
69 | * @throws UnresolvedClassException if parameter not resolved |
||
70 | * @throws RuntimeException if invokable goes wrong |
||
71 | */ |
||
72 | public static function __callStatic($name, $arguments): object |
||
85 | |||
86 | /** |
||
87 | * @return Container |
||
88 | * @throws LogicException if container not instantiated |
||
89 | */ |
||
90 | protected static function getContainer(): Container |
||
98 | |||
99 | /** |
||
100 | * @param Container $container |
||
101 | */ |
||
102 | protected static function setContainer(Container $container) |
||
106 | } |
This check looks for access to methods that are not accessible from the current context.
If you need to make a method accessible to another context you can raise its visibility level in the defining class.