aboutsummaryrefslogtreecommitdiffstats
path: root/apps/workflowengine/lib/Check/Directory.php
blob: 4acdf00672e336d7f2a6f5ab75bc704df77dd6fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace OCA\WorkflowEngine\Check;

use OCA\WorkflowEngine\Entity\File;
use OCP\IL10N;
use OCP\WorkflowEngine\IFileCheck;

class Directory extends AbstractStringCheck implements IFileCheck {
	use TFileCheck;

	/**
	 * @param IL10N $l
	 */
	public function __construct(
		IL10N $l,
	) {
		parent::__construct($l);
	}

	/**
	 * @return string
	 */
	protected function getActualValue(): string {
		if ($this->path === null) {
			return '';
		}
		// files/some/path -> some/path
		return preg_replace('/^files\//', '', pathinfo($this->path, PATHINFO_DIRNAME));
	}

	/**
	 * @param string $operator
	 * @param string $checkValue
	 * @param string $actualValue
	 * @return bool
	 */
	protected function executeStringCheck($operator, $checkValue, $actualValue) {
		if ($operator === 'is' || $operator === '!is') {
			$checkValue = ltrim(rtrim($checkValue, '/'), '/');
		}
		return parent::executeStringCheck($operator, $checkValue, $actualValue);
	}

	public function supportedEntities(): array {
		return [ File::class ];
	}

	public function isAvailableForScope(int $scope): bool {
		return true;
	}
}