Skip to content

Commit 8237112

Browse files
authored
Engine: Add support for inject annotation on property.
1 parent 3da583f commit 8237112

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/Engine.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Mathematicator\Search\Query;
1010
use Mathematicator\SearchController\IController;
1111
use Nette\DI\Container;
12+
use Nette\DI\Extensions\InjectExtension;
1213
use Tracy\Debugger;
1314

1415
final class Engine
@@ -76,25 +77,31 @@ public function compute(string $query): EngineResult
7677

7778
/**
7879
* @param Query $query
79-
* @param string $controller
80+
* @param string $serviceName
8081
* @return IController|null
8182
* @throws InvalidDataException
8283
*/
83-
private function processCallback(Query $query, string $controller): ?IController
84+
private function processCallback(Query $query, string $serviceName): ?IController
8485
{
85-
/** @var IController|null $return */
86-
$return = $this->serviceFactory->getByType($controller);
86+
/** @var IController|null $controller */
87+
$controller = $this->serviceFactory->getByType($serviceName);
8788

88-
if ($return !== null) {
89-
$return->createContext($query);
89+
if ($controller !== null) {
90+
// 1. Process magic services
91+
foreach (InjectExtension::getInjectProperties(\get_class($controller)) as $property => $service) {
92+
$controller->{$property} = $this->serviceFactory->getByType($service);
93+
}
94+
95+
// 2. Create context
96+
$controller->createContext($query);
9097

9198
try {
92-
$return->actionDefault();
99+
$controller->actionDefault();
93100
} catch (TerminateException $e) {
94101
}
95102
}
96103

97-
return $return ?? null;
104+
return $controller ?? null;
98105
}
99106

100107
/**

0 commit comments

Comments
 (0)