@@ -36,56 +36,56 @@ |
||
36 | 36 | * @since 18.0.0 |
37 | 37 | */ |
38 | 38 | interface IRuleMatcher extends IFileCheck { |
39 | - /** |
|
40 | - * This method is left for backwards compatibility and easier porting of |
|
41 | - * apps. Please use 'getFlows' instead (and setOperation if you implement |
|
42 | - * an IComplexOperation). |
|
43 | - * |
|
44 | - * @since 18.0.0 |
|
45 | - * @deprecated 18.0.0 |
|
46 | - */ |
|
47 | - public function getMatchingOperations(string $class, bool $returnFirstMatchingOperationOnly = true): array; |
|
39 | + /** |
|
40 | + * This method is left for backwards compatibility and easier porting of |
|
41 | + * apps. Please use 'getFlows' instead (and setOperation if you implement |
|
42 | + * an IComplexOperation). |
|
43 | + * |
|
44 | + * @since 18.0.0 |
|
45 | + * @deprecated 18.0.0 |
|
46 | + */ |
|
47 | + public function getMatchingOperations(string $class, bool $returnFirstMatchingOperationOnly = true): array; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @throws RuntimeException |
|
51 | - * @since 18.0.0 |
|
52 | - */ |
|
53 | - public function getFlows(bool $returnFirstMatchingOperationOnly = true): array; |
|
49 | + /** |
|
50 | + * @throws RuntimeException |
|
51 | + * @since 18.0.0 |
|
52 | + */ |
|
53 | + public function getFlows(bool $returnFirstMatchingOperationOnly = true): array; |
|
54 | 54 | |
55 | - /** |
|
56 | - * this method can only be called once and is typically called by the |
|
57 | - * Flow engine, unless for IComplexOperations. |
|
58 | - * |
|
59 | - * @throws RuntimeException |
|
60 | - * @since 18.0.0 |
|
61 | - */ |
|
62 | - public function setOperation(IOperation $operation): void; |
|
55 | + /** |
|
56 | + * this method can only be called once and is typically called by the |
|
57 | + * Flow engine, unless for IComplexOperations. |
|
58 | + * |
|
59 | + * @throws RuntimeException |
|
60 | + * @since 18.0.0 |
|
61 | + */ |
|
62 | + public function setOperation(IOperation $operation): void; |
|
63 | 63 | |
64 | - /** |
|
65 | - * this method can only be called once and is typically called by the |
|
66 | - * Flow engine, unless for IComplexOperations. |
|
67 | - * |
|
68 | - * @throws RuntimeException |
|
69 | - * @since 18.0.0 |
|
70 | - */ |
|
71 | - public function setEntity(IEntity $entity): void; |
|
64 | + /** |
|
65 | + * this method can only be called once and is typically called by the |
|
66 | + * Flow engine, unless for IComplexOperations. |
|
67 | + * |
|
68 | + * @throws RuntimeException |
|
69 | + * @since 18.0.0 |
|
70 | + */ |
|
71 | + public function setEntity(IEntity $entity): void; |
|
72 | 72 | |
73 | - /** |
|
74 | - * returns the entity which might provide more information, depending on |
|
75 | - * the interfaces it implements |
|
76 | - * |
|
77 | - * @return IEntity |
|
78 | - * @since 18.0.0 |
|
79 | - */ |
|
80 | - public function getEntity(): IEntity; |
|
73 | + /** |
|
74 | + * returns the entity which might provide more information, depending on |
|
75 | + * the interfaces it implements |
|
76 | + * |
|
77 | + * @return IEntity |
|
78 | + * @since 18.0.0 |
|
79 | + */ |
|
80 | + public function getEntity(): IEntity; |
|
81 | 81 | |
82 | - /** |
|
83 | - * this method can be called once to set the event name that is currently |
|
84 | - * being processed. The workflow engine takes care of this usually, only an |
|
85 | - * IComplexOperation might want to make use of it. |
|
86 | - * |
|
87 | - * @throws RuntimeException |
|
88 | - * @since 20.0.0 |
|
89 | - */ |
|
90 | - public function setEventName(string $eventName): void; |
|
82 | + /** |
|
83 | + * this method can be called once to set the event name that is currently |
|
84 | + * being processed. The workflow engine takes care of this usually, only an |
|
85 | + * IComplexOperation might want to make use of it. |
|
86 | + * |
|
87 | + * @throws RuntimeException |
|
88 | + * @since 20.0.0 |
|
89 | + */ |
|
90 | + public function setEventName(string $eventName): void; |
|
91 | 91 | } |
@@ -44,200 +44,200 @@ |
||
44 | 44 | |
45 | 45 | class RuleMatcher implements IRuleMatcher { |
46 | 46 | |
47 | - /** @var IUserSession */ |
|
48 | - protected $session; |
|
49 | - /** @var IManager */ |
|
50 | - protected $manager; |
|
51 | - /** @var array */ |
|
52 | - protected $contexts; |
|
53 | - /** @var IServerContainer */ |
|
54 | - protected $container; |
|
55 | - /** @var array */ |
|
56 | - protected $fileInfo = []; |
|
57 | - /** @var IL10N */ |
|
58 | - protected $l; |
|
59 | - /** @var IOperation */ |
|
60 | - protected $operation; |
|
61 | - /** @var IEntity */ |
|
62 | - protected $entity; |
|
63 | - /** @var Logger */ |
|
64 | - protected $logger; |
|
65 | - /** @var string */ |
|
66 | - protected $eventName; |
|
67 | - |
|
68 | - public function __construct( |
|
69 | - IUserSession $session, |
|
70 | - IServerContainer $container, |
|
71 | - IL10N $l, |
|
72 | - Manager $manager, |
|
73 | - Logger $logger |
|
74 | - ) { |
|
75 | - $this->session = $session; |
|
76 | - $this->manager = $manager; |
|
77 | - $this->container = $container; |
|
78 | - $this->l = $l; |
|
79 | - $this->logger = $logger; |
|
80 | - } |
|
81 | - |
|
82 | - public function setFileInfo(IStorage $storage, string $path, bool $isDir = false): void { |
|
83 | - $this->fileInfo['storage'] = $storage; |
|
84 | - $this->fileInfo['path'] = $path; |
|
85 | - $this->fileInfo['isDir'] = $isDir; |
|
86 | - } |
|
87 | - |
|
88 | - public function setEntitySubject(IEntity $entity, $subject): void { |
|
89 | - $this->contexts[get_class($entity)] = [$entity, $subject]; |
|
90 | - } |
|
91 | - |
|
92 | - public function setOperation(IOperation $operation): void { |
|
93 | - if ($this->operation !== null) { |
|
94 | - throw new RuntimeException('This method must not be called more than once'); |
|
95 | - } |
|
96 | - $this->operation = $operation; |
|
97 | - } |
|
98 | - |
|
99 | - public function setEntity(IEntity $entity): void { |
|
100 | - if ($this->entity !== null) { |
|
101 | - throw new RuntimeException('This method must not be called more than once'); |
|
102 | - } |
|
103 | - $this->entity = $entity; |
|
104 | - } |
|
105 | - |
|
106 | - public function setEventName(string $eventName): void { |
|
107 | - if ($this->eventName !== null) { |
|
108 | - throw new RuntimeException('This method must not be called more than once'); |
|
109 | - } |
|
110 | - $this->eventName = $eventName; |
|
111 | - } |
|
112 | - |
|
113 | - public function getEntity(): IEntity { |
|
114 | - if ($this->entity === null) { |
|
115 | - throw new \LogicException('Entity was not set yet'); |
|
116 | - } |
|
117 | - return $this->entity; |
|
118 | - } |
|
119 | - |
|
120 | - public function getFlows(bool $returnFirstMatchingOperationOnly = true): array { |
|
121 | - if (!$this->operation) { |
|
122 | - throw new RuntimeException('Operation is not set'); |
|
123 | - } |
|
124 | - return $this->getMatchingOperations(get_class($this->operation), $returnFirstMatchingOperationOnly); |
|
125 | - } |
|
126 | - |
|
127 | - public function getMatchingOperations(string $class, bool $returnFirstMatchingOperationOnly = true): array { |
|
128 | - $scopes[] = new ScopeContext(IManager::SCOPE_ADMIN); |
|
129 | - $user = $this->session->getUser(); |
|
130 | - if ($user !== null && $this->manager->isUserScopeEnabled()) { |
|
131 | - $scopes[] = new ScopeContext(IManager::SCOPE_USER, $user->getUID()); |
|
132 | - } |
|
133 | - |
|
134 | - $ctx = new LogContext(); |
|
135 | - $ctx |
|
136 | - ->setScopes($scopes) |
|
137 | - ->setEntity($this->entity) |
|
138 | - ->setOperation($this->operation); |
|
139 | - $this->logger->logFlowRequests($ctx); |
|
140 | - |
|
141 | - $operations = []; |
|
142 | - foreach ($scopes as $scope) { |
|
143 | - $operations = array_merge($operations, $this->manager->getOperations($class, $scope)); |
|
144 | - } |
|
145 | - |
|
146 | - if ($this->entity instanceof IEntity) { |
|
147 | - /** @var ScopeContext[] $additionalScopes */ |
|
148 | - $additionalScopes = $this->manager->getAllConfiguredScopesForOperation($class); |
|
149 | - foreach ($additionalScopes as $hash => $scopeCandidate) { |
|
150 | - if ($scopeCandidate->getScope() !== IManager::SCOPE_USER || in_array($scopeCandidate, $scopes)) { |
|
151 | - continue; |
|
152 | - } |
|
153 | - if ($this->entity->isLegitimatedForUserId($scopeCandidate->getScopeId())) { |
|
154 | - $ctx = new LogContext(); |
|
155 | - $ctx |
|
156 | - ->setScopes([$scopeCandidate]) |
|
157 | - ->setEntity($this->entity) |
|
158 | - ->setOperation($this->operation); |
|
159 | - $this->logger->logScopeExpansion($ctx); |
|
160 | - $operations = array_merge($operations, $this->manager->getOperations($class, $scopeCandidate)); |
|
161 | - } |
|
162 | - } |
|
163 | - } |
|
164 | - |
|
165 | - $matches = []; |
|
166 | - foreach ($operations as $operation) { |
|
167 | - $configuredEvents = json_decode($operation['events'], true); |
|
168 | - if ($this->eventName !== null && !in_array($this->eventName, $configuredEvents)) { |
|
169 | - continue; |
|
170 | - } |
|
171 | - |
|
172 | - $checkIds = json_decode($operation['checks'], true); |
|
173 | - $checks = $this->manager->getChecks($checkIds); |
|
174 | - |
|
175 | - foreach ($checks as $check) { |
|
176 | - if (!$this->check($check)) { |
|
177 | - // Check did not match, continue with the next operation |
|
178 | - continue 2; |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - $ctx = new LogContext(); |
|
183 | - $ctx |
|
184 | - ->setEntity($this->entity) |
|
185 | - ->setOperation($this->operation) |
|
186 | - ->setConfiguration($operation); |
|
187 | - $this->logger->logPassedCheck($ctx); |
|
188 | - |
|
189 | - if ($returnFirstMatchingOperationOnly) { |
|
190 | - $ctx = new LogContext(); |
|
191 | - $ctx |
|
192 | - ->setEntity($this->entity) |
|
193 | - ->setOperation($this->operation) |
|
194 | - ->setConfiguration($operation); |
|
195 | - $this->logger->logRunSingle($ctx); |
|
196 | - return $operation; |
|
197 | - } |
|
198 | - $matches[] = $operation; |
|
199 | - } |
|
200 | - |
|
201 | - $ctx = new LogContext(); |
|
202 | - $ctx |
|
203 | - ->setEntity($this->entity) |
|
204 | - ->setOperation($this->operation); |
|
205 | - if (!empty($matches)) { |
|
206 | - $ctx->setConfiguration($matches); |
|
207 | - $this->logger->logRunAll($ctx); |
|
208 | - } else { |
|
209 | - $this->logger->logRunNone($ctx); |
|
210 | - } |
|
211 | - |
|
212 | - return $matches; |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * @param array $check |
|
217 | - * @return bool |
|
218 | - */ |
|
219 | - public function check(array $check) { |
|
220 | - try { |
|
221 | - $checkInstance = $this->container->query($check['class']); |
|
222 | - } catch (QueryException $e) { |
|
223 | - // Check does not exist, assume it matches. |
|
224 | - return true; |
|
225 | - } |
|
226 | - |
|
227 | - if ($checkInstance instanceof IFileCheck) { |
|
228 | - if (empty($this->fileInfo)) { |
|
229 | - throw new RuntimeException('Must set file info before running the check'); |
|
230 | - } |
|
231 | - $checkInstance->setFileInfo($this->fileInfo['storage'], $this->fileInfo['path'], $this->fileInfo['isDir']); |
|
232 | - } elseif ($checkInstance instanceof IEntityCheck) { |
|
233 | - foreach ($this->contexts as $entityInfo) { |
|
234 | - list($entity, $subject) = $entityInfo; |
|
235 | - $checkInstance->setEntitySubject($entity, $subject); |
|
236 | - } |
|
237 | - } elseif (!$checkInstance instanceof ICheck) { |
|
238 | - // Check is invalid |
|
239 | - throw new \UnexpectedValueException($this->l->t('Check %s is invalid or does not exist', $check['class'])); |
|
240 | - } |
|
241 | - return $checkInstance->executeCheck($check['operator'], $check['value']); |
|
242 | - } |
|
47 | + /** @var IUserSession */ |
|
48 | + protected $session; |
|
49 | + /** @var IManager */ |
|
50 | + protected $manager; |
|
51 | + /** @var array */ |
|
52 | + protected $contexts; |
|
53 | + /** @var IServerContainer */ |
|
54 | + protected $container; |
|
55 | + /** @var array */ |
|
56 | + protected $fileInfo = []; |
|
57 | + /** @var IL10N */ |
|
58 | + protected $l; |
|
59 | + /** @var IOperation */ |
|
60 | + protected $operation; |
|
61 | + /** @var IEntity */ |
|
62 | + protected $entity; |
|
63 | + /** @var Logger */ |
|
64 | + protected $logger; |
|
65 | + /** @var string */ |
|
66 | + protected $eventName; |
|
67 | + |
|
68 | + public function __construct( |
|
69 | + IUserSession $session, |
|
70 | + IServerContainer $container, |
|
71 | + IL10N $l, |
|
72 | + Manager $manager, |
|
73 | + Logger $logger |
|
74 | + ) { |
|
75 | + $this->session = $session; |
|
76 | + $this->manager = $manager; |
|
77 | + $this->container = $container; |
|
78 | + $this->l = $l; |
|
79 | + $this->logger = $logger; |
|
80 | + } |
|
81 | + |
|
82 | + public function setFileInfo(IStorage $storage, string $path, bool $isDir = false): void { |
|
83 | + $this->fileInfo['storage'] = $storage; |
|
84 | + $this->fileInfo['path'] = $path; |
|
85 | + $this->fileInfo['isDir'] = $isDir; |
|
86 | + } |
|
87 | + |
|
88 | + public function setEntitySubject(IEntity $entity, $subject): void { |
|
89 | + $this->contexts[get_class($entity)] = [$entity, $subject]; |
|
90 | + } |
|
91 | + |
|
92 | + public function setOperation(IOperation $operation): void { |
|
93 | + if ($this->operation !== null) { |
|
94 | + throw new RuntimeException('This method must not be called more than once'); |
|
95 | + } |
|
96 | + $this->operation = $operation; |
|
97 | + } |
|
98 | + |
|
99 | + public function setEntity(IEntity $entity): void { |
|
100 | + if ($this->entity !== null) { |
|
101 | + throw new RuntimeException('This method must not be called more than once'); |
|
102 | + } |
|
103 | + $this->entity = $entity; |
|
104 | + } |
|
105 | + |
|
106 | + public function setEventName(string $eventName): void { |
|
107 | + if ($this->eventName !== null) { |
|
108 | + throw new RuntimeException('This method must not be called more than once'); |
|
109 | + } |
|
110 | + $this->eventName = $eventName; |
|
111 | + } |
|
112 | + |
|
113 | + public function getEntity(): IEntity { |
|
114 | + if ($this->entity === null) { |
|
115 | + throw new \LogicException('Entity was not set yet'); |
|
116 | + } |
|
117 | + return $this->entity; |
|
118 | + } |
|
119 | + |
|
120 | + public function getFlows(bool $returnFirstMatchingOperationOnly = true): array { |
|
121 | + if (!$this->operation) { |
|
122 | + throw new RuntimeException('Operation is not set'); |
|
123 | + } |
|
124 | + return $this->getMatchingOperations(get_class($this->operation), $returnFirstMatchingOperationOnly); |
|
125 | + } |
|
126 | + |
|
127 | + public function getMatchingOperations(string $class, bool $returnFirstMatchingOperationOnly = true): array { |
|
128 | + $scopes[] = new ScopeContext(IManager::SCOPE_ADMIN); |
|
129 | + $user = $this->session->getUser(); |
|
130 | + if ($user !== null && $this->manager->isUserScopeEnabled()) { |
|
131 | + $scopes[] = new ScopeContext(IManager::SCOPE_USER, $user->getUID()); |
|
132 | + } |
|
133 | + |
|
134 | + $ctx = new LogContext(); |
|
135 | + $ctx |
|
136 | + ->setScopes($scopes) |
|
137 | + ->setEntity($this->entity) |
|
138 | + ->setOperation($this->operation); |
|
139 | + $this->logger->logFlowRequests($ctx); |
|
140 | + |
|
141 | + $operations = []; |
|
142 | + foreach ($scopes as $scope) { |
|
143 | + $operations = array_merge($operations, $this->manager->getOperations($class, $scope)); |
|
144 | + } |
|
145 | + |
|
146 | + if ($this->entity instanceof IEntity) { |
|
147 | + /** @var ScopeContext[] $additionalScopes */ |
|
148 | + $additionalScopes = $this->manager->getAllConfiguredScopesForOperation($class); |
|
149 | + foreach ($additionalScopes as $hash => $scopeCandidate) { |
|
150 | + if ($scopeCandidate->getScope() !== IManager::SCOPE_USER || in_array($scopeCandidate, $scopes)) { |
|
151 | + continue; |
|
152 | + } |
|
153 | + if ($this->entity->isLegitimatedForUserId($scopeCandidate->getScopeId())) { |
|
154 | + $ctx = new LogContext(); |
|
155 | + $ctx |
|
156 | + ->setScopes([$scopeCandidate]) |
|
157 | + ->setEntity($this->entity) |
|
158 | + ->setOperation($this->operation); |
|
159 | + $this->logger->logScopeExpansion($ctx); |
|
160 | + $operations = array_merge($operations, $this->manager->getOperations($class, $scopeCandidate)); |
|
161 | + } |
|
162 | + } |
|
163 | + } |
|
164 | + |
|
165 | + $matches = []; |
|
166 | + foreach ($operations as $operation) { |
|
167 | + $configuredEvents = json_decode($operation['events'], true); |
|
168 | + if ($this->eventName !== null && !in_array($this->eventName, $configuredEvents)) { |
|
169 | + continue; |
|
170 | + } |
|
171 | + |
|
172 | + $checkIds = json_decode($operation['checks'], true); |
|
173 | + $checks = $this->manager->getChecks($checkIds); |
|
174 | + |
|
175 | + foreach ($checks as $check) { |
|
176 | + if (!$this->check($check)) { |
|
177 | + // Check did not match, continue with the next operation |
|
178 | + continue 2; |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + $ctx = new LogContext(); |
|
183 | + $ctx |
|
184 | + ->setEntity($this->entity) |
|
185 | + ->setOperation($this->operation) |
|
186 | + ->setConfiguration($operation); |
|
187 | + $this->logger->logPassedCheck($ctx); |
|
188 | + |
|
189 | + if ($returnFirstMatchingOperationOnly) { |
|
190 | + $ctx = new LogContext(); |
|
191 | + $ctx |
|
192 | + ->setEntity($this->entity) |
|
193 | + ->setOperation($this->operation) |
|
194 | + ->setConfiguration($operation); |
|
195 | + $this->logger->logRunSingle($ctx); |
|
196 | + return $operation; |
|
197 | + } |
|
198 | + $matches[] = $operation; |
|
199 | + } |
|
200 | + |
|
201 | + $ctx = new LogContext(); |
|
202 | + $ctx |
|
203 | + ->setEntity($this->entity) |
|
204 | + ->setOperation($this->operation); |
|
205 | + if (!empty($matches)) { |
|
206 | + $ctx->setConfiguration($matches); |
|
207 | + $this->logger->logRunAll($ctx); |
|
208 | + } else { |
|
209 | + $this->logger->logRunNone($ctx); |
|
210 | + } |
|
211 | + |
|
212 | + return $matches; |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * @param array $check |
|
217 | + * @return bool |
|
218 | + */ |
|
219 | + public function check(array $check) { |
|
220 | + try { |
|
221 | + $checkInstance = $this->container->query($check['class']); |
|
222 | + } catch (QueryException $e) { |
|
223 | + // Check does not exist, assume it matches. |
|
224 | + return true; |
|
225 | + } |
|
226 | + |
|
227 | + if ($checkInstance instanceof IFileCheck) { |
|
228 | + if (empty($this->fileInfo)) { |
|
229 | + throw new RuntimeException('Must set file info before running the check'); |
|
230 | + } |
|
231 | + $checkInstance->setFileInfo($this->fileInfo['storage'], $this->fileInfo['path'], $this->fileInfo['isDir']); |
|
232 | + } elseif ($checkInstance instanceof IEntityCheck) { |
|
233 | + foreach ($this->contexts as $entityInfo) { |
|
234 | + list($entity, $subject) = $entityInfo; |
|
235 | + $checkInstance->setEntitySubject($entity, $subject); |
|
236 | + } |
|
237 | + } elseif (!$checkInstance instanceof ICheck) { |
|
238 | + // Check is invalid |
|
239 | + throw new \UnexpectedValueException($this->l->t('Check %s is invalid or does not exist', $check['class'])); |
|
240 | + } |
|
241 | + return $checkInstance->executeCheck($check['operator'], $check['value']); |
|
242 | + } |
|
243 | 243 | } |
@@ -43,86 +43,86 @@ |
||
43 | 43 | use OCP\WorkflowEngine\IOperationCompat; |
44 | 44 | |
45 | 45 | class Application extends App implements IBootstrap { |
46 | - public const APP_ID = 'workflowengine'; |
|
46 | + public const APP_ID = 'workflowengine'; |
|
47 | 47 | |
48 | - public function __construct() { |
|
49 | - parent::__construct(self::APP_ID); |
|
50 | - } |
|
48 | + public function __construct() { |
|
49 | + parent::__construct(self::APP_ID); |
|
50 | + } |
|
51 | 51 | |
52 | - public function register(IRegistrationContext $context): void { |
|
53 | - $context->registerServiceAlias('RequestTimeController', RequestTime::class); |
|
54 | - $context->registerEventListener( |
|
55 | - LoadSettingsScriptsEvent::class, |
|
56 | - LoadAdditionalSettingsScriptsListener::class, |
|
57 | - -100 |
|
58 | - ); |
|
59 | - } |
|
52 | + public function register(IRegistrationContext $context): void { |
|
53 | + $context->registerServiceAlias('RequestTimeController', RequestTime::class); |
|
54 | + $context->registerEventListener( |
|
55 | + LoadSettingsScriptsEvent::class, |
|
56 | + LoadAdditionalSettingsScriptsListener::class, |
|
57 | + -100 |
|
58 | + ); |
|
59 | + } |
|
60 | 60 | |
61 | - public function boot(IBootContext $context): void { |
|
62 | - $context->injectFn(Closure::fromCallable([$this, 'registerRuleListeners'])); |
|
63 | - } |
|
61 | + public function boot(IBootContext $context): void { |
|
62 | + $context->injectFn(Closure::fromCallable([$this, 'registerRuleListeners'])); |
|
63 | + } |
|
64 | 64 | |
65 | - private function registerRuleListeners(IEventDispatcher $dispatcher, |
|
66 | - IServerContainer $container, |
|
67 | - ILogger $logger): void { |
|
68 | - /** @var Manager $manager */ |
|
69 | - $manager = $container->query(Manager::class); |
|
70 | - $configuredEvents = $manager->getAllConfiguredEvents(); |
|
65 | + private function registerRuleListeners(IEventDispatcher $dispatcher, |
|
66 | + IServerContainer $container, |
|
67 | + ILogger $logger): void { |
|
68 | + /** @var Manager $manager */ |
|
69 | + $manager = $container->query(Manager::class); |
|
70 | + $configuredEvents = $manager->getAllConfiguredEvents(); |
|
71 | 71 | |
72 | - foreach ($configuredEvents as $operationClass => $events) { |
|
73 | - foreach ($events as $entityClass => $eventNames) { |
|
74 | - array_map(function (string $eventName) use ($manager, $container, $dispatcher, $logger, $operationClass, $entityClass) { |
|
75 | - $dispatcher->addListener( |
|
76 | - $eventName, |
|
77 | - function ($event) use ($manager, $container, $eventName, $logger, $operationClass, $entityClass) { |
|
78 | - $ruleMatcher = $manager->getRuleMatcher(); |
|
79 | - try { |
|
80 | - /** @var IEntity $entity */ |
|
81 | - $entity = $container->query($entityClass); |
|
82 | - /** @var IOperation $operation */ |
|
83 | - $operation = $container->query($operationClass); |
|
72 | + foreach ($configuredEvents as $operationClass => $events) { |
|
73 | + foreach ($events as $entityClass => $eventNames) { |
|
74 | + array_map(function (string $eventName) use ($manager, $container, $dispatcher, $logger, $operationClass, $entityClass) { |
|
75 | + $dispatcher->addListener( |
|
76 | + $eventName, |
|
77 | + function ($event) use ($manager, $container, $eventName, $logger, $operationClass, $entityClass) { |
|
78 | + $ruleMatcher = $manager->getRuleMatcher(); |
|
79 | + try { |
|
80 | + /** @var IEntity $entity */ |
|
81 | + $entity = $container->query($entityClass); |
|
82 | + /** @var IOperation $operation */ |
|
83 | + $operation = $container->query($operationClass); |
|
84 | 84 | |
85 | - $ruleMatcher->setEventName($eventName); |
|
86 | - $ruleMatcher->setEntity($entity); |
|
87 | - $ruleMatcher->setOperation($operation); |
|
85 | + $ruleMatcher->setEventName($eventName); |
|
86 | + $ruleMatcher->setEntity($entity); |
|
87 | + $ruleMatcher->setOperation($operation); |
|
88 | 88 | |
89 | - $ctx = new LogContext(); |
|
90 | - $ctx |
|
91 | - ->setOperation($operation) |
|
92 | - ->setEntity($entity) |
|
93 | - ->setEventName($eventName); |
|
89 | + $ctx = new LogContext(); |
|
90 | + $ctx |
|
91 | + ->setOperation($operation) |
|
92 | + ->setEntity($entity) |
|
93 | + ->setEventName($eventName); |
|
94 | 94 | |
95 | - /** @var Logger $flowLogger */ |
|
96 | - $flowLogger = $container->query(Logger::class); |
|
97 | - $flowLogger->logEventInit($ctx); |
|
95 | + /** @var Logger $flowLogger */ |
|
96 | + $flowLogger = $container->query(Logger::class); |
|
97 | + $flowLogger->logEventInit($ctx); |
|
98 | 98 | |
99 | - if ($event instanceof Event) { |
|
100 | - $entity->prepareRuleMatcher($ruleMatcher, $eventName, $event); |
|
101 | - $operation->onEvent($eventName, $event, $ruleMatcher); |
|
102 | - } elseif ($entity instanceof IEntityCompat && $operation instanceof IOperationCompat) { |
|
103 | - // TODO: Remove this block (and the compat classes) in the first major release in 2023 |
|
104 | - $entity->prepareRuleMatcherCompat($ruleMatcher, $eventName, $event); |
|
105 | - $operation->onEventCompat($eventName, $event, $ruleMatcher); |
|
106 | - } else { |
|
107 | - $logger->debug( |
|
108 | - 'Cannot handle event {name} of {event} against entity {entity} and operation {operation}', |
|
109 | - [ |
|
110 | - 'app' => self::APP_ID, |
|
111 | - 'name' => $eventName, |
|
112 | - 'event' => get_class($event), |
|
113 | - 'entity' => $entityClass, |
|
114 | - 'operation' => $operationClass, |
|
115 | - ] |
|
116 | - ); |
|
117 | - } |
|
118 | - $flowLogger->logEventDone($ctx); |
|
119 | - } catch (QueryException $e) { |
|
120 | - // Ignore query exceptions since they might occur when an entity/operation were setup before by an app that is disabled now |
|
121 | - } |
|
122 | - } |
|
123 | - ); |
|
124 | - }, $eventNames ?? []); |
|
125 | - } |
|
126 | - } |
|
127 | - } |
|
99 | + if ($event instanceof Event) { |
|
100 | + $entity->prepareRuleMatcher($ruleMatcher, $eventName, $event); |
|
101 | + $operation->onEvent($eventName, $event, $ruleMatcher); |
|
102 | + } elseif ($entity instanceof IEntityCompat && $operation instanceof IOperationCompat) { |
|
103 | + // TODO: Remove this block (and the compat classes) in the first major release in 2023 |
|
104 | + $entity->prepareRuleMatcherCompat($ruleMatcher, $eventName, $event); |
|
105 | + $operation->onEventCompat($eventName, $event, $ruleMatcher); |
|
106 | + } else { |
|
107 | + $logger->debug( |
|
108 | + 'Cannot handle event {name} of {event} against entity {entity} and operation {operation}', |
|
109 | + [ |
|
110 | + 'app' => self::APP_ID, |
|
111 | + 'name' => $eventName, |
|
112 | + 'event' => get_class($event), |
|
113 | + 'entity' => $entityClass, |
|
114 | + 'operation' => $operationClass, |
|
115 | + ] |
|
116 | + ); |
|
117 | + } |
|
118 | + $flowLogger->logEventDone($ctx); |
|
119 | + } catch (QueryException $e) { |
|
120 | + // Ignore query exceptions since they might occur when an entity/operation were setup before by an app that is disabled now |
|
121 | + } |
|
122 | + } |
|
123 | + ); |
|
124 | + }, $eventNames ?? []); |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | 128 | } |