Passed
Push — master ( d23e96...1bc100 )
by Roeland
11:25 queued 10s
created
apps/files_external/lib/Lib/Backend/Backend.php 1 patch
Indentation   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -57,110 +57,110 @@
 block discarded – undo
57 57
  */
58 58
 class Backend implements \JsonSerializable {
59 59
 
60
-	use VisibilityTrait;
61
-	use FrontendDefinitionTrait;
62
-	use PriorityTrait;
63
-	use DependencyTrait;
64
-	use StorageModifierTrait;
65
-	use IdentifierTrait;
66
-
67
-	/** @var string storage class */
68
-	private $storageClass;
69
-
70
-	/** @var array 'scheme' => true, supported authentication schemes */
71
-	private $authSchemes = [];
72
-
73
-	/** @var AuthMechanism|callable authentication mechanism fallback */
74
-	private $legacyAuthMechanism;
75
-
76
-	/**
77
-	 * @return string
78
-	 */
79
-	public function getStorageClass() {
80
-		return $this->storageClass;
81
-	}
82
-
83
-	/**
84
-	 * @param string $class
85
-	 * @return $this
86
-	 */
87
-	public function setStorageClass($class) {
88
-		$this->storageClass = $class;
89
-		return $this;
90
-	}
91
-
92
-	/**
93
-	 * @return array
94
-	 */
95
-	public function getAuthSchemes() {
96
-		if (empty($this->authSchemes)) {
97
-			return [AuthMechanism::SCHEME_NULL => true];
98
-		}
99
-		return $this->authSchemes;
100
-	}
101
-
102
-	/**
103
-	 * @param string $scheme
104
-	 * @return self
105
-	 */
106
-	public function addAuthScheme($scheme) {
107
-		$this->authSchemes[$scheme] = true;
108
-		return $this;
109
-	}
110
-
111
-	/**
112
-	 * @param array $parameters storage parameters, for dynamic mechanism selection
113
-	 * @return AuthMechanism
114
-	 */
115
-	public function getLegacyAuthMechanism(array $parameters = []) {
116
-		if (is_callable($this->legacyAuthMechanism)) {
117
-			return call_user_func($this->legacyAuthMechanism, $parameters);
118
-		}
119
-		return $this->legacyAuthMechanism;
120
-	}
121
-
122
-	/**
123
-	 * @param AuthMechanism $authMechanism
124
-	 * @return self
125
-	 */
126
-	public function setLegacyAuthMechanism(AuthMechanism $authMechanism) {
127
-		$this->legacyAuthMechanism = $authMechanism;
128
-		return $this;
129
-	}
130
-
131
-	/**
132
-	 * @param callable $callback dynamic auth mechanism selection
133
-	 * @return self
134
-	 */
135
-	public function setLegacyAuthMechanismCallback(callable $callback) {
136
-		$this->legacyAuthMechanism = $callback;
137
-	}
138
-
139
-	/**
140
-	 * Serialize into JSON for client-side JS
141
-	 *
142
-	 * @return array
143
-	 */
144
-	public function jsonSerialize() {
145
-		$data = $this->jsonSerializeDefinition();
146
-		$data += $this->jsonSerializeIdentifier();
147
-
148
-		$data['backend'] = $data['name']; // legacy compat
149
-		$data['priority'] = $this->getPriority();
150
-		$data['authSchemes'] = $this->getAuthSchemes();
151
-
152
-		return $data;
153
-	}
154
-
155
-	/**
156
-	 * Check if parameters are satisfied in a StorageConfig
157
-	 *
158
-	 * @param StorageConfig $storage
159
-	 * @return bool
160
-	 */
161
-	public function validateStorage(StorageConfig $storage) {
162
-		return $this->validateStorageDefinition($storage);
163
-	}
60
+    use VisibilityTrait;
61
+    use FrontendDefinitionTrait;
62
+    use PriorityTrait;
63
+    use DependencyTrait;
64
+    use StorageModifierTrait;
65
+    use IdentifierTrait;
66
+
67
+    /** @var string storage class */
68
+    private $storageClass;
69
+
70
+    /** @var array 'scheme' => true, supported authentication schemes */
71
+    private $authSchemes = [];
72
+
73
+    /** @var AuthMechanism|callable authentication mechanism fallback */
74
+    private $legacyAuthMechanism;
75
+
76
+    /**
77
+     * @return string
78
+     */
79
+    public function getStorageClass() {
80
+        return $this->storageClass;
81
+    }
82
+
83
+    /**
84
+     * @param string $class
85
+     * @return $this
86
+     */
87
+    public function setStorageClass($class) {
88
+        $this->storageClass = $class;
89
+        return $this;
90
+    }
91
+
92
+    /**
93
+     * @return array
94
+     */
95
+    public function getAuthSchemes() {
96
+        if (empty($this->authSchemes)) {
97
+            return [AuthMechanism::SCHEME_NULL => true];
98
+        }
99
+        return $this->authSchemes;
100
+    }
101
+
102
+    /**
103
+     * @param string $scheme
104
+     * @return self
105
+     */
106
+    public function addAuthScheme($scheme) {
107
+        $this->authSchemes[$scheme] = true;
108
+        return $this;
109
+    }
110
+
111
+    /**
112
+     * @param array $parameters storage parameters, for dynamic mechanism selection
113
+     * @return AuthMechanism
114
+     */
115
+    public function getLegacyAuthMechanism(array $parameters = []) {
116
+        if (is_callable($this->legacyAuthMechanism)) {
117
+            return call_user_func($this->legacyAuthMechanism, $parameters);
118
+        }
119
+        return $this->legacyAuthMechanism;
120
+    }
121
+
122
+    /**
123
+     * @param AuthMechanism $authMechanism
124
+     * @return self
125
+     */
126
+    public function setLegacyAuthMechanism(AuthMechanism $authMechanism) {
127
+        $this->legacyAuthMechanism = $authMechanism;
128
+        return $this;
129
+    }
130
+
131
+    /**
132
+     * @param callable $callback dynamic auth mechanism selection
133
+     * @return self
134
+     */
135
+    public function setLegacyAuthMechanismCallback(callable $callback) {
136
+        $this->legacyAuthMechanism = $callback;
137
+    }
138
+
139
+    /**
140
+     * Serialize into JSON for client-side JS
141
+     *
142
+     * @return array
143
+     */
144
+    public function jsonSerialize() {
145
+        $data = $this->jsonSerializeDefinition();
146
+        $data += $this->jsonSerializeIdentifier();
147
+
148
+        $data['backend'] = $data['name']; // legacy compat
149
+        $data['priority'] = $this->getPriority();
150
+        $data['authSchemes'] = $this->getAuthSchemes();
151
+
152
+        return $data;
153
+    }
154
+
155
+    /**
156
+     * Check if parameters are satisfied in a StorageConfig
157
+     *
158
+     * @param StorageConfig $storage
159
+     * @return bool
160
+     */
161
+    public function validateStorage(StorageConfig $storage) {
162
+        return $this->validateStorageDefinition($storage);
163
+    }
164 164
 
165 165
 }
166 166
 
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/FrontendDefinitionTrait.php 1 patch
Indentation   +124 added lines, -124 removed lines patch added patch discarded remove patch
@@ -31,129 +31,129 @@
 block discarded – undo
31 31
  */
32 32
 trait FrontendDefinitionTrait {
33 33
 
34
-	/** @var string human-readable mechanism name */
35
-	private $text;
36
-
37
-	/** @var DefinitionParameter[] parameters for mechanism */
38
-	private $parameters = [];
39
-
40
-	/** @var string[] custom JS */
41
-	private $customJs = [];
42
-
43
-	/**
44
-	 * @return string
45
-	 */
46
-	public function getText() {
47
-		return $this->text;
48
-	}
49
-
50
-	/**
51
-	 * @param string $text
52
-	 * @return $this
53
-	 */
54
-	public function setText($text) {
55
-		$this->text = $text;
56
-		return $this;
57
-	}
58
-
59
-	/**
60
-	 * @param FrontendDefinitionTrait $a
61
-	 * @param FrontendDefinitionTrait $b
62
-	 * @return int
63
-	 */
64
-	public static function lexicalCompare(FrontendDefinitionTrait $a, FrontendDefinitionTrait $b) {
65
-		return strcmp($a->getText(), $b->getText());
66
-	}
67
-
68
-	/**
69
-	 * @return DefinitionParameter[]
70
-	 */
71
-	public function getParameters() {
72
-		return $this->parameters;
73
-	}
74
-
75
-	/**
76
-	 * @param DefinitionParameter[] $parameters
77
-	 * @return self
78
-	 */
79
-	public function addParameters(array $parameters) {
80
-		foreach ($parameters as $parameter) {
81
-			$this->addParameter($parameter);
82
-		}
83
-		return $this;
84
-	}
85
-
86
-	/**
87
-	 * @param DefinitionParameter $parameter
88
-	 * @return self
89
-	 */
90
-	public function addParameter(DefinitionParameter $parameter) {
91
-		$this->parameters[$parameter->getName()] = $parameter;
92
-		return $this;
93
-	}
94
-
95
-	/**
96
-	 * @return string[]
97
-	 */
98
-	public function getCustomJs() {
99
-		return $this->customJs;
100
-	}
101
-
102
-	/**
103
-	 * @param string $custom
104
-	 * @return self
105
-	 */
106
-	public function addCustomJs($custom) {
107
-		$this->customJs[] = $custom;
108
-		return $this;
109
-	}
110
-
111
-	/**
112
-	 * @param string $custom
113
-	 * @return self
114
-	 * @deprecated 9.1.0, use addCustomJs() instead
115
-	 */
116
-	public function setCustomJs($custom) {
117
-		$this->customJs = [$custom];
118
-		return $this;
119
-	}
120
-
121
-	/**
122
-	 * Serialize into JSON for client-side JS
123
-	 *
124
-	 * @return array
125
-	 */
126
-	public function jsonSerializeDefinition() {
127
-		$configuration = [];
128
-		foreach ($this->getParameters() as $parameter) {
129
-			$configuration[$parameter->getName()] = $parameter;
130
-		}
131
-
132
-		$data = [
133
-			'name' => $this->getText(),
134
-			'configuration' => $configuration,
135
-			'custom' => $this->getCustomJs(),
136
-		];
137
-		return $data;
138
-	}
139
-
140
-	/**
141
-	 * Check if parameters are satisfied in a StorageConfig
142
-	 *
143
-	 * @param StorageConfig $storage
144
-	 * @return bool
145
-	 */
146
-	public function validateStorageDefinition(StorageConfig $storage) {
147
-		foreach ($this->getParameters() as $name => $parameter) {
148
-			$value = $storage->getBackendOption($name);
149
-			if (!is_null($value) || !$parameter->isOptional()) {
150
-				if (!$parameter->validateValue($value)) {
151
-					return false;
152
-				}
153
-				$storage->setBackendOption($name, $value);
154
-			}
155
-		}
156
-		return true;
157
-	}
34
+    /** @var string human-readable mechanism name */
35
+    private $text;
36
+
37
+    /** @var DefinitionParameter[] parameters for mechanism */
38
+    private $parameters = [];
39
+
40
+    /** @var string[] custom JS */
41
+    private $customJs = [];
42
+
43
+    /**
44
+     * @return string
45
+     */
46
+    public function getText() {
47
+        return $this->text;
48
+    }
49
+
50
+    /**
51
+     * @param string $text
52
+     * @return $this
53
+     */
54
+    public function setText($text) {
55
+        $this->text = $text;
56
+        return $this;
57
+    }
58
+
59
+    /**
60
+     * @param FrontendDefinitionTrait $a
61
+     * @param FrontendDefinitionTrait $b
62
+     * @return int
63
+     */
64
+    public static function lexicalCompare(FrontendDefinitionTrait $a, FrontendDefinitionTrait $b) {
65
+        return strcmp($a->getText(), $b->getText());
66
+    }
67
+
68
+    /**
69
+     * @return DefinitionParameter[]
70
+     */
71
+    public function getParameters() {
72
+        return $this->parameters;
73
+    }
74
+
75
+    /**
76
+     * @param DefinitionParameter[] $parameters
77
+     * @return self
78
+     */
79
+    public function addParameters(array $parameters) {
80
+        foreach ($parameters as $parameter) {
81
+            $this->addParameter($parameter);
82
+        }
83
+        return $this;
84
+    }
85
+
86
+    /**
87
+     * @param DefinitionParameter $parameter
88
+     * @return self
89
+     */
90
+    public function addParameter(DefinitionParameter $parameter) {
91
+        $this->parameters[$parameter->getName()] = $parameter;
92
+        return $this;
93
+    }
94
+
95
+    /**
96
+     * @return string[]
97
+     */
98
+    public function getCustomJs() {
99
+        return $this->customJs;
100
+    }
101
+
102
+    /**
103
+     * @param string $custom
104
+     * @return self
105
+     */
106
+    public function addCustomJs($custom) {
107
+        $this->customJs[] = $custom;
108
+        return $this;
109
+    }
110
+
111
+    /**
112
+     * @param string $custom
113
+     * @return self
114
+     * @deprecated 9.1.0, use addCustomJs() instead
115
+     */
116
+    public function setCustomJs($custom) {
117
+        $this->customJs = [$custom];
118
+        return $this;
119
+    }
120
+
121
+    /**
122
+     * Serialize into JSON for client-side JS
123
+     *
124
+     * @return array
125
+     */
126
+    public function jsonSerializeDefinition() {
127
+        $configuration = [];
128
+        foreach ($this->getParameters() as $parameter) {
129
+            $configuration[$parameter->getName()] = $parameter;
130
+        }
131
+
132
+        $data = [
133
+            'name' => $this->getText(),
134
+            'configuration' => $configuration,
135
+            'custom' => $this->getCustomJs(),
136
+        ];
137
+        return $data;
138
+    }
139
+
140
+    /**
141
+     * Check if parameters are satisfied in a StorageConfig
142
+     *
143
+     * @param StorageConfig $storage
144
+     * @return bool
145
+     */
146
+    public function validateStorageDefinition(StorageConfig $storage) {
147
+        foreach ($this->getParameters() as $name => $parameter) {
148
+            $value = $storage->getBackendOption($name);
149
+            if (!is_null($value) || !$parameter->isOptional()) {
150
+                if (!$parameter->validateValue($value)) {
151
+                    return false;
152
+                }
153
+                $storage->setBackendOption($name, $value);
154
+            }
155
+        }
156
+        return true;
157
+    }
158 158
 
159 159
 }
Please login to merge, or discard this patch.
files_external/lib/Lib/InsufficientDataForMeaningfulAnswerException.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -29,15 +29,15 @@
 block discarded – undo
29 29
  * Authentication mechanism or backend has insufficient data
30 30
  */
31 31
 class InsufficientDataForMeaningfulAnswerException extends StorageNotAvailableException {
32
-	/**
33
-	 * StorageNotAvailableException constructor.
34
-	 *
35
-	 * @param string $message
36
-	 * @param int $code
37
-	 * @param \Exception|null $previous
38
-	 * @since 6.0.0
39
-	 */
40
-	public function __construct($message = '', $code = self::STATUS_INDETERMINATE, \Exception $previous = null) {
41
-		parent::__construct($message, $code, $previous);
42
-	}
32
+    /**
33
+     * StorageNotAvailableException constructor.
34
+     *
35
+     * @param string $message
36
+     * @param int $code
37
+     * @param \Exception|null $previous
38
+     * @since 6.0.0
39
+     */
40
+    public function __construct($message = '', $code = self::STATUS_INDETERMINATE, \Exception $previous = null) {
41
+        parent::__construct($message, $code, $previous);
42
+    }
43 43
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/IdentifierTrait.php 1 patch
Indentation   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -28,76 +28,76 @@
 block discarded – undo
28 28
  */
29 29
 trait IdentifierTrait {
30 30
 
31
-	/** @var string */
32
-	protected $identifier;
31
+    /** @var string */
32
+    protected $identifier;
33 33
 
34
-	/** @var string[] */
35
-	protected $identifierAliases = [];
34
+    /** @var string[] */
35
+    protected $identifierAliases = [];
36 36
 
37
-	/** @var IdentifierTrait */
38
-	protected $deprecateTo = null;
37
+    /** @var IdentifierTrait */
38
+    protected $deprecateTo = null;
39 39
 
40
-	/**
41
-	 * @return string
42
-	 */
43
-	public function getIdentifier() {
44
-		return $this->identifier;
45
-	}
40
+    /**
41
+     * @return string
42
+     */
43
+    public function getIdentifier() {
44
+        return $this->identifier;
45
+    }
46 46
 
47
-	/**
48
-	 * @param string $identifier
49
-	 * @return $this
50
-	 */
51
-	public function setIdentifier($identifier) {
52
-		$this->identifier = $identifier;
53
-		$this->identifierAliases[] = $identifier;
54
-		return $this;
55
-	}
47
+    /**
48
+     * @param string $identifier
49
+     * @return $this
50
+     */
51
+    public function setIdentifier($identifier) {
52
+        $this->identifier = $identifier;
53
+        $this->identifierAliases[] = $identifier;
54
+        return $this;
55
+    }
56 56
 
57
-	/**
58
-	 * @return string[]
59
-	 */
60
-	public function getIdentifierAliases() {
61
-		return $this->identifierAliases;
62
-	}
57
+    /**
58
+     * @return string[]
59
+     */
60
+    public function getIdentifierAliases() {
61
+        return $this->identifierAliases;
62
+    }
63 63
 
64
-	/**
65
-	 * @param string $alias
66
-	 * @return $this
67
-	 */
68
-	public function addIdentifierAlias($alias) {
69
-		$this->identifierAliases[] = $alias;
70
-		return $this;
71
-	}
64
+    /**
65
+     * @param string $alias
66
+     * @return $this
67
+     */
68
+    public function addIdentifierAlias($alias) {
69
+        $this->identifierAliases[] = $alias;
70
+        return $this;
71
+    }
72 72
 
73
-	/**
74
-	 * @return object|null
75
-	 */
76
-	public function getDeprecateTo() {
77
-		return $this->deprecateTo;
78
-	}
73
+    /**
74
+     * @return object|null
75
+     */
76
+    public function getDeprecateTo() {
77
+        return $this->deprecateTo;
78
+    }
79 79
 
80
-	/**
81
-	 * @param object $destinationObject
82
-	 * @return self
83
-	 */
84
-	public function deprecateTo($destinationObject) {
85
-		$this->deprecateTo = $destinationObject;
86
-		return $this;
87
-	}
80
+    /**
81
+     * @param object $destinationObject
82
+     * @return self
83
+     */
84
+    public function deprecateTo($destinationObject) {
85
+        $this->deprecateTo = $destinationObject;
86
+        return $this;
87
+    }
88 88
 
89
-	/**
90
-	 * @return array
91
-	 */
92
-	public function jsonSerializeIdentifier() {
93
-		$data = [
94
-			'identifier' => $this->identifier,
95
-			'identifierAliases' => $this->identifierAliases,
96
-		];
97
-		if ($this->deprecateTo) {
98
-			$data['deprecateTo'] = $this->deprecateTo->getIdentifier();
99
-		}
100
-		return $data;
101
-	}
89
+    /**
90
+     * @return array
91
+     */
92
+    public function jsonSerializeIdentifier() {
93
+        $data = [
94
+            'identifier' => $this->identifier,
95
+            'identifierAliases' => $this->identifierAliases,
96
+        ];
97
+        if ($this->deprecateTo) {
98
+            $data['deprecateTo'] = $this->deprecateTo->getIdentifier();
99
+        }
100
+        return $data;
101
+    }
102 102
 
103 103
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Command/Create.php 2 patches
Indentation   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -42,182 +42,182 @@
 block discarded – undo
42 42
 use Symfony\Component\Console\Output\OutputInterface;
43 43
 
44 44
 class Create extends Base {
45
-	/**
46
-	 * @var GlobalStoragesService
47
-	 */
48
-	private $globalService;
49
-
50
-	/**
51
-	 * @var UserStoragesService
52
-	 */
53
-	private $userService;
54
-
55
-	/**
56
-	 * @var IUserManager
57
-	 */
58
-	private $userManager;
59
-
60
-	/** @var BackendService */
61
-	private $backendService;
62
-
63
-	/** @var IUserSession */
64
-	private $userSession;
65
-
66
-	function __construct(GlobalStoragesService $globalService,
67
-						 UserStoragesService $userService,
68
-						 IUserManager $userManager,
69
-						 IUserSession $userSession,
70
-						 BackendService $backendService
71
-	) {
72
-		parent::__construct();
73
-		$this->globalService = $globalService;
74
-		$this->userService = $userService;
75
-		$this->userManager = $userManager;
76
-		$this->userSession = $userSession;
77
-		$this->backendService = $backendService;
78
-	}
79
-
80
-	protected function configure() {
81
-		$this
82
-			->setName('files_external:create')
83
-			->setDescription('Create a new mount configuration')
84
-			->addOption(
85
-				'user',
86
-				'',
87
-				InputOption::VALUE_OPTIONAL,
88
-				'user to add the mount configuration for, if not set the mount will be added as system mount'
89
-			)
90
-			->addArgument(
91
-				'mount_point',
92
-				InputArgument::REQUIRED,
93
-				'mount point for the new mount'
94
-			)
95
-			->addArgument(
96
-				'storage_backend',
97
-				InputArgument::REQUIRED,
98
-				'storage backend identifier for the new mount, see `occ files_external:backends` for possible values'
99
-			)
100
-			->addArgument(
101
-				'authentication_backend',
102
-				InputArgument::REQUIRED,
103
-				'authentication backend identifier for the new mount, see `occ files_external:backends` for possible values'
104
-			)
105
-			->addOption(
106
-				'config',
107
-				'c',
108
-				InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
109
-				'Mount configuration option in key=value format'
110
-			)
111
-			->addOption(
112
-				'dry',
113
-				'',
114
-				InputOption::VALUE_NONE,
115
-				'Don\'t save the created mount, only list the new mount'
116
-			);
117
-		parent::configure();
118
-	}
119
-
120
-	protected function execute(InputInterface $input, OutputInterface $output) {
121
-		$user = $input->getOption('user');
122
-		$mountPoint = $input->getArgument('mount_point');
123
-		$storageIdentifier = $input->getArgument('storage_backend');
124
-		$authIdentifier = $input->getArgument('authentication_backend');
125
-		$configInput = $input->getOption('config');
126
-
127
-		$storageBackend = $this->backendService->getBackend($storageIdentifier);
128
-		$authBackend = $this->backendService->getAuthMechanism($authIdentifier);
129
-
130
-		if (!Filesystem::isValidPath($mountPoint)) {
131
-			$output->writeln('<error>Invalid mountpoint "' . $mountPoint . '"</error>');
132
-			return 1;
133
-		}
134
-		if (is_null($storageBackend)) {
135
-			$output->writeln('<error>Storage backend with identifier "' . $storageIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
136
-			return 404;
137
-		}
138
-		if (is_null($authBackend)) {
139
-			$output->writeln('<error>Authentication backend with identifier "' . $authIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
140
-			return 404;
141
-		}
142
-		$supportedSchemes = array_keys($storageBackend->getAuthSchemes());
143
-		if (!in_array($authBackend->getScheme(), $supportedSchemes)) {
144
-			$output->writeln('<error>Authentication backend "' . $authIdentifier . '" not valid for storage backend "' . $storageIdentifier . '" (see `occ files_external:backends storage ' . $storageIdentifier . '` for possible values)</error>');
145
-			return 1;
146
-		}
147
-
148
-		$config = [];
149
-		foreach ($configInput as $configOption) {
150
-			if (!strpos($configOption, '=')) {
151
-				$output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>');
152
-				return 1;
153
-			}
154
-			list($key, $value) = explode('=', $configOption, 2);
155
-			if (!$this->validateParam($key, $value, $storageBackend, $authBackend)) {
156
-				$output->writeln('<error>Unknown configuration for backends "' . $key . '"</error>');
157
-				return 1;
158
-			}
159
-			$config[$key] = $value;
160
-		}
161
-
162
-		$mount = new StorageConfig();
163
-		$mount->setMountPoint($mountPoint);
164
-		$mount->setBackend($storageBackend);
165
-		$mount->setAuthMechanism($authBackend);
166
-		$mount->setBackendOptions($config);
167
-
168
-		if ($user) {
169
-			if (!$this->userManager->userExists($user)) {
170
-				$output->writeln('<error>User "' . $user . '" not found</error>');
171
-				return 1;
172
-			}
173
-			$mount->setApplicableUsers([$user]);
174
-		}
175
-
176
-		if ($input->getOption('dry')) {
177
-			$this->showMount($user, $mount, $input, $output);
178
-		} else {
179
-			$this->getStorageService($user)->addStorage($mount);
180
-			if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) {
181
-				$output->writeln('<info>Storage created with id ' . $mount->getId() . '</info>');
182
-			} else {
183
-				$output->writeln((string)$mount->getId());
184
-			}
185
-		}
186
-		return 0;
187
-	}
188
-
189
-	private function validateParam($key, &$value, Backend $storageBackend, AuthMechanism $authBackend) {
190
-		$params = array_merge($storageBackend->getParameters(), $authBackend->getParameters());
191
-		foreach ($params as $param) {
192
-			/** @var DefinitionParameter $param */
193
-			if ($param->getName() === $key) {
194
-				if ($param->getType() === DefinitionParameter::VALUE_BOOLEAN) {
195
-					$value = ($value === 'true');
196
-				}
197
-				return true;
198
-			}
199
-		}
200
-		return false;
201
-	}
202
-
203
-	private function showMount($user, StorageConfig $mount, InputInterface $input, OutputInterface $output) {
204
-		$listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
205
-		$listInput = new ArrayInput([], $listCommand->getDefinition());
206
-		$listInput->setOption('output', $input->getOption('output'));
207
-		$listInput->setOption('show-password', true);
208
-		$listCommand->listMounts($user, [$mount], $listInput, $output);
209
-	}
210
-
211
-	protected function getStorageService($userId) {
212
-		if (!empty($userId)) {
213
-			$user = $this->userManager->get($userId);
214
-			if (is_null($user)) {
215
-				throw new NoUserException("user $userId not found");
216
-			}
217
-			$this->userSession->setUser($user);
218
-			return $this->userService;
219
-		} else {
220
-			return $this->globalService;
221
-		}
222
-	}
45
+    /**
46
+     * @var GlobalStoragesService
47
+     */
48
+    private $globalService;
49
+
50
+    /**
51
+     * @var UserStoragesService
52
+     */
53
+    private $userService;
54
+
55
+    /**
56
+     * @var IUserManager
57
+     */
58
+    private $userManager;
59
+
60
+    /** @var BackendService */
61
+    private $backendService;
62
+
63
+    /** @var IUserSession */
64
+    private $userSession;
65
+
66
+    function __construct(GlobalStoragesService $globalService,
67
+                            UserStoragesService $userService,
68
+                            IUserManager $userManager,
69
+                            IUserSession $userSession,
70
+                            BackendService $backendService
71
+    ) {
72
+        parent::__construct();
73
+        $this->globalService = $globalService;
74
+        $this->userService = $userService;
75
+        $this->userManager = $userManager;
76
+        $this->userSession = $userSession;
77
+        $this->backendService = $backendService;
78
+    }
79
+
80
+    protected function configure() {
81
+        $this
82
+            ->setName('files_external:create')
83
+            ->setDescription('Create a new mount configuration')
84
+            ->addOption(
85
+                'user',
86
+                '',
87
+                InputOption::VALUE_OPTIONAL,
88
+                'user to add the mount configuration for, if not set the mount will be added as system mount'
89
+            )
90
+            ->addArgument(
91
+                'mount_point',
92
+                InputArgument::REQUIRED,
93
+                'mount point for the new mount'
94
+            )
95
+            ->addArgument(
96
+                'storage_backend',
97
+                InputArgument::REQUIRED,
98
+                'storage backend identifier for the new mount, see `occ files_external:backends` for possible values'
99
+            )
100
+            ->addArgument(
101
+                'authentication_backend',
102
+                InputArgument::REQUIRED,
103
+                'authentication backend identifier for the new mount, see `occ files_external:backends` for possible values'
104
+            )
105
+            ->addOption(
106
+                'config',
107
+                'c',
108
+                InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY,
109
+                'Mount configuration option in key=value format'
110
+            )
111
+            ->addOption(
112
+                'dry',
113
+                '',
114
+                InputOption::VALUE_NONE,
115
+                'Don\'t save the created mount, only list the new mount'
116
+            );
117
+        parent::configure();
118
+    }
119
+
120
+    protected function execute(InputInterface $input, OutputInterface $output) {
121
+        $user = $input->getOption('user');
122
+        $mountPoint = $input->getArgument('mount_point');
123
+        $storageIdentifier = $input->getArgument('storage_backend');
124
+        $authIdentifier = $input->getArgument('authentication_backend');
125
+        $configInput = $input->getOption('config');
126
+
127
+        $storageBackend = $this->backendService->getBackend($storageIdentifier);
128
+        $authBackend = $this->backendService->getAuthMechanism($authIdentifier);
129
+
130
+        if (!Filesystem::isValidPath($mountPoint)) {
131
+            $output->writeln('<error>Invalid mountpoint "' . $mountPoint . '"</error>');
132
+            return 1;
133
+        }
134
+        if (is_null($storageBackend)) {
135
+            $output->writeln('<error>Storage backend with identifier "' . $storageIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
136
+            return 404;
137
+        }
138
+        if (is_null($authBackend)) {
139
+            $output->writeln('<error>Authentication backend with identifier "' . $authIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
140
+            return 404;
141
+        }
142
+        $supportedSchemes = array_keys($storageBackend->getAuthSchemes());
143
+        if (!in_array($authBackend->getScheme(), $supportedSchemes)) {
144
+            $output->writeln('<error>Authentication backend "' . $authIdentifier . '" not valid for storage backend "' . $storageIdentifier . '" (see `occ files_external:backends storage ' . $storageIdentifier . '` for possible values)</error>');
145
+            return 1;
146
+        }
147
+
148
+        $config = [];
149
+        foreach ($configInput as $configOption) {
150
+            if (!strpos($configOption, '=')) {
151
+                $output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>');
152
+                return 1;
153
+            }
154
+            list($key, $value) = explode('=', $configOption, 2);
155
+            if (!$this->validateParam($key, $value, $storageBackend, $authBackend)) {
156
+                $output->writeln('<error>Unknown configuration for backends "' . $key . '"</error>');
157
+                return 1;
158
+            }
159
+            $config[$key] = $value;
160
+        }
161
+
162
+        $mount = new StorageConfig();
163
+        $mount->setMountPoint($mountPoint);
164
+        $mount->setBackend($storageBackend);
165
+        $mount->setAuthMechanism($authBackend);
166
+        $mount->setBackendOptions($config);
167
+
168
+        if ($user) {
169
+            if (!$this->userManager->userExists($user)) {
170
+                $output->writeln('<error>User "' . $user . '" not found</error>');
171
+                return 1;
172
+            }
173
+            $mount->setApplicableUsers([$user]);
174
+        }
175
+
176
+        if ($input->getOption('dry')) {
177
+            $this->showMount($user, $mount, $input, $output);
178
+        } else {
179
+            $this->getStorageService($user)->addStorage($mount);
180
+            if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) {
181
+                $output->writeln('<info>Storage created with id ' . $mount->getId() . '</info>');
182
+            } else {
183
+                $output->writeln((string)$mount->getId());
184
+            }
185
+        }
186
+        return 0;
187
+    }
188
+
189
+    private function validateParam($key, &$value, Backend $storageBackend, AuthMechanism $authBackend) {
190
+        $params = array_merge($storageBackend->getParameters(), $authBackend->getParameters());
191
+        foreach ($params as $param) {
192
+            /** @var DefinitionParameter $param */
193
+            if ($param->getName() === $key) {
194
+                if ($param->getType() === DefinitionParameter::VALUE_BOOLEAN) {
195
+                    $value = ($value === 'true');
196
+                }
197
+                return true;
198
+            }
199
+        }
200
+        return false;
201
+    }
202
+
203
+    private function showMount($user, StorageConfig $mount, InputInterface $input, OutputInterface $output) {
204
+        $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
205
+        $listInput = new ArrayInput([], $listCommand->getDefinition());
206
+        $listInput->setOption('output', $input->getOption('output'));
207
+        $listInput->setOption('show-password', true);
208
+        $listCommand->listMounts($user, [$mount], $listInput, $output);
209
+    }
210
+
211
+    protected function getStorageService($userId) {
212
+        if (!empty($userId)) {
213
+            $user = $this->userManager->get($userId);
214
+            if (is_null($user)) {
215
+                throw new NoUserException("user $userId not found");
216
+            }
217
+            $this->userSession->setUser($user);
218
+            return $this->userService;
219
+        } else {
220
+            return $this->globalService;
221
+        }
222
+    }
223 223
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -128,32 +128,32 @@  discard block
 block discarded – undo
128 128
 		$authBackend = $this->backendService->getAuthMechanism($authIdentifier);
129 129
 
130 130
 		if (!Filesystem::isValidPath($mountPoint)) {
131
-			$output->writeln('<error>Invalid mountpoint "' . $mountPoint . '"</error>');
131
+			$output->writeln('<error>Invalid mountpoint "'.$mountPoint.'"</error>');
132 132
 			return 1;
133 133
 		}
134 134
 		if (is_null($storageBackend)) {
135
-			$output->writeln('<error>Storage backend with identifier "' . $storageIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
135
+			$output->writeln('<error>Storage backend with identifier "'.$storageIdentifier.'" not found (see `occ files_external:backends` for possible values)</error>');
136 136
 			return 404;
137 137
 		}
138 138
 		if (is_null($authBackend)) {
139
-			$output->writeln('<error>Authentication backend with identifier "' . $authIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>');
139
+			$output->writeln('<error>Authentication backend with identifier "'.$authIdentifier.'" not found (see `occ files_external:backends` for possible values)</error>');
140 140
 			return 404;
141 141
 		}
142 142
 		$supportedSchemes = array_keys($storageBackend->getAuthSchemes());
143 143
 		if (!in_array($authBackend->getScheme(), $supportedSchemes)) {
144
-			$output->writeln('<error>Authentication backend "' . $authIdentifier . '" not valid for storage backend "' . $storageIdentifier . '" (see `occ files_external:backends storage ' . $storageIdentifier . '` for possible values)</error>');
144
+			$output->writeln('<error>Authentication backend "'.$authIdentifier.'" not valid for storage backend "'.$storageIdentifier.'" (see `occ files_external:backends storage '.$storageIdentifier.'` for possible values)</error>');
145 145
 			return 1;
146 146
 		}
147 147
 
148 148
 		$config = [];
149 149
 		foreach ($configInput as $configOption) {
150 150
 			if (!strpos($configOption, '=')) {
151
-				$output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>');
151
+				$output->writeln('<error>Invalid mount configuration option "'.$configOption.'"</error>');
152 152
 				return 1;
153 153
 			}
154 154
 			list($key, $value) = explode('=', $configOption, 2);
155 155
 			if (!$this->validateParam($key, $value, $storageBackend, $authBackend)) {
156
-				$output->writeln('<error>Unknown configuration for backends "' . $key . '"</error>');
156
+				$output->writeln('<error>Unknown configuration for backends "'.$key.'"</error>');
157 157
 				return 1;
158 158
 			}
159 159
 			$config[$key] = $value;
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 
168 168
 		if ($user) {
169 169
 			if (!$this->userManager->userExists($user)) {
170
-				$output->writeln('<error>User "' . $user . '" not found</error>');
170
+				$output->writeln('<error>User "'.$user.'" not found</error>');
171 171
 				return 1;
172 172
 			}
173 173
 			$mount->setApplicableUsers([$user]);
@@ -178,9 +178,9 @@  discard block
 block discarded – undo
178 178
 		} else {
179 179
 			$this->getStorageService($user)->addStorage($mount);
180 180
 			if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) {
181
-				$output->writeln('<info>Storage created with id ' . $mount->getId() . '</info>');
181
+				$output->writeln('<info>Storage created with id '.$mount->getId().'</info>');
182 182
 			} else {
183
-				$output->writeln((string)$mount->getId());
183
+				$output->writeln((string) $mount->getId());
184 184
 			}
185 185
 		}
186 186
 		return 0;
Please login to merge, or discard this patch.
apps/testing/appinfo/routes.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -21,62 +21,62 @@
 block discarded – undo
21 21
  */
22 22
 
23 23
 return [
24
-	'routes' => [
25
-		[
26
-			'name' => 'RateLimitTest#userAndAnonProtected',
27
-			'url' => '/userAndAnonProtected',
28
-			'verb' => 'GET',
29
-		],
30
-		[
31
-			'name' => 'RateLimitTest#onlyAnonProtected',
32
-			'url' => '/anonProtected',
33
-			'verb' => 'GET',
34
-		],
35
-	],
24
+    'routes' => [
25
+        [
26
+            'name' => 'RateLimitTest#userAndAnonProtected',
27
+            'url' => '/userAndAnonProtected',
28
+            'verb' => 'GET',
29
+        ],
30
+        [
31
+            'name' => 'RateLimitTest#onlyAnonProtected',
32
+            'url' => '/anonProtected',
33
+            'verb' => 'GET',
34
+        ],
35
+    ],
36 36
 
37
-	'ocs' => [
38
-		[
39
-			'name' => 'Config#setAppValue',
40
-			'url'  => '/api/v1/app/{appid}/{configkey}',
41
-			'verb' => 'POST',
42
-		],
43
-		[
44
-			'name' => 'Config#deleteAppValue',
45
-			'url'  => '/api/v1/app/{appid}/{configkey}',
46
-			'verb' => 'DELETE',
47
-		],
48
-		[
49
-			'name' => 'Locking#isLockingEnabled',
50
-			'url'  => '/api/v1/lockprovisioning',
51
-			'verb' => 'GET',
52
-		],
53
-		[
54
-			'name' => 'Locking#isLocked',
55
-			'url'  => '/api/v1/lockprovisioning/{type}/{user}',
56
-			'verb' => 'GET',
57
-		],
58
-		[
59
-			'name' => 'Locking#acquireLock',
60
-			'url'  => '/api/v1/lockprovisioning/{type}/{user}',
61
-			'verb' => 'POST',
62
-		],
63
-		[
64
-			'name' => 'Locking#changeLock',
65
-			'url'  => '/api/v1/lockprovisioning/{type}/{user}',
66
-			'verb' => 'PUT',
67
-		],
68
-		[
69
-			'name' => 'Locking#releaseLock',
70
-			'url'  => '/api/v1/lockprovisioning/{type}/{user}',
71
-			'verb' => 'DELETE',
72
-		],
73
-		[
74
-			'name' => 'Locking#releaseAll',
75
-			'url'  => '/api/v1/lockprovisioning/{type}',
76
-			'verb' => 'DELETE',
77
-			'defaults' => [
78
-				'type' => null
79
-			]
80
-		],
81
-	],
37
+    'ocs' => [
38
+        [
39
+            'name' => 'Config#setAppValue',
40
+            'url'  => '/api/v1/app/{appid}/{configkey}',
41
+            'verb' => 'POST',
42
+        ],
43
+        [
44
+            'name' => 'Config#deleteAppValue',
45
+            'url'  => '/api/v1/app/{appid}/{configkey}',
46
+            'verb' => 'DELETE',
47
+        ],
48
+        [
49
+            'name' => 'Locking#isLockingEnabled',
50
+            'url'  => '/api/v1/lockprovisioning',
51
+            'verb' => 'GET',
52
+        ],
53
+        [
54
+            'name' => 'Locking#isLocked',
55
+            'url'  => '/api/v1/lockprovisioning/{type}/{user}',
56
+            'verb' => 'GET',
57
+        ],
58
+        [
59
+            'name' => 'Locking#acquireLock',
60
+            'url'  => '/api/v1/lockprovisioning/{type}/{user}',
61
+            'verb' => 'POST',
62
+        ],
63
+        [
64
+            'name' => 'Locking#changeLock',
65
+            'url'  => '/api/v1/lockprovisioning/{type}/{user}',
66
+            'verb' => 'PUT',
67
+        ],
68
+        [
69
+            'name' => 'Locking#releaseLock',
70
+            'url'  => '/api/v1/lockprovisioning/{type}/{user}',
71
+            'verb' => 'DELETE',
72
+        ],
73
+        [
74
+            'name' => 'Locking#releaseAll',
75
+            'url'  => '/api/v1/lockprovisioning/{type}',
76
+            'verb' => 'DELETE',
77
+            'defaults' => [
78
+                'type' => null
79
+            ]
80
+        ],
81
+    ],
82 82
 ];
Please login to merge, or discard this patch.
lib/public/AppFramework/OCS/OCSNotFoundException.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -32,14 +32,14 @@
 block discarded – undo
32 32
  * @since 9.1.0
33 33
  */
34 34
 class OCSNotFoundException extends OCSException {
35
-	/**
36
-	 * OCSNotFoundException constructor.
37
-	 *
38
-	 * @param string $message
39
-	 * @param Exception|null $previous
40
-	 * @since 9.1.0
41
-	 */
42
-	public function __construct($message = '', Exception $previous = null) {
43
-		parent::__construct($message, Http::STATUS_NOT_FOUND, $previous);
44
-	}
35
+    /**
36
+     * OCSNotFoundException constructor.
37
+     *
38
+     * @param string $message
39
+     * @param Exception|null $previous
40
+     * @since 9.1.0
41
+     */
42
+    public function __construct($message = '', Exception $previous = null) {
43
+        parent::__construct($message, Http::STATUS_NOT_FOUND, $previous);
44
+    }
45 45
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/OCS/OCSForbiddenException.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -32,14 +32,14 @@
 block discarded – undo
32 32
  * @since 9.1.0
33 33
  */
34 34
 class OCSForbiddenException extends OCSException {
35
-	/**
36
-	 * OCSForbiddenException constructor.
37
-	 *
38
-	 * @param string $message
39
-	 * @param Exception|null $previous
40
-	 * @since 9.1.0
41
-	 */
42
-	public function __construct($message = '', Exception $previous = null) {
43
-		parent::__construct($message, Http::STATUS_FORBIDDEN, $previous);
44
-	}
35
+    /**
36
+     * OCSForbiddenException constructor.
37
+     *
38
+     * @param string $message
39
+     * @param Exception|null $previous
40
+     * @since 9.1.0
41
+     */
42
+    public function __construct($message = '', Exception $previous = null) {
43
+        parent::__construct($message, Http::STATUS_FORBIDDEN, $previous);
44
+    }
45 45
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/OCS/OCSBadRequestException.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -32,14 +32,14 @@
 block discarded – undo
32 32
  * @since 9.1.0
33 33
  */
34 34
 class OCSBadRequestException extends OCSException {
35
-	/**
36
-	 * OCSBadRequestException constructor.
37
-	 *
38
-	 * @param string $message
39
-	 * @param Exception|null $previous
40
-	 * @since 9.1.0
41
-	 */
42
-	public function __construct($message = '', Exception $previous = null) {
43
-		parent::__construct($message, Http::STATUS_BAD_REQUEST, $previous);
44
-	}
35
+    /**
36
+     * OCSBadRequestException constructor.
37
+     *
38
+     * @param string $message
39
+     * @param Exception|null $previous
40
+     * @since 9.1.0
41
+     */
42
+    public function __construct($message = '', Exception $previous = null) {
43
+        parent::__construct($message, Http::STATUS_BAD_REQUEST, $previous);
44
+    }
45 45
 }
Please login to merge, or discard this patch.