File tree Expand file tree Collapse file tree 1 file changed +15
-6
lines changed
Expand file tree Collapse file tree 1 file changed +15
-6
lines changed Original file line number Diff line number Diff line change 44namespace Queue \Queue ;
55
66use Cake \Core \ContainerInterface ;
7+ use LogicException ;
78
89trait ServicesTrait {
910
1011 /**
11- * @var \Cake\Core\ContainerInterface
12+ * @var \Cake\Core\ContainerInterface|null
1213 */
13- protected ContainerInterface $ container ;
14+ protected ? ContainerInterface $ container = null ;
1415
1516 /**
16- * @param string $id Classname or identifier of the service you want to retrieve
17+ * @template T
18+ *
19+ * @param class-string<T> $id Classname or identifier of the service you want to retrieve
1720 *
18- * @throws \Psr\Container\NotFoundExceptionInterface
1921 * @throws \Psr\Container\ContainerExceptionInterface
22+ * @throws \Psr\Container\NotFoundExceptionInterface
2023 *
21- * @return mixed
24+ * @return T
2225 */
23- protected function getService (string $ id ): mixed {
26+ protected function getService (string $ id ) {
27+ if ($ this ->container === null ) {
28+ throw new LogicException (
29+ "The Container has not been set. Hint: getService() must not be called in the Task's constructor. " ,
30+ );
31+ }
32+
2433 return $ this ->container ->get ($ id );
2534 }
2635
You can’t perform that action at this time.
0 commit comments