@@ -46,82 +46,82 @@ |
||
46 | 46 | use Psr\Log\LoggerInterface; |
47 | 47 | |
48 | 48 | class Application extends App implements IBootstrap { |
49 | - public const APP_ID = 'workflowengine'; |
|
49 | + public const APP_ID = 'workflowengine'; |
|
50 | 50 | |
51 | - public function __construct() { |
|
52 | - parent::__construct(self::APP_ID); |
|
53 | - } |
|
51 | + public function __construct() { |
|
52 | + parent::__construct(self::APP_ID); |
|
53 | + } |
|
54 | 54 | |
55 | - public function register(IRegistrationContext $context): void { |
|
56 | - $context->registerServiceAlias('RequestTimeController', RequestTime::class); |
|
57 | - $context->registerEventListener( |
|
58 | - LoadSettingsScriptsEvent::class, |
|
59 | - LoadAdditionalSettingsScriptsListener::class, |
|
60 | - -100 |
|
61 | - ); |
|
62 | - } |
|
55 | + public function register(IRegistrationContext $context): void { |
|
56 | + $context->registerServiceAlias('RequestTimeController', RequestTime::class); |
|
57 | + $context->registerEventListener( |
|
58 | + LoadSettingsScriptsEvent::class, |
|
59 | + LoadAdditionalSettingsScriptsListener::class, |
|
60 | + -100 |
|
61 | + ); |
|
62 | + } |
|
63 | 63 | |
64 | - public function boot(IBootContext $context): void { |
|
65 | - $context->injectFn(Closure::fromCallable([$this, 'registerRuleListeners'])); |
|
66 | - } |
|
64 | + public function boot(IBootContext $context): void { |
|
65 | + $context->injectFn(Closure::fromCallable([$this, 'registerRuleListeners'])); |
|
66 | + } |
|
67 | 67 | |
68 | - private function registerRuleListeners(IEventDispatcher $dispatcher, |
|
69 | - ContainerInterface $container, |
|
70 | - LoggerInterface $logger): void { |
|
71 | - /** @var Manager $manager */ |
|
72 | - $manager = $container->get(Manager::class); |
|
73 | - $configuredEvents = $manager->getAllConfiguredEvents(); |
|
68 | + private function registerRuleListeners(IEventDispatcher $dispatcher, |
|
69 | + ContainerInterface $container, |
|
70 | + LoggerInterface $logger): void { |
|
71 | + /** @var Manager $manager */ |
|
72 | + $manager = $container->get(Manager::class); |
|
73 | + $configuredEvents = $manager->getAllConfiguredEvents(); |
|
74 | 74 | |
75 | - foreach ($configuredEvents as $operationClass => $events) { |
|
76 | - foreach ($events as $entityClass => $eventNames) { |
|
77 | - array_map(function (string $eventName) use ($manager, $container, $dispatcher, $logger, $operationClass, $entityClass) { |
|
78 | - $dispatcher->addListener( |
|
79 | - $eventName, |
|
80 | - function ($event) use ($manager, $container, $eventName, $logger, $operationClass, $entityClass) { |
|
81 | - $ruleMatcher = $manager->getRuleMatcher(); |
|
82 | - try { |
|
83 | - /** @var IEntity $entity */ |
|
84 | - $entity = $container->get($entityClass); |
|
85 | - /** @var IOperation $operation */ |
|
86 | - $operation = $container->get($operationClass); |
|
75 | + foreach ($configuredEvents as $operationClass => $events) { |
|
76 | + foreach ($events as $entityClass => $eventNames) { |
|
77 | + array_map(function (string $eventName) use ($manager, $container, $dispatcher, $logger, $operationClass, $entityClass) { |
|
78 | + $dispatcher->addListener( |
|
79 | + $eventName, |
|
80 | + function ($event) use ($manager, $container, $eventName, $logger, $operationClass, $entityClass) { |
|
81 | + $ruleMatcher = $manager->getRuleMatcher(); |
|
82 | + try { |
|
83 | + /** @var IEntity $entity */ |
|
84 | + $entity = $container->get($entityClass); |
|
85 | + /** @var IOperation $operation */ |
|
86 | + $operation = $container->get($operationClass); |
|
87 | 87 | |
88 | - $ruleMatcher->setEventName($eventName); |
|
89 | - $ruleMatcher->setEntity($entity); |
|
90 | - $ruleMatcher->setOperation($operation); |
|
88 | + $ruleMatcher->setEventName($eventName); |
|
89 | + $ruleMatcher->setEntity($entity); |
|
90 | + $ruleMatcher->setOperation($operation); |
|
91 | 91 | |
92 | - $ctx = new LogContext(); |
|
93 | - $ctx |
|
94 | - ->setOperation($operation) |
|
95 | - ->setEntity($entity) |
|
96 | - ->setEventName($eventName); |
|
92 | + $ctx = new LogContext(); |
|
93 | + $ctx |
|
94 | + ->setOperation($operation) |
|
95 | + ->setEntity($entity) |
|
96 | + ->setEventName($eventName); |
|
97 | 97 | |
98 | - /** @var Logger $flowLogger */ |
|
99 | - $flowLogger = $container->get(Logger::class); |
|
100 | - $flowLogger->logEventInit($ctx); |
|
98 | + /** @var Logger $flowLogger */ |
|
99 | + $flowLogger = $container->get(Logger::class); |
|
100 | + $flowLogger->logEventInit($ctx); |
|
101 | 101 | |
102 | - if ($event instanceof Event) { |
|
103 | - $entity->prepareRuleMatcher($ruleMatcher, $eventName, $event); |
|
104 | - $operation->onEvent($eventName, $event, $ruleMatcher); |
|
105 | - } else { |
|
106 | - $logger->debug( |
|
107 | - 'Cannot handle event {name} of {event} against entity {entity} and operation {operation}', |
|
108 | - [ |
|
109 | - 'app' => self::APP_ID, |
|
110 | - 'name' => $eventName, |
|
111 | - 'event' => get_class($event), |
|
112 | - 'entity' => $entityClass, |
|
113 | - 'operation' => $operationClass, |
|
114 | - ] |
|
115 | - ); |
|
116 | - } |
|
117 | - $flowLogger->logEventDone($ctx); |
|
118 | - } catch (ContainerExceptionInterface $e) { |
|
119 | - // Ignore query exceptions since they might occur when an entity/operation were set up before by an app that is disabled now |
|
120 | - } |
|
121 | - } |
|
122 | - ); |
|
123 | - }, $eventNames ?? []); |
|
124 | - } |
|
125 | - } |
|
126 | - } |
|
102 | + if ($event instanceof Event) { |
|
103 | + $entity->prepareRuleMatcher($ruleMatcher, $eventName, $event); |
|
104 | + $operation->onEvent($eventName, $event, $ruleMatcher); |
|
105 | + } else { |
|
106 | + $logger->debug( |
|
107 | + 'Cannot handle event {name} of {event} against entity {entity} and operation {operation}', |
|
108 | + [ |
|
109 | + 'app' => self::APP_ID, |
|
110 | + 'name' => $eventName, |
|
111 | + 'event' => get_class($event), |
|
112 | + 'entity' => $entityClass, |
|
113 | + 'operation' => $operationClass, |
|
114 | + ] |
|
115 | + ); |
|
116 | + } |
|
117 | + $flowLogger->logEventDone($ctx); |
|
118 | + } catch (ContainerExceptionInterface $e) { |
|
119 | + // Ignore query exceptions since they might occur when an entity/operation were set up before by an app that is disabled now |
|
120 | + } |
|
121 | + } |
|
122 | + ); |
|
123 | + }, $eventNames ?? []); |
|
124 | + } |
|
125 | + } |
|
126 | + } |
|
127 | 127 | } |