summaryrefslogtreecommitdiffstats
path: root/apps/files_external/lib/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_external/lib/Lib')
-rw-r--r--apps/files_external/lib/Lib/Api.php87
-rw-r--r--apps/files_external/lib/Lib/Auth/Builtin.php2
-rw-r--r--apps/files_external/lib/Lib/Auth/NullMechanism.php1
-rw-r--r--apps/files_external/lib/Lib/DefinitionParameter.php193
-rw-r--r--apps/files_external/lib/Lib/DependencyTrait.php41
-rw-r--r--apps/files_external/lib/Lib/FrontendDefinitionTrait.php158
-rw-r--r--apps/files_external/lib/Lib/IdentifierTrait.php102
-rw-r--r--apps/files_external/lib/Lib/InsufficientDataForMeaningfulAnswerException.php42
-rw-r--r--apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php70
-rw-r--r--apps/files_external/lib/Lib/MissingDependency.php64
-rw-r--r--apps/files_external/lib/Lib/PersonalMount.php88
-rw-r--r--apps/files_external/lib/Lib/PriorityTrait.php60
-rw-r--r--apps/files_external/lib/Lib/SessionStorageWrapper.php43
-rw-r--r--apps/files_external/lib/Lib/StorageConfig.php430
-rw-r--r--apps/files_external/lib/Lib/StorageModifierTrait.php69
-rw-r--r--apps/files_external/lib/Lib/VisibilityTrait.php136
16 files changed, 1583 insertions, 3 deletions
diff --git a/apps/files_external/lib/Lib/Api.php b/apps/files_external/lib/Lib/Api.php
new file mode 100644
index 00000000000..589317dcf98
--- /dev/null
+++ b/apps/files_external/lib/Lib/Api.php
@@ -0,0 +1,87 @@
+<?php
+/**
+ * @author Jesús Macias <jmacias@solidgear.es>
+ * @author Joas Schilling <nickvergessen@owncloud.com>
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ * @author Vincent Petry <pvince81@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Lib;
+
+class Api {
+
+ /**
+ * Formats the given mount config to a mount entry.
+ *
+ * @param string $mountPoint mount point name, relative to the data dir
+ * @param array $mountConfig mount config to format
+ *
+ * @return array entry
+ */
+ private static function formatMount($mountPoint, $mountConfig) {
+ // strip "/$user/files" from mount point
+ $mountPoint = explode('/', trim($mountPoint, '/'), 3);
+ $mountPoint = $mountPoint[2];
+
+ // split path from mount point
+ $path = dirname($mountPoint);
+ if ($path === '.') {
+ $path = '';
+ }
+
+ $isSystemMount = !$mountConfig['personal'];
+
+ $permissions = \OCP\Constants::PERMISSION_READ;
+ // personal mounts can be deleted
+ if (!$isSystemMount) {
+ $permissions |= \OCP\Constants::PERMISSION_DELETE;
+ }
+
+ $entry = array(
+ 'name' => basename($mountPoint),
+ 'path' => $path,
+ 'type' => 'dir',
+ 'backend' => $mountConfig['backend'],
+ 'scope' => ( $isSystemMount ? 'system' : 'personal' ),
+ 'permissions' => $permissions,
+ 'id' => $mountConfig['id'],
+ 'class' => $mountConfig['class']
+ );
+ return $entry;
+ }
+
+ /**
+ * Returns the mount points visible for this user.
+ *
+ * @param array $params
+ * @return \OC_OCS_Result share information
+ */
+ public static function getUserMounts($params) {
+ $entries = array();
+ $user = \OC::$server->getUserSession()->getUser()->getUID();
+
+ $mounts = \OC_Mount_Config::getAbsoluteMountPoints($user);
+ foreach($mounts as $mountPoint => $mount) {
+ $entries[] = self::formatMount($mountPoint, $mount);
+ }
+
+ return new \OC_OCS_Result($entries);
+ }
+}
diff --git a/apps/files_external/lib/Lib/Auth/Builtin.php b/apps/files_external/lib/Lib/Auth/Builtin.php
index 8b43cb459cc..c5c3a19e54f 100644
--- a/apps/files_external/lib/Lib/Auth/Builtin.php
+++ b/apps/files_external/lib/Lib/Auth/Builtin.php
@@ -22,8 +22,6 @@
namespace OCA\Files_External\Lib\Auth;
use \OCP\IL10N;
-use \OCA\Files_External\Lib\Auth\AuthMechanism;
-use \OCA\Files_external\Lib\StorageConfig;
/**
* Builtin authentication mechanism, for legacy backends
diff --git a/apps/files_external/lib/Lib/Auth/NullMechanism.php b/apps/files_external/lib/Lib/Auth/NullMechanism.php
index c0a8f4f119b..671a5ff66c5 100644
--- a/apps/files_external/lib/Lib/Auth/NullMechanism.php
+++ b/apps/files_external/lib/Lib/Auth/NullMechanism.php
@@ -22,7 +22,6 @@
namespace OCA\Files_External\Lib\Auth;
use \OCP\IL10N;
-use \OCA\Files_external\Lib\StorageConfig;
/**
* Null authentication mechanism
diff --git a/apps/files_external/lib/Lib/DefinitionParameter.php b/apps/files_external/lib/Lib/DefinitionParameter.php
new file mode 100644
index 00000000000..16c07f4b8cc
--- /dev/null
+++ b/apps/files_external/lib/Lib/DefinitionParameter.php
@@ -0,0 +1,193 @@
+<?php
+/**
+ * @author Robin Appelman <icewind@owncloud.com>
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Lib;
+
+/**
+ * Parameter for an external storage definition
+ */
+class DefinitionParameter implements \JsonSerializable {
+
+ /** Value constants */
+ const VALUE_TEXT = 0;
+ const VALUE_BOOLEAN = 1;
+ const VALUE_PASSWORD = 2;
+ const VALUE_HIDDEN = 3;
+
+ /** Flag constants */
+ const FLAG_NONE = 0;
+ const FLAG_OPTIONAL = 1;
+ const FLAG_USER_PROVIDED = 2;
+
+ /** @var string name of parameter */
+ private $name;
+
+ /** @var string human-readable parameter text */
+ private $text;
+
+ /** @var int value type, see self::VALUE_* constants */
+ private $type = self::VALUE_TEXT;
+
+ /** @var int flags, see self::FLAG_* constants */
+ private $flags = self::FLAG_NONE;
+
+ /**
+ * @param string $name
+ * @param string $text
+ */
+ public function __construct($name, $text) {
+ $this->name = $name;
+ $this->text = $text;
+ }
+
+ /**
+ * @return string
+ */
+ public function getName() {
+ return $this->name;
+ }
+
+ /**
+ * @return string
+ */
+ public function getText() {
+ return $this->text;
+ }
+
+ /**
+ * Get value type
+ *
+ * @return int
+ */
+ public function getType() {
+ return $this->type;
+ }
+
+ /**
+ * Set value type
+ *
+ * @param int $type
+ * @return self
+ */
+ public function setType($type) {
+ $this->type = $type;
+ return $this;
+ }
+
+ /**
+ * @return string
+ */
+ public function getTypeName() {
+ switch ($this->type) {
+ case self::VALUE_BOOLEAN:
+ return 'boolean';
+ case self::VALUE_TEXT:
+ return 'text';
+ case self::VALUE_PASSWORD:
+ return 'password';
+ default:
+ return 'unknown';
+ }
+ }
+
+ /**
+ * @return int
+ */
+ public function getFlags() {
+ return $this->flags;
+ }
+
+ /**
+ * @param int $flags
+ * @return self
+ */
+ public function setFlags($flags) {
+ $this->flags = $flags;
+ return $this;
+ }
+
+ /**
+ * @param int $flag
+ * @return self
+ */
+ public function setFlag($flag) {
+ $this->flags |= $flag;
+ return $this;
+ }
+
+ /**
+ * @param int $flag
+ * @return bool
+ */
+ public function isFlagSet($flag) {
+ return (bool)($this->flags & $flag);
+ }
+
+ /**
+ * Serialize into JSON for client-side JS
+ *
+ * @return string
+ */
+ public function jsonSerialize() {
+ return [
+ 'value' => $this->getText(),
+ 'flags' => $this->getFlags(),
+ 'type' => $this->getType()
+ ];
+ }
+
+ public function isOptional() {
+ return $this->isFlagSet(self::FLAG_OPTIONAL) || $this->isFlagSet(self::FLAG_USER_PROVIDED);
+ }
+
+ /**
+ * Validate a parameter value against this
+ * Convert type as necessary
+ *
+ * @param mixed $value Value to check
+ * @return bool success
+ */
+ public function validateValue(&$value) {
+ switch ($this->getType()) {
+ case self::VALUE_BOOLEAN:
+ if (!is_bool($value)) {
+ switch ($value) {
+ case 'true':
+ $value = true;
+ break;
+ case 'false':
+ $value = false;
+ break;
+ default:
+ return false;
+ }
+ }
+ break;
+ default:
+ if (!$value && !$this->isOptional()) {
+ return false;
+ }
+ break;
+ }
+ return true;
+ }
+}
diff --git a/apps/files_external/lib/Lib/DependencyTrait.php b/apps/files_external/lib/Lib/DependencyTrait.php
new file mode 100644
index 00000000000..eed3ba1b327
--- /dev/null
+++ b/apps/files_external/lib/Lib/DependencyTrait.php
@@ -0,0 +1,41 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Lib;
+
+use \OCA\Files_External\Lib\MissingDependency;
+
+/**
+ * Trait for objects that have dependencies for use
+ */
+trait DependencyTrait {
+
+ /**
+ * Check if object is valid for use
+ *
+ * @return MissingDependency[] Unsatisfied dependencies
+ */
+ public function checkDependencies() {
+ return []; // no dependencies by default
+ }
+
+}
+
diff --git a/apps/files_external/lib/Lib/FrontendDefinitionTrait.php b/apps/files_external/lib/Lib/FrontendDefinitionTrait.php
new file mode 100644
index 00000000000..ccc2a75fd1b
--- /dev/null
+++ b/apps/files_external/lib/Lib/FrontendDefinitionTrait.php
@@ -0,0 +1,158 @@
+<?php
+/**
+ * @author Robin Appelman <icewind@owncloud.com>
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Lib;
+
+use \OCA\Files_External\Lib\DefinitionParameter;
+use \OCA\Files_External\Lib\StorageConfig;
+
+/**
+ * Trait for objects that have a frontend representation
+ */
+trait FrontendDefinitionTrait {
+
+ /** @var string human-readable mechanism name */
+ private $text;
+
+ /** @var DefinitionParameter[] parameters for mechanism */
+ private $parameters = [];
+
+ /** @var string[] custom JS */
+ private $customJs = [];
+
+ /**
+ * @return string
+ */
+ public function getText() {
+ return $this->text;
+ }
+
+ /**
+ * @param string $text
+ * @return self
+ */
+ public function setText($text) {
+ $this->text = $text;
+ return $this;
+ }
+
+ /**
+ * @param FrontendDefinitionTrait $a
+ * @param FrontendDefinitionTrait $b
+ * @return int
+ */
+ public static function lexicalCompare(FrontendDefinitionTrait $a, FrontendDefinitionTrait $b) {
+ return strcmp($a->getText(), $b->getText());
+ }
+
+ /**
+ * @return DefinitionParameter[]
+ */
+ public function getParameters() {
+ return $this->parameters;
+ }
+
+ /**
+ * @param DefinitionParameter[] $parameters
+ * @return self
+ */
+ public function addParameters(array $parameters) {
+ foreach ($parameters as $parameter) {
+ $this->addParameter($parameter);
+ }
+ return $this;
+ }
+
+ /**
+ * @param DefinitionParameter $parameter
+ * @return self
+ */
+ public function addParameter(DefinitionParameter $parameter) {
+ $this->parameters[$parameter->getName()] = $parameter;
+ return $this;
+ }
+
+ /**
+ * @return string[]
+ */
+ public function getCustomJs() {
+ return $this->customJs;
+ }
+
+ /**
+ * @param string $custom
+ * @return self
+ */
+ public function addCustomJs($custom) {
+ $this->customJs[] = $custom;
+ return $this;
+ }
+
+ /**
+ * @param string $custom
+ * @return self
+ * @deprecated 9.1.0, use addCustomJs() instead
+ */
+ public function setCustomJs($custom) {
+ $this->customJs = [$custom];
+ return $this;
+ }
+
+ /**
+ * Serialize into JSON for client-side JS
+ *
+ * @return array
+ */
+ public function jsonSerializeDefinition() {
+ $configuration = [];
+ foreach ($this->getParameters() as $parameter) {
+ $configuration[$parameter->getName()] = $parameter;
+ }
+
+ $data = [
+ 'name' => $this->getText(),
+ 'configuration' => $configuration,
+ 'custom' => $this->getCustomJs(),
+ ];
+ return $data;
+ }
+
+ /**
+ * Check if parameters are satisfied in a StorageConfig
+ *
+ * @param StorageConfig $storage
+ * @return bool
+ */
+ public function validateStorageDefinition(StorageConfig $storage) {
+ foreach ($this->getParameters() as $name => $parameter) {
+ $value = $storage->getBackendOption($name);
+ if (!is_null($value) || !$parameter->isOptional()) {
+ if (!$parameter->validateValue($value)) {
+ return false;
+ }
+ $storage->setBackendOption($name, $value);
+ }
+ }
+ return true;
+ }
+
+}
diff --git a/apps/files_external/lib/Lib/IdentifierTrait.php b/apps/files_external/lib/Lib/IdentifierTrait.php
new file mode 100644
index 00000000000..c49f4fcbc8d
--- /dev/null
+++ b/apps/files_external/lib/Lib/IdentifierTrait.php
@@ -0,0 +1,102 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Lib;
+
+/**
+ * Trait for objects requiring an identifier (and/or identifier aliases)
+ * Also supports deprecation to a different object, linking the objects
+ */
+trait IdentifierTrait {
+
+ /** @var string */
+ protected $identifier;
+
+ /** @var string[] */
+ protected $identifierAliases = [];
+
+ /** @var IdentifierTrait */
+ protected $deprecateTo = null;
+
+ /**
+ * @return string
+ */
+ public function getIdentifier() {
+ return $this->identifier;
+ }
+
+ /**
+ * @param string $identifier
+ * @return self
+ */
+ public function setIdentifier($identifier) {
+ $this->identifier = $identifier;
+ $this->identifierAliases[] = $identifier;
+ return $this;
+ }
+
+ /**
+ * @return string[]
+ */
+ public function getIdentifierAliases() {
+ return $this->identifierAliases;
+ }
+
+ /**
+ * @param string $alias
+ * @return self
+ */
+ public function addIdentifierAlias($alias) {
+ $this->identifierAliases[] = $alias;
+ return $this;
+ }
+
+ /**
+ * @return object|null
+ */
+ public function getDeprecateTo() {
+ return $this->deprecateTo;
+ }
+
+ /**
+ * @param object $destinationObject
+ * @return self
+ */
+ public function deprecateTo($destinationObject) {
+ $this->deprecateTo = $destinationObject;
+ return $this;
+ }
+
+ /**
+ * @return array
+ */
+ public function jsonSerializeIdentifier() {
+ $data = [
+ 'identifier' => $this->identifier,
+ 'identifierAliases' => $this->identifierAliases,
+ ];
+ if ($this->deprecateTo) {
+ $data['deprecateTo'] = $this->deprecateTo->getIdentifier();
+ }
+ return $data;
+ }
+
+}
diff --git a/apps/files_external/lib/Lib/InsufficientDataForMeaningfulAnswerException.php b/apps/files_external/lib/Lib/InsufficientDataForMeaningfulAnswerException.php
new file mode 100644
index 00000000000..1906057eb67
--- /dev/null
+++ b/apps/files_external/lib/Lib/InsufficientDataForMeaningfulAnswerException.php
@@ -0,0 +1,42 @@
+<?php
+/**
+ * @author Robin Appelman <icewind@owncloud.com>
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Lib;
+
+use \OCP\Files\StorageNotAvailableException;
+
+/**
+ * Authentication mechanism or backend has insufficient data
+ */
+class InsufficientDataForMeaningfulAnswerException extends StorageNotAvailableException {
+ /**
+ * StorageNotAvailableException constructor.
+ *
+ * @param string $message
+ * @param int $code
+ * @param \Exception $previous
+ * @since 6.0.0
+ */
+ public function __construct($message = '', $code = self::STATUS_INDETERMINATE, \Exception $previous = null) {
+ parent::__construct($message, $code, $previous);
+ }
+}
diff --git a/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php b/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php
new file mode 100644
index 00000000000..7d6c0c4b45b
--- /dev/null
+++ b/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php
@@ -0,0 +1,70 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Lib;
+
+use \OCA\Files_External\Lib\MissingDependency;
+
+/**
+ * Polyfill for checking dependencies using legacy Storage::checkDependencies()
+ */
+trait LegacyDependencyCheckPolyfill {
+
+ /**
+ * @return string
+ */
+ abstract public function getStorageClass();
+
+ /**
+ * Check if object is valid for use
+ *
+ * @return MissingDependency[] Unsatisfied dependencies
+ */
+ public function checkDependencies() {
+ $ret = [];
+
+ $result = call_user_func([$this->getStorageClass(), 'checkDependencies']);
+ if ($result !== true) {
+ if (!is_array($result)) {
+ $result = [$result];
+ }
+ foreach ($result as $key => $value) {
+ if (!($value instanceof MissingDependency)) {
+ $module = null;
+ $message = null;
+ if (is_numeric($key)) {
+ $module = $value;
+ } else {
+ $module = $key;
+ $message = $value;
+ }
+ $value = new MissingDependency($module, $this);
+ $value->setMessage($message);
+ }
+ $ret[] = $value;
+ }
+ }
+
+ return $ret;
+ }
+
+}
+
diff --git a/apps/files_external/lib/Lib/MissingDependency.php b/apps/files_external/lib/Lib/MissingDependency.php
new file mode 100644
index 00000000000..a4a20dd1128
--- /dev/null
+++ b/apps/files_external/lib/Lib/MissingDependency.php
@@ -0,0 +1,64 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Lib;
+
+/**
+ * External storage backend dependency
+ */
+class MissingDependency {
+
+ /** @var string */
+ private $dependency;
+
+ /** @var string|null Custom message */
+ private $message = null;
+
+ /**
+ * @param string $dependency
+ */
+ public function __construct($dependency) {
+ $this->dependency = $dependency;
+ }
+
+ /**
+ * @return string
+ */
+ public function getDependency() {
+ return $this->dependency;
+ }
+
+ /**
+ * @return string|null
+ */
+ public function getMessage() {
+ return $this->message;
+ }
+
+ /**
+ * @param string $message
+ * @return self
+ */
+ public function setMessage($message) {
+ $this->message = $message;
+ return $this;
+ }
+}
diff --git a/apps/files_external/lib/Lib/PersonalMount.php b/apps/files_external/lib/Lib/PersonalMount.php
new file mode 100644
index 00000000000..c3b71fbef32
--- /dev/null
+++ b/apps/files_external/lib/Lib/PersonalMount.php
@@ -0,0 +1,88 @@
+<?php
+/**
+ * @author Morris Jobke <hey@morrisjobke.de>
+ * @author Robin Appelman <icewind@owncloud.com>
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Lib;
+
+use OC\Files\Mount\MountPoint;
+use OC\Files\Mount\MoveableMount;
+use OCA\Files_External\Service\UserStoragesService;
+
+/**
+ * Person mount points can be moved by the user
+ */
+class PersonalMount extends MountPoint implements MoveableMount {
+ /** @var UserStoragesService */
+ protected $storagesService;
+
+ /** @var int */
+ protected $numericStorageId;
+
+ /**
+ * @param UserStoragesService $storagesService
+ * @param int $storageId
+ * @param \OCP\Files\Storage $storage
+ * @param string $mountpoint
+ * @param array $arguments (optional) configuration for the storage backend
+ * @param \OCP\Files\Storage\IStorageFactory $loader
+ * @param array $mountOptions mount specific options
+ */
+ public function __construct(
+ UserStoragesService $storagesService,
+ $storageId,
+ $storage,
+ $mountpoint,
+ $arguments = null,
+ $loader = null,
+ $mountOptions = null
+ ) {
+ parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions);
+ $this->storagesService = $storagesService;
+ $this->numericStorageId = $storageId;
+ }
+
+ /**
+ * Move the mount point to $target
+ *
+ * @param string $target the target mount point
+ * @return bool
+ */
+ public function moveMount($target) {
+ $storage = $this->storagesService->getStorage($this->numericStorageId);
+ // remove "/$user/files" prefix
+ $targetParts = explode('/', trim($target, '/'), 3);
+ $storage->setMountPoint($targetParts[2]);
+ $this->storagesService->updateStorage($storage);
+ $this->setMountPoint($target);
+ return true;
+ }
+
+ /**
+ * Remove the mount points
+ *
+ * @return bool
+ */
+ public function removeMount() {
+ $this->storagesService->removeStorage($this->numericStorageId);
+ return true;
+ }
+}
diff --git a/apps/files_external/lib/Lib/PriorityTrait.php b/apps/files_external/lib/Lib/PriorityTrait.php
new file mode 100644
index 00000000000..9745015bef4
--- /dev/null
+++ b/apps/files_external/lib/Lib/PriorityTrait.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Lib;
+
+use \OCA\Files_External\Service\BackendService;
+
+/**
+ * Trait to implement priority mechanics for a configuration class
+ */
+trait PriorityTrait {
+
+ /** @var int initial priority */
+ protected $priority = BackendService::PRIORITY_DEFAULT;
+
+ /**
+ * @return int
+ */
+ public function getPriority() {
+ return $this->priority;
+ }
+
+ /**
+ * @param int $priority
+ * @return self
+ */
+ public function setPriority($priority) {
+ $this->priority = $priority;
+ return $this;
+ }
+
+ /**
+ * @param PriorityTrait $a
+ * @param PriorityTrait $b
+ * @return int
+ */
+ public static function priorityCompare(PriorityTrait $a, PriorityTrait $b) {
+ return ($a->getPriority() - $b->getPriority());
+ }
+
+}
+
diff --git a/apps/files_external/lib/Lib/SessionStorageWrapper.php b/apps/files_external/lib/Lib/SessionStorageWrapper.php
new file mode 100644
index 00000000000..c592cb87a34
--- /dev/null
+++ b/apps/files_external/lib/Lib/SessionStorageWrapper.php
@@ -0,0 +1,43 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Lib;
+
+use \OCP\Files\Storage;
+use \OC\Files\Storage\Wrapper\PermissionsMask;
+use \OCP\Constants;
+
+/**
+ * Wrap Storage in PermissionsMask for session ephemeral use
+ */
+class SessionStorageWrapper extends PermissionsMask {
+
+ /**
+ * @param array $arguments ['storage' => $storage]
+ */
+ public function __construct($arguments) {
+ // disable sharing permission
+ $arguments['mask'] = Constants::PERMISSION_ALL & ~Constants::PERMISSION_SHARE;
+ parent::__construct($arguments);
+ }
+
+}
+
diff --git a/apps/files_external/lib/Lib/StorageConfig.php b/apps/files_external/lib/Lib/StorageConfig.php
new file mode 100644
index 00000000000..2a22b324ead
--- /dev/null
+++ b/apps/files_external/lib/Lib/StorageConfig.php
@@ -0,0 +1,430 @@
+<?php
+/**
+ * @author Jesús Macias <jmacias@solidgear.es>
+ * @author Lukas Reschke <lukas@owncloud.com>
+ * @author Robin Appelman <icewind@owncloud.com>
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ * @author Vincent Petry <pvince81@owncloud.com>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Lib;
+
+use OCA\Files_External\Lib\Auth\IUserProvided;
+use \OCA\Files_External\Lib\Backend\Backend;
+use \OCA\Files_External\Lib\Auth\AuthMechanism;
+
+/**
+ * External storage configuration
+ */
+class StorageConfig implements \JsonSerializable {
+ const MOUNT_TYPE_ADMIN = 1;
+ const MOUNT_TYPE_PERSONAl = 2;
+
+ /**
+ * Storage config id
+ *
+ * @var int
+ */
+ private $id;
+
+ /**
+ * Backend
+ *
+ * @var Backend
+ */
+ private $backend;
+
+ /**
+ * Authentication mechanism
+ *
+ * @var AuthMechanism
+ */
+ private $authMechanism;
+
+ /**
+ * Backend options
+ *
+ * @var array
+ */
+ private $backendOptions = [];
+
+ /**
+ * Mount point path, relative to the user's "files" folder
+ *
+ * @var string
+ */
+ private $mountPoint;
+
+ /**
+ * Storage status
+ *
+ * @var int
+ */
+ private $status;
+
+ /**
+ * Status message
+ *
+ * @var string
+ */
+ private $statusMessage;
+
+ /**
+ * Priority
+ *
+ * @var int
+ */
+ private $priority;
+
+ /**
+ * List of users who have access to this storage
+ *
+ * @var array
+ */
+ private $applicableUsers = [];
+
+ /**
+ * List of groups that have access to this storage
+ *
+ * @var array
+ */
+ private $applicableGroups = [];
+
+ /**
+ * Mount-specific options
+ *
+ * @var array
+ */
+ private $mountOptions = [];
+
+ /**
+ * Whether it's a personal or admin mount
+ *
+ * @var int
+ */
+ private $type;
+
+ /**
+ * Creates a storage config
+ *
+ * @param int|null $id config id or null for a new config
+ */
+ public function __construct($id = null) {
+ $this->id = $id;
+ $this->mountOptions['enable_sharing'] = false;
+ }
+
+ /**
+ * Returns the configuration id
+ *
+ * @return int
+ */
+ public function getId() {
+ return $this->id;
+ }
+
+ /**
+ * Sets the configuration id
+ *
+ * @param int $id configuration id
+ */
+ public function setId($id) {
+ $this->id = $id;
+ }
+
+ /**
+ * Returns mount point path relative to the user's
+ * "files" folder.
+ *
+ * @return string path
+ */
+ public function getMountPoint() {
+ return $this->mountPoint;
+ }
+
+ /**
+ * Sets mount point path relative to the user's
+ * "files" folder.
+ * The path will be normalized.
+ *
+ * @param string $mountPoint path
+ */
+ public function setMountPoint($mountPoint) {
+ $this->mountPoint = \OC\Files\Filesystem::normalizePath($mountPoint);
+ }
+
+ /**
+ * @return Backend
+ */
+ public function getBackend() {
+ return $this->backend;
+ }
+
+ /**
+ * @param Backend $backend
+ */
+ public function setBackend(Backend $backend) {
+ $this->backend= $backend;
+ }
+
+ /**
+ * @return AuthMechanism
+ */
+ public function getAuthMechanism() {
+ return $this->authMechanism;
+ }
+
+ /**
+ * @param AuthMechanism $authMechanism
+ */
+ public function setAuthMechanism(AuthMechanism $authMechanism) {
+ $this->authMechanism = $authMechanism;
+ }
+
+ /**
+ * Returns the external storage backend-specific options
+ *
+ * @return array backend options
+ */
+ public function getBackendOptions() {
+ return $this->backendOptions;
+ }
+
+ /**
+ * Sets the external storage backend-specific options
+ *
+ * @param array $backendOptions backend options
+ */
+ public function setBackendOptions($backendOptions) {
+ if($this->getBackend() instanceof Backend) {
+ $parameters = $this->getBackend()->getParameters();
+ foreach($backendOptions as $key => $value) {
+ if(isset($parameters[$key])) {
+ switch ($parameters[$key]->getType()) {
+ case \OCA\Files_External\Lib\DefinitionParameter::VALUE_BOOLEAN:
+ $value = (bool)$value;
+ break;
+ }
+ $backendOptions[$key] = $value;
+ }
+ }
+ }
+
+ $this->backendOptions = $backendOptions;
+ }
+
+ /**
+ * @param string $key
+ * @return mixed
+ */
+ public function getBackendOption($key) {
+ if (isset($this->backendOptions[$key])) {
+ return $this->backendOptions[$key];
+ }
+ return null;
+ }
+
+ /**
+ * @param string $key
+ * @param mixed $value
+ */
+ public function setBackendOption($key, $value) {
+ $this->backendOptions[$key] = $value;
+ }
+
+ /**
+ * Returns the mount priority
+ *
+ * @return int priority
+ */
+ public function getPriority() {
+ return $this->priority;
+ }
+
+ /**
+ * Sets the mount priotity
+ *
+ * @param int $priority priority
+ */
+ public function setPriority($priority) {
+ $this->priority = $priority;
+ }
+
+ /**
+ * Returns the users for which to mount this storage
+ *
+ * @return array applicable users
+ */
+ public function getApplicableUsers() {
+ return $this->applicableUsers;
+ }
+
+ /**
+ * Sets the users for which to mount this storage
+ *
+ * @param array|null $applicableUsers applicable users
+ */
+ public function setApplicableUsers($applicableUsers) {
+ if (is_null($applicableUsers)) {
+ $applicableUsers = [];
+ }
+ $this->applicableUsers = $applicableUsers;
+ }
+
+ /**
+ * Returns the groups for which to mount this storage
+ *
+ * @return array applicable groups
+ */
+ public function getApplicableGroups() {
+ return $this->applicableGroups;
+ }
+
+ /**
+ * Sets the groups for which to mount this storage
+ *
+ * @param array|null $applicableGroups applicable groups
+ */
+ public function setApplicableGroups($applicableGroups) {
+ if (is_null($applicableGroups)) {
+ $applicableGroups = [];
+ }
+ $this->applicableGroups = $applicableGroups;
+ }
+
+ /**
+ * Returns the mount-specific options
+ *
+ * @return array mount specific options
+ */
+ public function getMountOptions() {
+ return $this->mountOptions;
+ }
+
+ /**
+ * Sets the mount-specific options
+ *
+ * @param array $mountOptions applicable groups
+ */
+ public function setMountOptions($mountOptions) {
+ if (is_null($mountOptions)) {
+ $mountOptions = [];
+ }
+ $this->mountOptions = $mountOptions;
+ }
+
+ /**
+ * @param string $key
+ * @return mixed
+ */
+ public function getMountOption($key) {
+ if (isset($this->mountOptions[$key])) {
+ return $this->mountOptions[$key];
+ }
+ return null;
+ }
+
+ /**
+ * @param string $key
+ * @param mixed $value
+ */
+ public function setMountOption($key, $value) {
+ $this->mountOptions[$key] = $value;
+ }
+
+ /**
+ * Gets the storage status, whether the config worked last time
+ *
+ * @return int $status status
+ */
+ public function getStatus() {
+ return $this->status;
+ }
+
+ /**
+ * Gets the message describing the storage status
+ *
+ * @return string|null
+ */
+ public function getStatusMessage() {
+ return $this->statusMessage;
+ }
+
+ /**
+ * Sets the storage status, whether the config worked last time
+ *
+ * @param int $status status
+ * @param string|null $message optional message
+ */
+ public function setStatus($status, $message = null) {
+ $this->status = $status;
+ $this->statusMessage = $message;
+ }
+
+ /**
+ * @return int self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl
+ */
+ public function getType() {
+ return $this->type;
+ }
+
+ /**
+ * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAl
+ */
+ public function setType($type) {
+ $this->type = $type;
+ }
+
+ /**
+ * Serialize config to JSON
+ *
+ * @return array
+ */
+ public function jsonSerialize() {
+ $result = [];
+ if (!is_null($this->id)) {
+ $result['id'] = $this->id;
+ }
+ $result['mountPoint'] = $this->mountPoint;
+ $result['backend'] = $this->backend->getIdentifier();
+ $result['authMechanism'] = $this->authMechanism->getIdentifier();
+ $result['backendOptions'] = $this->backendOptions;
+ if (!is_null($this->priority)) {
+ $result['priority'] = $this->priority;
+ }
+ if (!empty($this->applicableUsers)) {
+ $result['applicableUsers'] = $this->applicableUsers;
+ }
+ if (!empty($this->applicableGroups)) {
+ $result['applicableGroups'] = $this->applicableGroups;
+ }
+ if (!empty($this->mountOptions)) {
+ $result['mountOptions'] = $this->mountOptions;
+ }
+ if (!is_null($this->status)) {
+ $result['status'] = $this->status;
+ }
+ if (!is_null($this->statusMessage)) {
+ $result['statusMessage'] = $this->statusMessage;
+ }
+ $result['userProvided'] = $this->authMechanism instanceof IUserProvided;
+ $result['type'] = ($this->getType() === self::MOUNT_TYPE_PERSONAl) ? 'personal': 'system';
+ return $result;
+ }
+}
diff --git a/apps/files_external/lib/Lib/StorageModifierTrait.php b/apps/files_external/lib/Lib/StorageModifierTrait.php
new file mode 100644
index 00000000000..30c2108feec
--- /dev/null
+++ b/apps/files_external/lib/Lib/StorageModifierTrait.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Lib;
+
+use \OCP\IUser;
+use \OCP\Files\Storage;
+use \OCA\Files_External\Lib\StorageConfig;
+use \OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException;
+use \OCP\Files\StorageNotAvailableException;
+
+/**
+ * Trait for objects that can modify StorageConfigs and wrap Storages
+ *
+ * When a storage implementation is being prepared for use, the StorageConfig
+ * is passed through manipulateStorageConfig() to update any parameters as
+ * necessary. After the storage implementation has been constructed, it is
+ * passed through wrapStorage(), potentially replacing the implementation with
+ * a wrapped storage that changes its behaviour.
+ *
+ * Certain configuration options need to be set before the implementation is
+ * constructed, while others are retrieved directly from the storage
+ * implementation and so need a wrapper to be modified.
+ */
+trait StorageModifierTrait {
+
+ /**
+ * Modify a StorageConfig parameters
+ *
+ * @param StorageConfig $storage
+ * @param IUser $user User the storage is being used as
+ * @throws InsufficientDataForMeaningfulAnswerException
+ * @throws StorageNotAvailableException
+ */
+ public function manipulateStorageConfig(StorageConfig &$storage, IUser $user = null) {
+ }
+
+ /**
+ * Wrap a Storage if necessary
+ *
+ * @param Storage $storage
+ * @return Storage
+ * @throws InsufficientDataForMeaningfulAnswerException
+ * @throws StorageNotAvailableException
+ */
+ public function wrapStorage(Storage $storage) {
+ return $storage;
+ }
+
+}
+
diff --git a/apps/files_external/lib/Lib/VisibilityTrait.php b/apps/files_external/lib/Lib/VisibilityTrait.php
new file mode 100644
index 00000000000..916c8e69d9c
--- /dev/null
+++ b/apps/files_external/lib/Lib/VisibilityTrait.php
@@ -0,0 +1,136 @@
+<?php
+/**
+ * @author Robin McCorkell <robin@mccorkell.me.uk>
+ *
+ * @copyright Copyright (c) 2016, ownCloud, Inc.
+ * @license AGPL-3.0
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace OCA\Files_External\Lib;
+
+use \OCA\Files_External\Service\BackendService;
+
+/**
+ * Trait to implement visibility mechanics for a configuration class
+ *
+ * The standard visibility defines which users/groups can use or see the
+ * object. The allowed visibility defines the maximum visibility allowed to be
+ * set on the object. The standard visibility is often set dynamically by
+ * stored configuration parameters that can be modified by the administrator,
+ * while the allowed visibility is set directly by the object and cannot be
+ * modified by the administrator.
+ */
+trait VisibilityTrait {
+
+ /** @var int visibility */
+ protected $visibility = BackendService::VISIBILITY_DEFAULT;
+
+ /** @var int allowed visibilities */
+ protected $allowedVisibility = BackendService::VISIBILITY_DEFAULT;
+
+ /**
+ * @return int
+ */
+ public function getVisibility() {
+ return $this->visibility;
+ }
+
+ /**
+ * Check if the backend is visible for a user type
+ *
+ * @param int $visibility
+ * @return bool
+ */
+ public function isVisibleFor($visibility) {
+ if ($this->visibility & $visibility) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @param int $visibility
+ * @return self
+ */
+ public function setVisibility($visibility) {
+ $this->visibility = $visibility;
+ $this->allowedVisibility |= $visibility;
+ return $this;
+ }
+
+ /**
+ * @param int $visibility
+ * @return self
+ */
+ public function addVisibility($visibility) {
+ return $this->setVisibility($this->visibility | $visibility);
+ }
+
+ /**
+ * @param int $visibility
+ * @return self
+ */
+ public function removeVisibility($visibility) {
+ return $this->setVisibility($this->visibility & ~$visibility);
+ }
+
+ /**
+ * @return int
+ */
+ public function getAllowedVisibility() {
+ return $this->allowedVisibility;
+ }
+
+ /**
+ * Check if the backend is allowed to be visible for a user type
+ *
+ * @param int $allowedVisibility
+ * @return bool
+ */
+ public function isAllowedVisibleFor($allowedVisibility) {
+ if ($this->allowedVisibility & $allowedVisibility) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @param int $allowedVisibility
+ * @return self
+ */
+ public function setAllowedVisibility($allowedVisibility) {
+ $this->allowedVisibility = $allowedVisibility;
+ $this->visibility &= $allowedVisibility;
+ return $this;
+ }
+
+ /**
+ * @param int $allowedVisibility
+ * @return self
+ */
+ public function addAllowedVisibility($allowedVisibility) {
+ return $this->setAllowedVisibility($this->allowedVisibility | $allowedVisibility);
+ }
+
+ /**
+ * @param int $allowedVisibility
+ * @return self
+ */
+ public function removeAllowedVisibility($allowedVisibility) {
+ return $this->setAllowedVisibility($this->allowedVisibility & ~$allowedVisibility);
+ }
+
+}