Completed
Push — master ( e4436e...70eef2 )
by Lukas
14:47
created

OCSShareAPIMiddleware::beforeController()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
cc 3
eloc 4
c 2
b 0
f 2
nc 3
nop 2
dl 0
loc 7
rs 9.4285
1
<?php
2
3
namespace OCA\Files_Sharing\Middleware;
4
5
use OCA\Files_Sharing\API\Share20OCS;
6
use OCP\AppFramework\Http\Response;
7
use OCP\AppFramework\Middleware;
8
use OCP\AppFramework\OCS\OCSNotFoundException;
9
use OCP\IL10N;
10
use OCP\Share\IManager;
11
12
class OCSShareAPIMiddleware extends Middleware {
13
	/** @var IManager */
14
	private $shareManager;
15
	/** @var IL10N */
16
	private $l;
17
18
	public function __construct(IManager $shareManager,
19
								IL10N $l) {
20
		$this->shareManager = $shareManager;
21
		$this->l = $l;
22
	}
23
24
	/**
25
	 * @param \OCP\AppFramework\Controller $controller
26
	 * @param string $methodName
27
	 *
28
	 * @throws OCSNotFoundException
29
	 */
30
	public function beforeController($controller, $methodName) {
31
		if ($controller instanceof Share20OCS) {
32
			if (!$this->shareManager->shareApiEnabled()) {
33
				throw new OCSNotFoundException($this->l->t('Share API is disabled'));
34
			}
35
		}
36
	}
37
38
	/**
39
	 * @param \OCP\AppFramework\Controller $controller
40
	 * @param string $methodName
41
	 * @param Response $response
42
	 * @return Response
43
	 */
44
	public function afterController($controller, $methodName, Response $response) {
45
		if ($controller instanceof Share20OCS) {
46
			/** @var Share20OCS $controller */
47
			$controller->cleanup();
48
		}
49
50
		return $response;
51
	}
52
}
53