Completed
Pull Request — master (#164)
by Blizzz
04:08
created

Application   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 1
dl 0
loc 42
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A addStorageWrapper() 0 4 1
A addStorageWrapperCallback() 0 13 3
A register() 0 4 1
A boot() 0 2 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016 Morris Jobke <[email protected]>
4
 *
5
 * @license GNU AGPL version 3 or any later version
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU Affero General Public License as
9
 * published by the Free Software Foundation, either version 3 of the
10
 * License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 *
20
 */
21
22
namespace OCA\FilesAccessControl\AppInfo;
23
24
use OC;
25
use OC\Files\Filesystem;
26
use OCA\Files_Sharing\SharedStorage;
27
use OCA\FilesAccessControl\Listener\FlowRegisterOperationListener;
28
use OCA\FilesAccessControl\Operation;
29
use OCA\FilesAccessControl\StorageWrapper;
30
use OCP\AppFramework\App;
31
use OCP\AppFramework\Bootstrap\IBootContext;
32
use OCP\AppFramework\Bootstrap\IBootstrap;
33
use OCP\AppFramework\Bootstrap\IRegistrationContext;
34
use OCP\Files\Storage\IStorage;
35
use OCP\Util;
36
use OCP\WorkflowEngine\Events\RegisterOperationsEvent;
37
use OCP\WorkflowEngine\IManager;
38
39
class Application extends App implements IBootstrap {
40
41
	public function __construct() {
42
		parent::__construct('files_accesscontrol');
43
	}
44
45
	/**
46
	 * @internal
47
	 */
48
	public function addStorageWrapper() {
49
		// Needs to be added as the first layer
50
		Filesystem::addStorageWrapper('files_accesscontrol', [$this, 'addStorageWrapperCallback'], -10);
51
	}
52
53
	/**
54
	 * @internal
55
	 * @param $mountPoint
56
	 * @param IStorage $storage
57
	 * @return StorageWrapper|IStorage
58
	 */
59
	public function addStorageWrapperCallback($mountPoint, IStorage $storage) {
60
		if (!OC::$CLI && !$storage->instanceOfStorage(SharedStorage::class)) {
61
			/** @var Operation $operation */
62
			$operation = $this->getContainer()->query(Operation::class);
63
			return new StorageWrapper([
64
				'storage' => $storage,
65
				'mountPoint' => $mountPoint,
66
				'operation' => $operation,
67
			]);
68
		}
69
70
		return $storage;
71
	}
72
73
	public function register(IRegistrationContext $context): void {
74
		Util::connectHook('OC_Filesystem', 'preSetup', $this, 'addStorageWrapper');
75
		$context->registerEventListener(RegisterOperationsEvent::class, FlowRegisterOperationListener::class);
76
	}
77
78
	public function boot(IBootContext $context): void {
79
	}
80
}
81