Completed
Push — master ( ca3aef...5b2d6b )
by Morris
15:49
created

Application::getSyncService()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Björn Schießle <[email protected]>
6
 * @author Robin Appelman <[email protected]>
7
 * @author Thomas Müller <[email protected]>
8
 *
9
 * @license AGPL-3.0
10
 *
11
 * This code is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License, version 3,
13
 * as published by the Free Software Foundation.
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, version 3,
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
22
 *
23
 */
24
25
namespace OCA\Federation\AppInfo;
26
27
use OCA\Federation\DAV\FedAuth;
28
use OCA\Federation\Hooks;
29
use OCA\Federation\Middleware\AddServerMiddleware;
30
use OCP\AppFramework\App;
31
use OCP\SabrePluginEvent;
32
use OCP\Util;
33
use Sabre\DAV\Auth\Plugin;
34
use Sabre\DAV\Server;
35
36
class Application extends App {
37
38
	/**
39
	 * @param array $urlParams
40
	 */
41
	public function __construct($urlParams = []) {
42
		parent::__construct('federation', $urlParams);
43
		$this->registerMiddleware();
44
	}
45
46
	private function registerMiddleware() {
47
		$container = $this->getContainer();
48
		$container->registerAlias('AddServerMiddleware', AddServerMiddleware::class);
49
		$container->registerMiddleWare('AddServerMiddleware');
50
	}
51
52
	/**
53
	 * listen to federated_share_added hooks to auto-add new servers to the
54
	 * list of trusted servers.
55
	 */
56
	public function registerHooks() {
57
58
		$container = $this->getContainer();
59
		$hooksManager = $container->query(Hooks::class);
60
61
		Util::connectHook(
62
				'OCP\Share',
63
				'federated_share_added',
64
				$hooksManager,
65
				'addServerHook'
66
		);
67
68
		$dispatcher = $container->getServer()->getEventDispatcher();
69
		$dispatcher->addListener('OCA\DAV\Connector\Sabre::authInit', function($event) use($container) {
70
			if ($event instanceof SabrePluginEvent) {
71
				$server = $event->getServer();
72
				if ($server instanceof Server) {
0 ignored issues
show
Bug introduced by
The class Sabre\DAV\Server does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
73
					$authPlugin = $server->getPlugin('auth');
74
					if ($authPlugin instanceof Plugin) {
0 ignored issues
show
Bug introduced by
The class Sabre\DAV\Auth\Plugin does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
75
						$authPlugin->addBackend($container->query(FedAuth::class));
76
					}
77
				}
78
			}
79
		});
80
	}
81
82
}
83