123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- <?php
- /**
- * @author Vincent Petry <pvince81@owncloud.com>
- *
- * @copyright Copyright (c) 2015, 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\Backend\Backend;
- use \OCA\Files_External\Lib\Auth\AuthMechanism;
- /**
- * External storage configuration
- */
- class StorageConfig implements \JsonSerializable {
- /**
- * 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;
- /**
- * 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 = [];
- /**
- * Creates a storage config
- *
- * @param int|null $id config id or null for a new config
- */
- public function __construct($id = null) {
- $this->id = $id;
- }
- /**
- * 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
- */
- public function setBackend(Backend $backend) {
- $this->backend= $backend;
- }
- /**
- * @return AuthMechanism
- */
- public function getAuthMechanism() {
- return $this->authMechanism;
- }
- /**
- * @param 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) {
- $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;
- }
- /**
- * Sets the storage status, whether the config worked last time
- *
- * @return int $status status
- */
- public function getStatus() {
- return $this->status;
- }
- /**
- * Sets the storage status, whether the config worked last time
- *
- * @param int $status status
- */
- public function setStatus($status) {
- $this->status = $status;
- }
- /**
- * 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;
- }
- return $result;
- }
- }
|