Skip to content

Commit 7fecb05

Browse files
committed
Use the new Events in Flow
Signed-off-by: Roeland Jago Douma <[email protected]>
1 parent 12136a0 commit 7fecb05

7 files changed

Lines changed: 171 additions & 20 deletions

File tree

apps/workflowengine/lib/Manager.php

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,24 @@
3737
use OCA\WorkflowEngine\Service\RuleMatcher;
3838
use OCP\AppFramework\QueryException;
3939
use OCP\DB\QueryBuilder\IQueryBuilder;
40+
use OCP\EventDispatcher\IEventDispatcher;
4041
use OCP\Files\Storage\IStorage;
4142
use OCP\IDBConnection;
4243
use OCP\IL10N;
4344
use OCP\ILogger;
4445
use OCP\IServerContainer;
4546
use OCP\IUserSession;
47+
use OCP\WorkflowEngine\Events\RegisterChecksEvent;
48+
use OCP\WorkflowEngine\Events\RegisterEntitiesEvent;
49+
use OCP\WorkflowEngine\Events\RegisterOperationsEvent;
4650
use OCP\WorkflowEngine\ICheck;
4751
use OCP\WorkflowEngine\IComplexOperation;
4852
use OCP\WorkflowEngine\IEntity;
4953
use OCP\WorkflowEngine\IEntityEvent;
5054
use OCP\WorkflowEngine\IManager;
5155
use OCP\WorkflowEngine\IOperation;
5256
use OCP\WorkflowEngine\IRuleMatcher;
53-
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
57+
use Symfony\Component\EventDispatcher\EventDispatcherInterface as LegacyDispatcher;
5458
use Symfony\Component\EventDispatcher\GenericEvent;
5559

5660
class Manager implements IManager {
@@ -79,8 +83,8 @@ class Manager implements IManager {
7983
/** @var IL10N */
8084
protected $l;
8185

82-
/** @var EventDispatcherInterface */
83-
protected $eventDispatcher;
86+
/** @var LegacyDispatcher */
87+
protected $legacyEventDispatcher;
8488

8589
/** @var IEntity[] */
8690
protected $registeredEntities = [];
@@ -100,26 +104,26 @@ class Manager implements IManager {
100104
/** @var IUserSession */
101105
protected $session;
102106

103-
/**
104-
* @param IDBConnection $connection
105-
* @param IServerContainer $container
106-
* @param IL10N $l
107-
*/
107+
/** @var IEventDispatcher */
108+
private $dispatcher;
109+
108110
public function __construct(
109111
IDBConnection $connection,
110112
IServerContainer $container,
111113
IL10N $l,
112-
EventDispatcherInterface $eventDispatcher,
114+
LegacyDispatcher $eventDispatcher,
113115
ILogger $logger,
114-
IUserSession $session
116+
IUserSession $session,
117+
IEventDispatcher $dispatcher
115118
) {
116119
$this->connection = $connection;
117120
$this->container = $container;
118121
$this->l = $l;
119-
$this->eventDispatcher = $eventDispatcher;
122+
$this->legacyEventDispatcher = $eventDispatcher;
120123
$this->logger = $logger;
121124
$this->operationsByScope = new CappedMemoryCache(64);
122125
$this->session = $session;
126+
$this->dispatcher = $dispatcher;
123127
}
124128

125129
public function getRuleMatcher(): IRuleMatcher {
@@ -599,7 +603,8 @@ public function formatOperation(array $operation): array {
599603
* @return IEntity[]
600604
*/
601605
public function getEntitiesList(): array {
602-
$this->eventDispatcher->dispatch(IManager::EVENT_NAME_REG_ENTITY, new GenericEvent($this));
606+
$this->dispatcher->dispatchTyped(new RegisterEntitiesEvent($this));
607+
$this->legacyEventDispatcher->dispatch(IManager::EVENT_NAME_REG_ENTITY, new GenericEvent($this));
603608

604609
return array_merge($this->getBuildInEntities(), $this->registeredEntities);
605610
}
@@ -608,7 +613,8 @@ public function getEntitiesList(): array {
608613
* @return IOperation[]
609614
*/
610615
public function getOperatorList(): array {
611-
$this->eventDispatcher->dispatch(IManager::EVENT_NAME_REG_OPERATION, new GenericEvent($this));
616+
$this->dispatcher->dispatchTyped(new RegisterOperationsEvent($this));
617+
$this->legacyEventDispatcher->dispatch(IManager::EVENT_NAME_REG_OPERATION, new GenericEvent($this));
612618

613619
return array_merge($this->getBuildInOperators(), $this->registeredOperators);
614620
}
@@ -617,7 +623,8 @@ public function getOperatorList(): array {
617623
* @return ICheck[]
618624
*/
619625
public function getCheckList(): array {
620-
$this->eventDispatcher->dispatch(IManager::EVENT_NAME_REG_CHECK, new GenericEvent($this));
626+
$this->dispatcher->dispatchTyped(new RegisterChecksEvent($this));
627+
$this->legacyEventDispatcher->dispatch(IManager::EVENT_NAME_REG_CHECK, new GenericEvent($this));
621628

622629
return array_merge($this->getBuildInChecks(), $this->registeredChecks);
623630
}

lib/composer/composer/autoload_classmap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,9 @@
489489
'OCP\\WorkflowEngine\\EntityContext\\IDisplayText' => $baseDir . '/lib/public/WorkflowEngine/EntityContext/IDisplayText.php',
490490
'OCP\\WorkflowEngine\\EntityContext\\IIcon' => $baseDir . '/lib/public/WorkflowEngine/EntityContext/IIcon.php',
491491
'OCP\\WorkflowEngine\\EntityContext\\IUrl' => $baseDir . '/lib/public/WorkflowEngine/EntityContext/IUrl.php',
492+
'OCP\\WorkflowEngine\\Events\\RegisterChecksEvent' => $baseDir . '/lib/public/WorkflowEngine/Events/RegisterChecksEvent.php',
493+
'OCP\\WorkflowEngine\\Events\\RegisterEntitiesEvent' => $baseDir . '/lib/public/WorkflowEngine/Events/RegisterEntitiesEvent.php',
494+
'OCP\\WorkflowEngine\\Events\\RegisterOperationsEvent' => $baseDir . '/lib/public/WorkflowEngine/Events/RegisterOperationsEvent.php',
492495
'OCP\\WorkflowEngine\\GenericEntityEvent' => $baseDir . '/lib/public/WorkflowEngine/GenericEntityEvent.php',
493496
'OCP\\WorkflowEngine\\ICheck' => $baseDir . '/lib/public/WorkflowEngine/ICheck.php',
494497
'OCP\\WorkflowEngine\\IComplexOperation' => $baseDir . '/lib/public/WorkflowEngine/IComplexOperation.php',

lib/composer/composer/autoload_static.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,9 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
518518
'OCP\\WorkflowEngine\\EntityContext\\IDisplayText' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/EntityContext/IDisplayText.php',
519519
'OCP\\WorkflowEngine\\EntityContext\\IIcon' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/EntityContext/IIcon.php',
520520
'OCP\\WorkflowEngine\\EntityContext\\IUrl' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/EntityContext/IUrl.php',
521+
'OCP\\WorkflowEngine\\Events\\RegisterChecksEvent' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/Events/RegisterChecksEvent.php',
522+
'OCP\\WorkflowEngine\\Events\\RegisterEntitiesEvent' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/Events/RegisterEntitiesEvent.php',
523+
'OCP\\WorkflowEngine\\Events\\RegisterOperationsEvent' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/Events/RegisterOperationsEvent.php',
521524
'OCP\\WorkflowEngine\\GenericEntityEvent' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/GenericEntityEvent.php',
522525
'OCP\\WorkflowEngine\\ICheck' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/ICheck.php',
523526
'OCP\\WorkflowEngine\\IComplexOperation' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IComplexOperation.php',
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* @copyright Copyright (c) 2019, Roeland Jago Douma <[email protected]>
5+
*
6+
* @author Roeland Jago Douma <[email protected]>
7+
*
8+
* @license GNU AGPL version 3 or any later version
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Affero General Public License as
12+
* published by the Free Software Foundation, either version 3 of the
13+
* License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*
23+
*/
24+
25+
namespace OCP\WorkflowEngine\Events;
26+
27+
use OCP\EventDispatcher\Event;
28+
use OCP\WorkflowEngine\ICheck;
29+
use OCP\WorkflowEngine\IManager;
30+
31+
class RegisterChecksEvent extends Event {
32+
33+
/** @var IManager */
34+
private $manager;
35+
36+
public function __construct(IManager $manager) {
37+
parent::__construct();
38+
39+
$this->manager = $manager;
40+
}
41+
42+
public function registerCheck(ICheck $check): void {
43+
$this->manager->registerCheck($check);
44+
}
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* @copyright Copyright (c) 2019, Roeland Jago Douma <[email protected]>
5+
*
6+
* @author Roeland Jago Douma <[email protected]>
7+
*
8+
* @license GNU AGPL version 3 or any later version
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Affero General Public License as
12+
* published by the Free Software Foundation, either version 3 of the
13+
* License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*
23+
*/
24+
25+
namespace OCP\WorkflowEngine\Events;
26+
27+
use OCP\EventDispatcher\Event;
28+
use OCP\WorkflowEngine\IEntity;
29+
use OCP\WorkflowEngine\IManager;
30+
31+
class RegisterEntitiesEvent extends Event {
32+
33+
/** @var IManager */
34+
private $manager;
35+
36+
public function __construct(IManager $manager) {
37+
parent::__construct();
38+
39+
$this->manager = $manager;
40+
}
41+
42+
public function registerEntity(IEntity $entity): void {
43+
$this->manager->registerEntity($entity);
44+
}
45+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
declare(strict_types=1);
3+
/**
4+
* @copyright Copyright (c) 2019, Roeland Jago Douma <[email protected]>
5+
*
6+
* @author Roeland Jago Douma <[email protected]>
7+
*
8+
* @license GNU AGPL version 3 or any later version
9+
*
10+
* This program is free software: you can redistribute it and/or modify
11+
* it under the terms of the GNU Affero General Public License as
12+
* published by the Free Software Foundation, either version 3 of the
13+
* License, or (at your option) any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful,
16+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
* GNU Affero General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU Affero General Public License
21+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22+
*
23+
*/
24+
25+
namespace OCP\WorkflowEngine\Events;
26+
27+
use OCP\EventDispatcher\Event;
28+
use OCP\WorkflowEngine\IManager;
29+
use OCP\WorkflowEngine\IOperation;
30+
31+
class RegisterOperationsEvent extends Event {
32+
33+
/** @var IManager */
34+
private $manager;
35+
36+
public function __construct(IManager $manager) {
37+
parent::__construct();
38+
39+
$this->manager = $manager;
40+
}
41+
42+
public function registerOperation(IOperation $operation): void {
43+
$this->manager->registerOperation($operation);
44+
}
45+
}

lib/public/WorkflowEngine/IManager.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,32 @@ interface IManager {
3535
const SCOPE_ADMIN = 0;
3636
const SCOPE_USER = 1;
3737

38+
/**
39+
* @depreacted Will be removed in NC19. Use the dedicated events in OCP\WorkflowEngine\Events
40+
*/
3841
const EVENT_NAME_REG_OPERATION = 'OCP\WorkflowEngine::registerOperations';
3942
const EVENT_NAME_REG_ENTITY = 'OCP\WorkflowEngine::registerEntities';
4043
const EVENT_NAME_REG_CHECK = 'OCP\WorkflowEngine::registerChecks';
4144

4245
/**
43-
* Listen to `\OCP\WorkflowEngine::EVENT_NAME_REG_ENTITY` at the
44-
* EventDispatcher for registering your entities.
46+
* Listen to `OCP\WorkflowEngine\Events\RegisterEntitiesEvent` at the
47+
* IEventDispatcher for registering your entities.
4548
*
4649
* @since 18.0.0
4750
*/
4851
public function registerEntity(IEntity $entity): void;
4952

5053
/**
51-
* Listen to `\OCP\WorkflowEngine::EVENT_NAME_REG_OPERATION` at the
52-
* EventDispatcher for registering your operators.
54+
* Listen to `OCP\WorkflowEngine\Events\RegisterOperationsEvent` at the
55+
* IEventDispatcher for registering your operators.
5356
*
5457
* @since 18.0.0
5558
*/
5659
public function registerOperation(IOperation $operator): void;
5760

5861
/**
59-
* Listen to `\OCP\WorkflowEngine::EVENT_NAME_REG_CHECK` at the
60-
* EventDispatcher for registering your operators.
62+
* Listen to `OCP\WorkflowEngine\Events\RegisterChecksEvent` at the
63+
* IEventDispatcher for registering your operators.
6164
*
6265
* @since 18.0.0
6366
*/

0 commit comments

Comments
 (0)