From 849d025d093d1c80d3820901d20bf6a664c6af02 Mon Sep 17 00:00:00 2001
From: Arthur Schiwon <blizzz@arthur-schiwon.de>
Date: Mon, 9 Sep 2019 16:53:59 +0200
Subject: [PATCH] let a dedicate service serve a stateful process

* includes making ICheck not requiring any context setter
* and IFileCheck extending the IEntityCheck as entity data can be handed in
  via Dispatcher

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
---
 .../composer/composer/autoload_classmap.php   |   3 +-
 .../composer/composer/autoload_static.php     |   3 +-
 .../lib/Check/AbstractStringCheck.php         |   5 -
 apps/workflowengine/lib/Check/FileSize.php    |   5 -
 .../lib/Check/RequestRemoteAddress.php        |   5 -
 apps/workflowengine/lib/Check/RequestTime.php |   5 -
 .../Check/{AFileCheck.php => TFileCheck.php}  |   2 -
 .../lib/Check/UserGroupMembership.php         |   5 -
 apps/workflowengine/lib/Manager.php           |  97 +------------
 .../lib/Service/RuleMatcher.php               | 137 ++++++++++++++++++
 lib/composer/composer/autoload_classmap.php   |   3 +-
 lib/composer/composer/autoload_static.php     |   3 +-
 lib/public/WorkflowEngine/ICheck.php          |  20 ---
 lib/public/WorkflowEngine/IEntityCheck.php    |  53 +++++++
 lib/public/WorkflowEngine/IFileCheck.php      |   6 +-
 lib/public/WorkflowEngine/IManager.php        |  23 +--
 .../{IEntityAware.php => IRuleMatcher.php}    |   7 +-
 17 files changed, 213 insertions(+), 169 deletions(-)
 rename apps/workflowengine/lib/Check/{AFileCheck.php => TFileCheck.php} (96%)
 create mode 100644 apps/workflowengine/lib/Service/RuleMatcher.php
 create mode 100644 lib/public/WorkflowEngine/IEntityCheck.php
 rename lib/public/WorkflowEngine/{IEntityAware.php => IRuleMatcher.php} (85%)

diff --git a/apps/workflowengine/composer/composer/autoload_classmap.php b/apps/workflowengine/composer/composer/autoload_classmap.php
index 6264358788c..0de2a50234c 100644
--- a/apps/workflowengine/composer/composer/autoload_classmap.php
+++ b/apps/workflowengine/composer/composer/autoload_classmap.php
@@ -16,7 +16,7 @@ return array(
     'OCA\\WorkflowEngine\\Check\\RequestTime' => $baseDir . '/../lib/Check/RequestTime.php',
     'OCA\\WorkflowEngine\\Check\\RequestURL' => $baseDir . '/../lib/Check/RequestURL.php',
     'OCA\\WorkflowEngine\\Check\\RequestUserAgent' => $baseDir . '/../lib/Check/RequestUserAgent.php',
-    'OCA\\WorkflowEngine\\Check\\TFileCheck' => $baseDir . '/../lib/Check/AFileCheck.php',
+    'OCA\\WorkflowEngine\\Check\\TFileCheck' => $baseDir . '/../lib/Check/TFileCheck.php',
     'OCA\\WorkflowEngine\\Check\\UserGroupMembership' => $baseDir . '/../lib/Check/UserGroupMembership.php',
     'OCA\\WorkflowEngine\\Command\\Index' => $baseDir . '/../lib/Command/Index.php',
     'OCA\\WorkflowEngine\\Controller\\AWorkflowController' => $baseDir . '/../lib/Controller/AWorkflowController.php',
@@ -28,6 +28,7 @@ return array(
     'OCA\\WorkflowEngine\\Manager' => $baseDir . '/../lib/Manager.php',
     'OCA\\WorkflowEngine\\Migration\\PopulateNewlyIntroducedDatabaseFields' => $baseDir . '/../lib/Migration/PopulateNewlyIntroducedDatabaseFields.php',
     'OCA\\WorkflowEngine\\Migration\\Version2019Date20190808074233' => $baseDir . '/../lib/Migration/Version2019Date20190808074233.php',
+    'OCA\\WorkflowEngine\\Service\\RuleMatcher' => $baseDir . '/../lib/Service/RuleMatcher.php',
     'OCA\\WorkflowEngine\\Settings\\ASettings' => $baseDir . '/../lib/Settings/ASettings.php',
     'OCA\\WorkflowEngine\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php',
     'OCA\\WorkflowEngine\\Settings\\Personal' => $baseDir . '/../lib/Settings/Personal.php',
diff --git a/apps/workflowengine/composer/composer/autoload_static.php b/apps/workflowengine/composer/composer/autoload_static.php
index cd370986f15..0f8a488295b 100644
--- a/apps/workflowengine/composer/composer/autoload_static.php
+++ b/apps/workflowengine/composer/composer/autoload_static.php
@@ -31,7 +31,7 @@ class ComposerStaticInitWorkflowEngine
         'OCA\\WorkflowEngine\\Check\\RequestTime' => __DIR__ . '/..' . '/../lib/Check/RequestTime.php',
         'OCA\\WorkflowEngine\\Check\\RequestURL' => __DIR__ . '/..' . '/../lib/Check/RequestURL.php',
         'OCA\\WorkflowEngine\\Check\\RequestUserAgent' => __DIR__ . '/..' . '/../lib/Check/RequestUserAgent.php',
-        'OCA\\WorkflowEngine\\Check\\TFileCheck' => __DIR__ . '/..' . '/../lib/Check/AFileCheck.php',
+        'OCA\\WorkflowEngine\\Check\\TFileCheck' => __DIR__ . '/..' . '/../lib/Check/TFileCheck.php',
         'OCA\\WorkflowEngine\\Check\\UserGroupMembership' => __DIR__ . '/..' . '/../lib/Check/UserGroupMembership.php',
         'OCA\\WorkflowEngine\\Command\\Index' => __DIR__ . '/..' . '/../lib/Command/Index.php',
         'OCA\\WorkflowEngine\\Controller\\AWorkflowController' => __DIR__ . '/..' . '/../lib/Controller/AWorkflowController.php',
@@ -43,6 +43,7 @@ class ComposerStaticInitWorkflowEngine
         'OCA\\WorkflowEngine\\Manager' => __DIR__ . '/..' . '/../lib/Manager.php',
         'OCA\\WorkflowEngine\\Migration\\PopulateNewlyIntroducedDatabaseFields' => __DIR__ . '/..' . '/../lib/Migration/PopulateNewlyIntroducedDatabaseFields.php',
         'OCA\\WorkflowEngine\\Migration\\Version2019Date20190808074233' => __DIR__ . '/..' . '/../lib/Migration/Version2019Date20190808074233.php',
+        'OCA\\WorkflowEngine\\Service\\RuleMatcher' => __DIR__ . '/..' . '/../lib/Service/RuleMatcher.php',
         'OCA\\WorkflowEngine\\Settings\\ASettings' => __DIR__ . '/..' . '/../lib/Settings/ASettings.php',
         'OCA\\WorkflowEngine\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php',
         'OCA\\WorkflowEngine\\Settings\\Personal' => __DIR__ . '/..' . '/../lib/Settings/Personal.php',
diff --git a/apps/workflowengine/lib/Check/AbstractStringCheck.php b/apps/workflowengine/lib/Check/AbstractStringCheck.php
index ec9a1945d9c..e86ac6bec17 100644
--- a/apps/workflowengine/lib/Check/AbstractStringCheck.php
+++ b/apps/workflowengine/lib/Check/AbstractStringCheck.php
@@ -24,7 +24,6 @@ namespace OCA\WorkflowEngine\Check;
 
 use OCP\IL10N;
 use OCP\WorkflowEngine\ICheck;
-use OCP\WorkflowEngine\IEntity;
 use OCP\WorkflowEngine\IManager;
 
 abstract class AbstractStringCheck implements ICheck {
@@ -121,8 +120,4 @@ abstract class AbstractStringCheck implements ICheck {
 		$this->matches[$patternHash][$subjectHash] = preg_match($pattern, $subject);
 		return $this->matches[$patternHash][$subjectHash];
 	}
-
-	public function setEntitySubject(IEntity $entity, $subject): void {
-		// Noop
-	}
 }
diff --git a/apps/workflowengine/lib/Check/FileSize.php b/apps/workflowengine/lib/Check/FileSize.php
index 2ad4bb09e01..736a3d932fb 100644
--- a/apps/workflowengine/lib/Check/FileSize.php
+++ b/apps/workflowengine/lib/Check/FileSize.php
@@ -23,7 +23,6 @@ namespace OCA\WorkflowEngine\Check;
 
 
 use OCA\WorkflowEngine\Entity\File;
-use OCP\Files\Storage\IStorage;
 use OCP\IL10N;
 use OCP\IRequest;
 use OCP\Util;
@@ -119,8 +118,4 @@ class FileSize implements ICheck {
 	public function isAvailableForScope(int $scope): bool {
 		return true;
 	}
-
-	public function setEntitySubject(IEntity $entity, $subject): void {
-		// NOOP
-	}
 }
diff --git a/apps/workflowengine/lib/Check/RequestRemoteAddress.php b/apps/workflowengine/lib/Check/RequestRemoteAddress.php
index 0079db4b831..00029771b52 100644
--- a/apps/workflowengine/lib/Check/RequestRemoteAddress.php
+++ b/apps/workflowengine/lib/Check/RequestRemoteAddress.php
@@ -25,7 +25,6 @@ namespace OCA\WorkflowEngine\Check;
 use OCP\IL10N;
 use OCP\IRequest;
 use OCP\WorkflowEngine\ICheck;
-use OCP\WorkflowEngine\IEntity;
 
 class RequestRemoteAddress implements ICheck {
 
@@ -171,8 +170,4 @@ class RequestRemoteAddress implements ICheck {
 	public function isAvailableForScope(int $scope): bool {
 		return true;
 	}
-
-	public function setEntitySubject(IEntity $entity, $subject): void {
-		// NOOP
-	}
 }
diff --git a/apps/workflowengine/lib/Check/RequestTime.php b/apps/workflowengine/lib/Check/RequestTime.php
index bf37bf3d2ba..a6ab4a961ed 100644
--- a/apps/workflowengine/lib/Check/RequestTime.php
+++ b/apps/workflowengine/lib/Check/RequestTime.php
@@ -25,7 +25,6 @@ namespace OCA\WorkflowEngine\Check;
 use OCP\AppFramework\Utility\ITimeFactory;
 use OCP\IL10N;
 use OCP\WorkflowEngine\ICheck;
-use OCP\WorkflowEngine\IEntity;
 
 class RequestTime implements ICheck {
 
@@ -134,8 +133,4 @@ class RequestTime implements ICheck {
 	public function supportedEntities(): array {
 		return [];
 	}
-
-	public function setEntitySubject(IEntity $entity, $subject): void {
-		// NOOP
-	}
 }
diff --git a/apps/workflowengine/lib/Check/AFileCheck.php b/apps/workflowengine/lib/Check/TFileCheck.php
similarity index 96%
rename from apps/workflowengine/lib/Check/AFileCheck.php
rename to apps/workflowengine/lib/Check/TFileCheck.php
index 45d251b1659..44a39aadfde 100644
--- a/apps/workflowengine/lib/Check/AFileCheck.php
+++ b/apps/workflowengine/lib/Check/TFileCheck.php
@@ -28,9 +28,7 @@ use OCA\WorkflowEngine\AppInfo\Application;
 use OCA\WorkflowEngine\Entity\File;
 use OCP\Files\Node;
 use OCP\Files\Storage\IStorage;
-use OCP\WorkflowEngine\ICheck;
 use OCP\WorkflowEngine\IEntity;
-use OCP\WorkflowEngine\IFileCheck;
 
 trait TFileCheck {
 	/** @var IStorage */
diff --git a/apps/workflowengine/lib/Check/UserGroupMembership.php b/apps/workflowengine/lib/Check/UserGroupMembership.php
index 55f1d017ed0..8839820050a 100644
--- a/apps/workflowengine/lib/Check/UserGroupMembership.php
+++ b/apps/workflowengine/lib/Check/UserGroupMembership.php
@@ -27,7 +27,6 @@ use OCP\IL10N;
 use OCP\IUser;
 use OCP\IUserSession;
 use OCP\WorkflowEngine\ICheck;
-use OCP\WorkflowEngine\IEntity;
 use OCP\WorkflowEngine\IManager;
 
 class UserGroupMembership implements ICheck {
@@ -114,8 +113,4 @@ class UserGroupMembership implements ICheck {
 		// admin only by default
 		return $scope === IManager::SCOPE_ADMIN;
 	}
-
-	public function setEntitySubject(IEntity $entity, $subject): void {
-		// NOOP
-	}
 }
diff --git a/apps/workflowengine/lib/Manager.php b/apps/workflowengine/lib/Manager.php
index 2e78b75aeb8..efe6c387059 100644
--- a/apps/workflowengine/lib/Manager.php
+++ b/apps/workflowengine/lib/Manager.php
@@ -21,7 +21,6 @@
 
 namespace OCA\WorkflowEngine;
 
-use OC\Files\Storage\Wrapper\Jail;
 use Doctrine\DBAL\DBALException;
 use OC\Cache\CappedMemoryCache;
 use OCA\WorkflowEngine\Check\FileMimeType;
@@ -35,6 +34,7 @@ use OCA\WorkflowEngine\Check\RequestUserAgent;
 use OCA\WorkflowEngine\Check\UserGroupMembership;
 use OCA\WorkflowEngine\Entity\File;
 use OCA\WorkflowEngine\Helper\ScopeContext;
+use OCA\WorkflowEngine\Service\RuleMatcher;
 use OCP\AppFramework\QueryException;
 use OCP\DB\QueryBuilder\IQueryBuilder;
 use OCP\Files\Storage\IStorage;
@@ -46,14 +46,14 @@ use OCP\IUserSession;
 use OCP\WorkflowEngine\ICheck;
 use OCP\WorkflowEngine\IComplexOperation;
 use OCP\WorkflowEngine\IEntity;
-use OCP\WorkflowEngine\IEntityAware;
 use OCP\WorkflowEngine\IEntityEvent;
 use OCP\WorkflowEngine\IManager;
 use OCP\WorkflowEngine\IOperation;
+use OCP\WorkflowEngine\IRuleMatcher;
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
 use Symfony\Component\EventDispatcher\GenericEvent;
 
-class Manager implements IManager, IEntityAware {
+class Manager implements IManager {
 
 	/** @var IStorage */
 	protected $storage;
@@ -122,77 +122,8 @@ class Manager implements IManager, IEntityAware {
 		$this->session = $session;
 	}
 
-	/**
-	 * @inheritdoc
-	 */
-	public function setFileInfo(IStorage $storage, $path) {
-		$this->storage = $storage;
-
-		if ($storage->instanceOfStorage(Jail::class)) {
-			/** @var Jail $storage */
-			$path = $storage->getJailedPath($path);
-		}
-		$this->path = $path;
-	}
-
-	/**
-	 * @inheritdoc
-	 */
-	public function getMatchingOperations($class, $returnFirstMatchingOperationOnly = true) {
-		$scopes[] = new ScopeContext(IManager::SCOPE_ADMIN);
-		$user = $this->session->getUser();
-		if($user !== null) {
-			$scopes[] = new ScopeContext(IManager::SCOPE_USER, $user->getUID());
-		}
-
-		$operations = [];
-		foreach ($scopes as $scope) {
-			$operations = array_merge($operations, $this->getOperations($class, $scope));
-		}
-
-		$matches = [];
-		foreach ($operations as $operation) {
-			$checkIds = json_decode($operation['checks'], true);
-			$checks = $this->getChecks($checkIds);
-
-			foreach ($checks as $check) {
-				if (!$this->check($check)) {
-					// Check did not match, continue with the next operation
-					continue 2;
-				}
-			}
-
-			if ($returnFirstMatchingOperationOnly) {
-				return $operation;
-			}
-			$matches[] = $operation;
-		}
-
-		return $matches;
-	}
-
-	/**
-	 * @param array $check
-	 * @return bool
-	 */
-	protected function check(array $check) {
-		try {
-			$checkInstance = $this->container->query($check['class']);
-		} catch (QueryException $e) {
-			// Check does not exist, assume it matches.
-			return true;
-		}
-
-		if ($checkInstance instanceof IEntityAware && $this->entity !== null) {
-			$checkInstance->setEntity($this->entity);
-			return $checkInstance->executeCheck($check['operator'], $check['value']);
-		} elseif ($checkInstance instanceof ICheck) {
-			$checkInstance->setFileInfo($this->storage, $this->path);
-			return $checkInstance->executeCheck($check['operator'], $check['value']);
-		} else {
-			// Check is invalid
-			throw new \UnexpectedValueException($this->l->t('Check %s is invalid or does not exist', $check['class']));
-		}
+	public function getRuleMatcher(): IRuleMatcher {
+		return new RuleMatcher($this->session, $this->container, $this->l, $this);
 	}
 
 	public function getAllConfiguredEvents() {
@@ -634,24 +565,6 @@ class Manager implements IManager, IEntityAware {
 		return $operation;
 	}
 
-	/**
-	 * @param object $entity
-	 * @since 18.0.0
-	 */
-	public function setEntity($entity) {
-		if(!is_object($entity)) {
-			$this->container->getLogger()->logException(
-				new \InvalidArgumentException('provided entity is not an object'),
-				[
-					'app' => 'workflowengine',
-					'level' => ILogger::ERROR,
-				]
-			);
-			return;
-		}
-		$this->entity = $entity;
-	}
-
 	/**
 	 * @return IEntity[]
 	 */
diff --git a/apps/workflowengine/lib/Service/RuleMatcher.php b/apps/workflowengine/lib/Service/RuleMatcher.php
new file mode 100644
index 00000000000..bc92eeee818
--- /dev/null
+++ b/apps/workflowengine/lib/Service/RuleMatcher.php
@@ -0,0 +1,137 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\WorkflowEngine\Service;
+
+use OCA\WorkflowEngine\AppInfo\Application;
+use OCA\WorkflowEngine\Entity\File;
+use OCA\WorkflowEngine\Helper\ScopeContext;
+use OCA\WorkflowEngine\Manager;
+use OCP\AppFramework\QueryException;
+use OCP\Files\Node;
+use OCP\Files\Storage\IStorage;
+use OCP\IL10N;
+use OCP\IServerContainer;
+use OCP\IUserSession;
+use OCP\WorkflowEngine\ICheck;
+use OCP\WorkflowEngine\IEntity;
+use OCP\WorkflowEngine\IFileCheck;
+use OCP\WorkflowEngine\IManager;
+use OCP\WorkflowEngine\IRuleMatcher;
+
+class RuleMatcher implements IRuleMatcher {
+
+	/** @var IUserSession */
+	protected $session;
+	/** @var IManager */
+	protected $manager;
+	/** @var array */
+	protected $contexts;
+	/** @var IServerContainer */
+	protected $container;
+	/** @var array */
+	protected $fileInfo = [];
+	/** @var IL10N */
+	protected $l;
+
+	public function __construct(IUserSession $session, IServerContainer $container, IL10N $l, Manager $manager) {
+		$this->session = $session;
+		$this->manager = $manager;
+		$this->container = $container;
+		$this->l = $l;
+	}
+
+	public function setFileInfo(IStorage $storage, string $path): void {
+		$this->fileInfo['storage'] = $storage;
+		$this->fileInfo['path'] = $path;
+	}
+
+
+	public function setEntitySubject(IEntity $entity, $subject): void {
+		$this->contexts[get_class($entity)] = [$entity, $subject];
+	}
+
+	public function getMatchingOperations(string $class, bool $returnFirstMatchingOperationOnly = true): array {
+		$scopes[] = new ScopeContext(IManager::SCOPE_ADMIN);
+		$user = $this->session->getUser();
+		if($user !== null) {
+			$scopes[] = new ScopeContext(IManager::SCOPE_USER, $user->getUID());
+		}
+
+		$operations = [];
+		foreach ($scopes as $scope) {
+			$operations = array_merge($operations, $this->manager->getOperations($class, $scope));
+		}
+
+		$matches = [];
+		foreach ($operations as $operation) {
+			$checkIds = json_decode($operation['checks'], true);
+			$checks = $this->manager->getChecks($checkIds);
+
+			foreach ($checks as $check) {
+				if (!$this->check($check)) {
+					// Check did not match, continue with the next operation
+					continue 2;
+				}
+			}
+
+			if ($returnFirstMatchingOperationOnly) {
+				return $operation;
+			}
+			$matches[] = $operation;
+		}
+
+		return $matches;
+	}
+
+	/**
+	 * @param array $check
+	 * @return bool
+	 */
+	public function check(array $check) {
+		try {
+			$checkInstance = $this->container->query($check['class']);
+		} catch (QueryException $e) {
+			// Check does not exist, assume it matches.
+			return true;
+		}
+
+		if ($checkInstance instanceof ICheck) {
+			foreach($this->contexts as $entityInfo) {
+				list($entity, $subject) = $entityInfo;
+				$checkInstance->setEntitySubject($entity, $subject);
+			}
+			return $checkInstance->executeCheck($check['operator'], $check['value']);
+		} elseif ($checkInstance instanceof IFileCheck) {
+			if(empty($this->fileInfo)) {
+				throw new \RuntimeException('Must set file info before running the check');
+			}
+			$checkInstance->setFileInfo($this->fileInfo['storage'], $this->fileInfo['path']);
+			return $checkInstance->executeCheck($check['operator'], $check['value']);
+		} else {
+			// Check is invalid
+			throw new \UnexpectedValueException($this->l->t('Check %s is invalid or does not exist', $check['class']));
+		}
+	}
+}
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 4078193b18a..b51b689b629 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -442,11 +442,12 @@ return array(
     'OCP\\WorkflowEngine\\ICheck' => $baseDir . '/lib/public/WorkflowEngine/ICheck.php',
     'OCP\\WorkflowEngine\\IComplexOperation' => $baseDir . '/lib/public/WorkflowEngine/IComplexOperation.php',
     'OCP\\WorkflowEngine\\IEntity' => $baseDir . '/lib/public/WorkflowEngine/IEntity.php',
-    'OCP\\WorkflowEngine\\IEntityAware' => $baseDir . '/lib/public/WorkflowEngine/IEntityAware.php',
+    'OCP\\WorkflowEngine\\IEntityCheck' => $baseDir . '/lib/public/WorkflowEngine/IEntityCheck.php',
     'OCP\\WorkflowEngine\\IEntityEvent' => $baseDir . '/lib/public/WorkflowEngine/IEntityEvent.php',
     'OCP\\WorkflowEngine\\IFileCheck' => $baseDir . '/lib/public/WorkflowEngine/IFileCheck.php',
     'OCP\\WorkflowEngine\\IManager' => $baseDir . '/lib/public/WorkflowEngine/IManager.php',
     'OCP\\WorkflowEngine\\IOperation' => $baseDir . '/lib/public/WorkflowEngine/IOperation.php',
+    'OCP\\WorkflowEngine\\IRuleMatcher' => $baseDir . '/lib/public/WorkflowEngine/IRuleMatcher.php',
     'OCP\\WorkflowEngine\\ISpecificOperation' => $baseDir . '/lib/public/WorkflowEngine/ISpecificOperation.php',
     'OC\\Accounts\\Account' => $baseDir . '/lib/private/Accounts/Account.php',
     'OC\\Accounts\\AccountManager' => $baseDir . '/lib/private/Accounts/AccountManager.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 4cf093dcaa8..1bcefc1dc1c 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -476,11 +476,12 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
         'OCP\\WorkflowEngine\\ICheck' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/ICheck.php',
         'OCP\\WorkflowEngine\\IComplexOperation' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IComplexOperation.php',
         'OCP\\WorkflowEngine\\IEntity' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IEntity.php',
-        'OCP\\WorkflowEngine\\IEntityAware' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IEntityAware.php',
+        'OCP\\WorkflowEngine\\IEntityCheck' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IEntityCheck.php',
         'OCP\\WorkflowEngine\\IEntityEvent' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IEntityEvent.php',
         'OCP\\WorkflowEngine\\IFileCheck' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IFileCheck.php',
         'OCP\\WorkflowEngine\\IManager' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IManager.php',
         'OCP\\WorkflowEngine\\IOperation' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IOperation.php',
+        'OCP\\WorkflowEngine\\IRuleMatcher' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/IRuleMatcher.php',
         'OCP\\WorkflowEngine\\ISpecificOperation' => __DIR__ . '/../../..' . '/lib/public/WorkflowEngine/ISpecificOperation.php',
         'OC\\Accounts\\Account' => __DIR__ . '/../../..' . '/lib/private/Accounts/Account.php',
         'OC\\Accounts\\AccountManager' => __DIR__ . '/../../..' . '/lib/private/Accounts/AccountManager.php',
diff --git a/lib/public/WorkflowEngine/ICheck.php b/lib/public/WorkflowEngine/ICheck.php
index 6e9c2fc765e..f5586e83d51 100644
--- a/lib/public/WorkflowEngine/ICheck.php
+++ b/lib/public/WorkflowEngine/ICheck.php
@@ -70,24 +70,4 @@ interface ICheck {
 	 * @since 18.0.0
 	 */
 	public function isAvailableForScope(int $scope): bool;
-
-	/**
-	 * Equips the check with a subject fitting the Entity. For instance, an
-	 * entity of File will receive an instance of OCP\Files\Node, or a comment
-	 * entity might get an IComment.
-	 *
-	 * The implementing check must be aware of the incoming type.
-	 *
-	 * If an unsupported subject is passed the implementation MAY throw an
-	 * \UnexpectedValueException.
-	 *
-	 * When an implementation does not depend on a subject being passed to it,
-	 * for example RequestTime, the implemented method SHOULD just pass, without
-	 * any further operation.
-	 *
-	 * @param IEntity $entity
-	 * @param mixed $subject
-	 * @throws \UnexpectedValueException
-	 */
-	public function setEntitySubject(IEntity $entity, $subject): void;
 }
diff --git a/lib/public/WorkflowEngine/IEntityCheck.php b/lib/public/WorkflowEngine/IEntityCheck.php
new file mode 100644
index 00000000000..82687a052ba
--- /dev/null
+++ b/lib/public/WorkflowEngine/IEntityCheck.php
@@ -0,0 +1,53 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCP\WorkflowEngine;
+
+
+use OCP\Files\Storage\IStorage;
+
+/**
+ * Interface IFileCheck
+ *
+ * @package OCP\WorkflowEngine
+ * @since 18.0.0
+ */
+interface IEntityCheck {
+	/**
+	 * Equips the check with a subject fitting the Entity. For instance, an
+	 * entity of File will receive an instance of OCP\Files\Node, or a comment
+	 * entity might get an IComment.
+	 *
+	 * The implementing check must be aware of the incoming type.
+	 *
+	 * If an unsupported subject is passed the implementation MAY throw an
+	 * \UnexpectedValueException.
+	 *
+	 * @param IEntity $entity
+	 * @param mixed $subject
+	 * @throws \UnexpectedValueException
+	 */
+	public function setEntitySubject(IEntity $entity, $subject): void;
+
+}
diff --git a/lib/public/WorkflowEngine/IFileCheck.php b/lib/public/WorkflowEngine/IFileCheck.php
index ce15d6c352c..557ba0f3c10 100644
--- a/lib/public/WorkflowEngine/IFileCheck.php
+++ b/lib/public/WorkflowEngine/IFileCheck.php
@@ -33,12 +33,10 @@ use OCP\Files\Storage\IStorage;
  * @package OCP\WorkflowEngine
  * @since 18.0.0
  */
-interface IFileCheck {
+interface IFileCheck extends IEntityCheck {
 	/**
-	 * @param IStorage $storage
-	 * @param string $path
 	 * @since 18.0.0
 	 */
-	public function setFileInfo(IStorage $storage, $path);
+	public function setFileInfo(IStorage $storage, string $path);
 
 }
diff --git a/lib/public/WorkflowEngine/IManager.php b/lib/public/WorkflowEngine/IManager.php
index 8be47d961e7..78fd718ec9e 100644
--- a/lib/public/WorkflowEngine/IManager.php
+++ b/lib/public/WorkflowEngine/IManager.php
@@ -23,9 +23,6 @@
 
 namespace OCP\WorkflowEngine;
 
-
-use OCP\Files\Storage\IStorage;
-
 /**
  * Interface IManager
  *
@@ -41,21 +38,6 @@ interface IManager {
 	const EVENT_NAME_REG_ENTITY = 'OCP\WorkflowEngine::registerEntities';
 	const EVENT_NAME_REG_CHECK = 'OCP\WorkflowEngine::registerChecks';
 
-	/**
-	 * @param IStorage $storage
-	 * @param string $path
-	 * @since 9.1
-	 */
-	public function setFileInfo(IStorage $storage, $path);
-
-	/**
-	 * @param string $class
-	 * @param bool $returnFirstMatchingOperationOnly
-	 * @return array
-	 * @since 9.1
-	 */
-	public function getMatchingOperations($class, $returnFirstMatchingOperationOnly = true);
-
 	/**
 	 * Listen to `\OCP\WorkflowEngine::EVENT_NAME_REG_ENTITY` at the
 	 * EventDispatcher for registering your entities.
@@ -79,4 +61,9 @@ interface IManager {
 	 * @since 18.0.0
 	 */
 	public function registerCheck(ICheck $check): void;
+
+	/**
+	 * @since 18.0.0
+	 */
+	public function getRuleMatcher(): IRuleMatcher;
 }
diff --git a/lib/public/WorkflowEngine/IEntityAware.php b/lib/public/WorkflowEngine/IRuleMatcher.php
similarity index 85%
rename from lib/public/WorkflowEngine/IEntityAware.php
rename to lib/public/WorkflowEngine/IRuleMatcher.php
index 5ef5066f9ad..5569800edb7 100644
--- a/lib/public/WorkflowEngine/IEntityAware.php
+++ b/lib/public/WorkflowEngine/IRuleMatcher.php
@@ -25,16 +25,15 @@ declare(strict_types=1);
 namespace OCP\WorkflowEngine;
 
 /**
- * Interface IEntityAware
+ * Class IRuleMatcher
  *
  * @package OCP\WorkflowEngine
  *
  * @since 18.0.0
  */
-interface IEntityAware {
+interface IRuleMatcher extends IFileCheck {
 	/**
-	 * @param object $entity
 	 * @since 18.0.0
 	 */
-	public function setEntity($entity);
+	public function getMatchingOperations(string $class, bool $returnFirstMatchingOperationOnly = true): array;
 }
-- 
GitLab