@@ -29,15 +29,15 @@ |
||
| 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 | } |
@@ -28,76 +28,76 @@ |
||
| 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 | } |
@@ -128,32 +128,32 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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; |
@@ -44,182 +44,182 @@ |
||
| 44 | 44 | use Symfony\Component\Console\Output\OutputInterface; |
| 45 | 45 | |
| 46 | 46 | class Create extends Base { |
| 47 | - /** |
|
| 48 | - * @var GlobalStoragesService |
|
| 49 | - */ |
|
| 50 | - private $globalService; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var UserStoragesService |
|
| 54 | - */ |
|
| 55 | - private $userService; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var IUserManager |
|
| 59 | - */ |
|
| 60 | - private $userManager; |
|
| 61 | - |
|
| 62 | - /** @var BackendService */ |
|
| 63 | - private $backendService; |
|
| 64 | - |
|
| 65 | - /** @var IUserSession */ |
|
| 66 | - private $userSession; |
|
| 67 | - |
|
| 68 | - public function __construct(GlobalStoragesService $globalService, |
|
| 69 | - UserStoragesService $userService, |
|
| 70 | - IUserManager $userManager, |
|
| 71 | - IUserSession $userSession, |
|
| 72 | - BackendService $backendService |
|
| 73 | - ) { |
|
| 74 | - parent::__construct(); |
|
| 75 | - $this->globalService = $globalService; |
|
| 76 | - $this->userService = $userService; |
|
| 77 | - $this->userManager = $userManager; |
|
| 78 | - $this->userSession = $userSession; |
|
| 79 | - $this->backendService = $backendService; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - protected function configure() { |
|
| 83 | - $this |
|
| 84 | - ->setName('files_external:create') |
|
| 85 | - ->setDescription('Create a new mount configuration') |
|
| 86 | - ->addOption( |
|
| 87 | - 'user', |
|
| 88 | - '', |
|
| 89 | - InputOption::VALUE_OPTIONAL, |
|
| 90 | - 'user to add the mount configuration for, if not set the mount will be added as system mount' |
|
| 91 | - ) |
|
| 92 | - ->addArgument( |
|
| 93 | - 'mount_point', |
|
| 94 | - InputArgument::REQUIRED, |
|
| 95 | - 'mount point for the new mount' |
|
| 96 | - ) |
|
| 97 | - ->addArgument( |
|
| 98 | - 'storage_backend', |
|
| 99 | - InputArgument::REQUIRED, |
|
| 100 | - 'storage backend identifier for the new mount, see `occ files_external:backends` for possible values' |
|
| 101 | - ) |
|
| 102 | - ->addArgument( |
|
| 103 | - 'authentication_backend', |
|
| 104 | - InputArgument::REQUIRED, |
|
| 105 | - 'authentication backend identifier for the new mount, see `occ files_external:backends` for possible values' |
|
| 106 | - ) |
|
| 107 | - ->addOption( |
|
| 108 | - 'config', |
|
| 109 | - 'c', |
|
| 110 | - InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
| 111 | - 'Mount configuration option in key=value format' |
|
| 112 | - ) |
|
| 113 | - ->addOption( |
|
| 114 | - 'dry', |
|
| 115 | - '', |
|
| 116 | - InputOption::VALUE_NONE, |
|
| 117 | - 'Don\'t save the created mount, only list the new mount' |
|
| 118 | - ); |
|
| 119 | - parent::configure(); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 123 | - $user = $input->getOption('user'); |
|
| 124 | - $mountPoint = $input->getArgument('mount_point'); |
|
| 125 | - $storageIdentifier = $input->getArgument('storage_backend'); |
|
| 126 | - $authIdentifier = $input->getArgument('authentication_backend'); |
|
| 127 | - $configInput = $input->getOption('config'); |
|
| 128 | - |
|
| 129 | - $storageBackend = $this->backendService->getBackend($storageIdentifier); |
|
| 130 | - $authBackend = $this->backendService->getAuthMechanism($authIdentifier); |
|
| 131 | - |
|
| 132 | - if (!Filesystem::isValidPath($mountPoint)) { |
|
| 133 | - $output->writeln('<error>Invalid mountpoint "' . $mountPoint . '"</error>'); |
|
| 134 | - return 1; |
|
| 135 | - } |
|
| 136 | - if (is_null($storageBackend)) { |
|
| 137 | - $output->writeln('<error>Storage backend with identifier "' . $storageIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>'); |
|
| 138 | - return 404; |
|
| 139 | - } |
|
| 140 | - if (is_null($authBackend)) { |
|
| 141 | - $output->writeln('<error>Authentication backend with identifier "' . $authIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>'); |
|
| 142 | - return 404; |
|
| 143 | - } |
|
| 144 | - $supportedSchemes = array_keys($storageBackend->getAuthSchemes()); |
|
| 145 | - if (!in_array($authBackend->getScheme(), $supportedSchemes)) { |
|
| 146 | - $output->writeln('<error>Authentication backend "' . $authIdentifier . '" not valid for storage backend "' . $storageIdentifier . '" (see `occ files_external:backends storage ' . $storageIdentifier . '` for possible values)</error>'); |
|
| 147 | - return 1; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - $config = []; |
|
| 151 | - foreach ($configInput as $configOption) { |
|
| 152 | - if (!strpos($configOption, '=')) { |
|
| 153 | - $output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>'); |
|
| 154 | - return 1; |
|
| 155 | - } |
|
| 156 | - list($key, $value) = explode('=', $configOption, 2); |
|
| 157 | - if (!$this->validateParam($key, $value, $storageBackend, $authBackend)) { |
|
| 158 | - $output->writeln('<error>Unknown configuration for backends "' . $key . '"</error>'); |
|
| 159 | - return 1; |
|
| 160 | - } |
|
| 161 | - $config[$key] = $value; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - $mount = new StorageConfig(); |
|
| 165 | - $mount->setMountPoint($mountPoint); |
|
| 166 | - $mount->setBackend($storageBackend); |
|
| 167 | - $mount->setAuthMechanism($authBackend); |
|
| 168 | - $mount->setBackendOptions($config); |
|
| 169 | - |
|
| 170 | - if ($user) { |
|
| 171 | - if (!$this->userManager->userExists($user)) { |
|
| 172 | - $output->writeln('<error>User "' . $user . '" not found</error>'); |
|
| 173 | - return 1; |
|
| 174 | - } |
|
| 175 | - $mount->setApplicableUsers([$user]); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - if ($input->getOption('dry')) { |
|
| 179 | - $this->showMount($user, $mount, $input, $output); |
|
| 180 | - } else { |
|
| 181 | - $this->getStorageService($user)->addStorage($mount); |
|
| 182 | - if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) { |
|
| 183 | - $output->writeln('<info>Storage created with id ' . $mount->getId() . '</info>'); |
|
| 184 | - } else { |
|
| 185 | - $output->writeln((string)$mount->getId()); |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - return 0; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - private function validateParam($key, &$value, Backend $storageBackend, AuthMechanism $authBackend) { |
|
| 192 | - $params = array_merge($storageBackend->getParameters(), $authBackend->getParameters()); |
|
| 193 | - foreach ($params as $param) { |
|
| 194 | - /** @var DefinitionParameter $param */ |
|
| 195 | - if ($param->getName() === $key) { |
|
| 196 | - if ($param->getType() === DefinitionParameter::VALUE_BOOLEAN) { |
|
| 197 | - $value = ($value === 'true'); |
|
| 198 | - } |
|
| 199 | - return true; |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - return false; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - private function showMount($user, StorageConfig $mount, InputInterface $input, OutputInterface $output) { |
|
| 206 | - $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager); |
|
| 207 | - $listInput = new ArrayInput([], $listCommand->getDefinition()); |
|
| 208 | - $listInput->setOption('output', $input->getOption('output')); |
|
| 209 | - $listInput->setOption('show-password', true); |
|
| 210 | - $listCommand->listMounts($user, [$mount], $listInput, $output); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - protected function getStorageService($userId) { |
|
| 214 | - if (!empty($userId)) { |
|
| 215 | - $user = $this->userManager->get($userId); |
|
| 216 | - if (is_null($user)) { |
|
| 217 | - throw new NoUserException("user $userId not found"); |
|
| 218 | - } |
|
| 219 | - $this->userSession->setUser($user); |
|
| 220 | - return $this->userService; |
|
| 221 | - } else { |
|
| 222 | - return $this->globalService; |
|
| 223 | - } |
|
| 224 | - } |
|
| 47 | + /** |
|
| 48 | + * @var GlobalStoragesService |
|
| 49 | + */ |
|
| 50 | + private $globalService; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var UserStoragesService |
|
| 54 | + */ |
|
| 55 | + private $userService; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var IUserManager |
|
| 59 | + */ |
|
| 60 | + private $userManager; |
|
| 61 | + |
|
| 62 | + /** @var BackendService */ |
|
| 63 | + private $backendService; |
|
| 64 | + |
|
| 65 | + /** @var IUserSession */ |
|
| 66 | + private $userSession; |
|
| 67 | + |
|
| 68 | + public function __construct(GlobalStoragesService $globalService, |
|
| 69 | + UserStoragesService $userService, |
|
| 70 | + IUserManager $userManager, |
|
| 71 | + IUserSession $userSession, |
|
| 72 | + BackendService $backendService |
|
| 73 | + ) { |
|
| 74 | + parent::__construct(); |
|
| 75 | + $this->globalService = $globalService; |
|
| 76 | + $this->userService = $userService; |
|
| 77 | + $this->userManager = $userManager; |
|
| 78 | + $this->userSession = $userSession; |
|
| 79 | + $this->backendService = $backendService; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + protected function configure() { |
|
| 83 | + $this |
|
| 84 | + ->setName('files_external:create') |
|
| 85 | + ->setDescription('Create a new mount configuration') |
|
| 86 | + ->addOption( |
|
| 87 | + 'user', |
|
| 88 | + '', |
|
| 89 | + InputOption::VALUE_OPTIONAL, |
|
| 90 | + 'user to add the mount configuration for, if not set the mount will be added as system mount' |
|
| 91 | + ) |
|
| 92 | + ->addArgument( |
|
| 93 | + 'mount_point', |
|
| 94 | + InputArgument::REQUIRED, |
|
| 95 | + 'mount point for the new mount' |
|
| 96 | + ) |
|
| 97 | + ->addArgument( |
|
| 98 | + 'storage_backend', |
|
| 99 | + InputArgument::REQUIRED, |
|
| 100 | + 'storage backend identifier for the new mount, see `occ files_external:backends` for possible values' |
|
| 101 | + ) |
|
| 102 | + ->addArgument( |
|
| 103 | + 'authentication_backend', |
|
| 104 | + InputArgument::REQUIRED, |
|
| 105 | + 'authentication backend identifier for the new mount, see `occ files_external:backends` for possible values' |
|
| 106 | + ) |
|
| 107 | + ->addOption( |
|
| 108 | + 'config', |
|
| 109 | + 'c', |
|
| 110 | + InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, |
|
| 111 | + 'Mount configuration option in key=value format' |
|
| 112 | + ) |
|
| 113 | + ->addOption( |
|
| 114 | + 'dry', |
|
| 115 | + '', |
|
| 116 | + InputOption::VALUE_NONE, |
|
| 117 | + 'Don\'t save the created mount, only list the new mount' |
|
| 118 | + ); |
|
| 119 | + parent::configure(); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 123 | + $user = $input->getOption('user'); |
|
| 124 | + $mountPoint = $input->getArgument('mount_point'); |
|
| 125 | + $storageIdentifier = $input->getArgument('storage_backend'); |
|
| 126 | + $authIdentifier = $input->getArgument('authentication_backend'); |
|
| 127 | + $configInput = $input->getOption('config'); |
|
| 128 | + |
|
| 129 | + $storageBackend = $this->backendService->getBackend($storageIdentifier); |
|
| 130 | + $authBackend = $this->backendService->getAuthMechanism($authIdentifier); |
|
| 131 | + |
|
| 132 | + if (!Filesystem::isValidPath($mountPoint)) { |
|
| 133 | + $output->writeln('<error>Invalid mountpoint "' . $mountPoint . '"</error>'); |
|
| 134 | + return 1; |
|
| 135 | + } |
|
| 136 | + if (is_null($storageBackend)) { |
|
| 137 | + $output->writeln('<error>Storage backend with identifier "' . $storageIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>'); |
|
| 138 | + return 404; |
|
| 139 | + } |
|
| 140 | + if (is_null($authBackend)) { |
|
| 141 | + $output->writeln('<error>Authentication backend with identifier "' . $authIdentifier . '" not found (see `occ files_external:backends` for possible values)</error>'); |
|
| 142 | + return 404; |
|
| 143 | + } |
|
| 144 | + $supportedSchemes = array_keys($storageBackend->getAuthSchemes()); |
|
| 145 | + if (!in_array($authBackend->getScheme(), $supportedSchemes)) { |
|
| 146 | + $output->writeln('<error>Authentication backend "' . $authIdentifier . '" not valid for storage backend "' . $storageIdentifier . '" (see `occ files_external:backends storage ' . $storageIdentifier . '` for possible values)</error>'); |
|
| 147 | + return 1; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + $config = []; |
|
| 151 | + foreach ($configInput as $configOption) { |
|
| 152 | + if (!strpos($configOption, '=')) { |
|
| 153 | + $output->writeln('<error>Invalid mount configuration option "' . $configOption . '"</error>'); |
|
| 154 | + return 1; |
|
| 155 | + } |
|
| 156 | + list($key, $value) = explode('=', $configOption, 2); |
|
| 157 | + if (!$this->validateParam($key, $value, $storageBackend, $authBackend)) { |
|
| 158 | + $output->writeln('<error>Unknown configuration for backends "' . $key . '"</error>'); |
|
| 159 | + return 1; |
|
| 160 | + } |
|
| 161 | + $config[$key] = $value; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + $mount = new StorageConfig(); |
|
| 165 | + $mount->setMountPoint($mountPoint); |
|
| 166 | + $mount->setBackend($storageBackend); |
|
| 167 | + $mount->setAuthMechanism($authBackend); |
|
| 168 | + $mount->setBackendOptions($config); |
|
| 169 | + |
|
| 170 | + if ($user) { |
|
| 171 | + if (!$this->userManager->userExists($user)) { |
|
| 172 | + $output->writeln('<error>User "' . $user . '" not found</error>'); |
|
| 173 | + return 1; |
|
| 174 | + } |
|
| 175 | + $mount->setApplicableUsers([$user]); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + if ($input->getOption('dry')) { |
|
| 179 | + $this->showMount($user, $mount, $input, $output); |
|
| 180 | + } else { |
|
| 181 | + $this->getStorageService($user)->addStorage($mount); |
|
| 182 | + if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN) { |
|
| 183 | + $output->writeln('<info>Storage created with id ' . $mount->getId() . '</info>'); |
|
| 184 | + } else { |
|
| 185 | + $output->writeln((string)$mount->getId()); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + return 0; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + private function validateParam($key, &$value, Backend $storageBackend, AuthMechanism $authBackend) { |
|
| 192 | + $params = array_merge($storageBackend->getParameters(), $authBackend->getParameters()); |
|
| 193 | + foreach ($params as $param) { |
|
| 194 | + /** @var DefinitionParameter $param */ |
|
| 195 | + if ($param->getName() === $key) { |
|
| 196 | + if ($param->getType() === DefinitionParameter::VALUE_BOOLEAN) { |
|
| 197 | + $value = ($value === 'true'); |
|
| 198 | + } |
|
| 199 | + return true; |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + return false; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + private function showMount($user, StorageConfig $mount, InputInterface $input, OutputInterface $output) { |
|
| 206 | + $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager); |
|
| 207 | + $listInput = new ArrayInput([], $listCommand->getDefinition()); |
|
| 208 | + $listInput->setOption('output', $input->getOption('output')); |
|
| 209 | + $listInput->setOption('show-password', true); |
|
| 210 | + $listCommand->listMounts($user, [$mount], $listInput, $output); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + protected function getStorageService($userId) { |
|
| 214 | + if (!empty($userId)) { |
|
| 215 | + $user = $this->userManager->get($userId); |
|
| 216 | + if (is_null($user)) { |
|
| 217 | + throw new NoUserException("user $userId not found"); |
|
| 218 | + } |
|
| 219 | + $this->userSession->setUser($user); |
|
| 220 | + return $this->userService; |
|
| 221 | + } else { |
|
| 222 | + return $this->globalService; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | 225 | } |
@@ -304,9 +304,9 @@ |
||
| 304 | 304 | */ |
| 305 | 305 | public static function linkToRemote($service) { |
| 306 | 306 | $urlGenerator = \OC::$server->getURLGenerator(); |
| 307 | - $remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service; |
|
| 307 | + $remoteBase = $urlGenerator->linkTo('', 'remote.php').'/'.$service; |
|
| 308 | 308 | return $urlGenerator->getAbsoluteURL( |
| 309 | - $remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '') |
|
| 309 | + $remoteBase.(($service[strlen($service) - 1] != '/') ? '/' : '') |
|
| 310 | 310 | ); |
| 311 | 311 | } |
| 312 | 312 | |
@@ -58,476 +58,476 @@ |
||
| 58 | 58 | * @since 4.0.0 |
| 59 | 59 | */ |
| 60 | 60 | class Util { |
| 61 | - /** |
|
| 62 | - * @deprecated 14.0.0 use \OCP\ILogger::DEBUG |
|
| 63 | - */ |
|
| 64 | - public const DEBUG = 0; |
|
| 65 | - /** |
|
| 66 | - * @deprecated 14.0.0 use \OCP\ILogger::INFO |
|
| 67 | - */ |
|
| 68 | - public const INFO = 1; |
|
| 69 | - /** |
|
| 70 | - * @deprecated 14.0.0 use \OCP\ILogger::WARN |
|
| 71 | - */ |
|
| 72 | - public const WARN = 2; |
|
| 73 | - /** |
|
| 74 | - * @deprecated 14.0.0 use \OCP\ILogger::ERROR |
|
| 75 | - */ |
|
| 76 | - public const ERROR = 3; |
|
| 77 | - /** |
|
| 78 | - * @deprecated 14.0.0 use \OCP\ILogger::FATAL |
|
| 79 | - */ |
|
| 80 | - public const FATAL = 4; |
|
| 81 | - |
|
| 82 | - /** \OCP\Share\IManager */ |
|
| 83 | - private static $shareManager; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * get the current installed version of Nextcloud |
|
| 87 | - * @return array |
|
| 88 | - * @since 4.0.0 |
|
| 89 | - */ |
|
| 90 | - public static function getVersion() { |
|
| 91 | - return \OC_Util::getVersion(); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @since 17.0.0 |
|
| 96 | - */ |
|
| 97 | - public static function hasExtendedSupport(): bool { |
|
| 98 | - try { |
|
| 99 | - /** @var \OCP\Support\Subscription\IRegistry */ |
|
| 100 | - $subscriptionRegistry = \OC::$server->query(\OCP\Support\Subscription\IRegistry::class); |
|
| 101 | - return $subscriptionRegistry->delegateHasExtendedSupport(); |
|
| 102 | - } catch (AppFramework\QueryException $e) { |
|
| 103 | - } |
|
| 104 | - return \OC::$server->getConfig()->getSystemValueBool('extendedSupport', false); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Set current update channel |
|
| 109 | - * @param string $channel |
|
| 110 | - * @since 8.1.0 |
|
| 111 | - */ |
|
| 112 | - public static function setChannel($channel) { |
|
| 113 | - \OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Get current update channel |
|
| 118 | - * @return string |
|
| 119 | - * @since 8.1.0 |
|
| 120 | - */ |
|
| 121 | - public static function getChannel() { |
|
| 122 | - return \OC_Util::getChannel(); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * write a message in the log |
|
| 127 | - * @param string $app |
|
| 128 | - * @param string $message |
|
| 129 | - * @param int $level |
|
| 130 | - * @since 4.0.0 |
|
| 131 | - * @deprecated 13.0.0 use log of \OCP\ILogger |
|
| 132 | - */ |
|
| 133 | - public static function writeLog($app, $message, $level) { |
|
| 134 | - $context = ['app' => $app]; |
|
| 135 | - \OC::$server->getLogger()->log($level, $message, $context); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * check if sharing is disabled for the current user |
|
| 140 | - * |
|
| 141 | - * @return boolean |
|
| 142 | - * @since 7.0.0 |
|
| 143 | - * @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser |
|
| 144 | - */ |
|
| 145 | - public static function isSharingDisabledForUser() { |
|
| 146 | - if (self::$shareManager === null) { |
|
| 147 | - self::$shareManager = \OC::$server->getShareManager(); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - $user = \OC::$server->getUserSession()->getUser(); |
|
| 151 | - if ($user !== null) { |
|
| 152 | - $user = $user->getUID(); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - return self::$shareManager->sharingDisabledForUser($user); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * get l10n object |
|
| 160 | - * @param string $application |
|
| 161 | - * @param string|null $language |
|
| 162 | - * @return \OCP\IL10N |
|
| 163 | - * @since 6.0.0 - parameter $language was added in 8.0.0 |
|
| 164 | - */ |
|
| 165 | - public static function getL10N($application, $language = null) { |
|
| 166 | - return \OC::$server->getL10N($application, $language); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * add a css file |
|
| 171 | - * @param string $application |
|
| 172 | - * @param string $file |
|
| 173 | - * @since 4.0.0 |
|
| 174 | - */ |
|
| 175 | - public static function addStyle($application, $file = null) { |
|
| 176 | - \OC_Util::addStyle($application, $file); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * add a javascript file |
|
| 181 | - * @param string $application |
|
| 182 | - * @param string $file |
|
| 183 | - * @since 4.0.0 |
|
| 184 | - */ |
|
| 185 | - public static function addScript($application, $file = null) { |
|
| 186 | - \OC_Util::addScript($application, $file); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Add a translation JS file |
|
| 191 | - * @param string $application application id |
|
| 192 | - * @param string $languageCode language code, defaults to the current locale |
|
| 193 | - * @since 8.0.0 |
|
| 194 | - */ |
|
| 195 | - public static function addTranslations($application, $languageCode = null) { |
|
| 196 | - \OC_Util::addTranslations($application, $languageCode); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Add a custom element to the header |
|
| 201 | - * If $text is null then the element will be written as empty element. |
|
| 202 | - * So use "" to get a closing tag. |
|
| 203 | - * @param string $tag tag name of the element |
|
| 204 | - * @param array $attributes array of attributes for the element |
|
| 205 | - * @param string $text the text content for the element |
|
| 206 | - * @since 4.0.0 |
|
| 207 | - */ |
|
| 208 | - public static function addHeader($tag, $attributes, $text = null) { |
|
| 209 | - \OC_Util::addHeader($tag, $attributes, $text); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Creates an absolute url to the given app and file. |
|
| 214 | - * @param string $app app |
|
| 215 | - * @param string $file file |
|
| 216 | - * @param array $args array with param=>value, will be appended to the returned url |
|
| 217 | - * The value of $args will be urlencoded |
|
| 218 | - * @return string the url |
|
| 219 | - * @since 4.0.0 - parameter $args was added in 4.5.0 |
|
| 220 | - */ |
|
| 221 | - public static function linkToAbsolute($app, $file, $args = []) { |
|
| 222 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 223 | - return $urlGenerator->getAbsoluteURL( |
|
| 224 | - $urlGenerator->linkTo($app, $file, $args) |
|
| 225 | - ); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Creates an absolute url for remote use. |
|
| 230 | - * @param string $service id |
|
| 231 | - * @return string the url |
|
| 232 | - * @since 4.0.0 |
|
| 233 | - */ |
|
| 234 | - public static function linkToRemote($service) { |
|
| 235 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 236 | - $remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service; |
|
| 237 | - return $urlGenerator->getAbsoluteURL( |
|
| 238 | - $remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '') |
|
| 239 | - ); |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Creates an absolute url for public use |
|
| 244 | - * @param string $service id |
|
| 245 | - * @return string the url |
|
| 246 | - * @since 4.5.0 |
|
| 247 | - * @deprecated 15.0.0 - use OCP\IURLGenerator |
|
| 248 | - */ |
|
| 249 | - public static function linkToPublic($service) { |
|
| 250 | - $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 251 | - if ($service === 'files') { |
|
| 252 | - return $urlGenerator->getAbsoluteURL('/s'); |
|
| 253 | - } |
|
| 254 | - return $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'public.php').'?service='.$service); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Returns the server host name without an eventual port number |
|
| 259 | - * @return string the server hostname |
|
| 260 | - * @since 5.0.0 |
|
| 261 | - */ |
|
| 262 | - public static function getServerHostName() { |
|
| 263 | - $host_name = \OC::$server->getRequest()->getServerHost(); |
|
| 264 | - // strip away port number (if existing) |
|
| 265 | - $colon_pos = strpos($host_name, ':'); |
|
| 266 | - if ($colon_pos != false) { |
|
| 267 | - $host_name = substr($host_name, 0, $colon_pos); |
|
| 268 | - } |
|
| 269 | - return $host_name; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Returns the default email address |
|
| 274 | - * @param string $user_part the user part of the address |
|
| 275 | - * @return string the default email address |
|
| 276 | - * |
|
| 277 | - * Assembles a default email address (using the server hostname |
|
| 278 | - * and the given user part, and returns it |
|
| 279 | - * Example: when given lostpassword-noreply as $user_part param, |
|
| 280 | - * and is currently accessed via http(s)://example.com/, |
|
| 281 | - * it would return '[email protected]' |
|
| 282 | - * |
|
| 283 | - * If the configuration value 'mail_from_address' is set in |
|
| 284 | - * config.php, this value will override the $user_part that |
|
| 285 | - * is passed to this function |
|
| 286 | - * @since 5.0.0 |
|
| 287 | - */ |
|
| 288 | - public static function getDefaultEmailAddress($user_part) { |
|
| 289 | - $config = \OC::$server->getConfig(); |
|
| 290 | - $user_part = $config->getSystemValue('mail_from_address', $user_part); |
|
| 291 | - $host_name = self::getServerHostName(); |
|
| 292 | - $host_name = $config->getSystemValue('mail_domain', $host_name); |
|
| 293 | - $defaultEmailAddress = $user_part.'@'.$host_name; |
|
| 294 | - |
|
| 295 | - $mailer = \OC::$server->getMailer(); |
|
| 296 | - if ($mailer->validateMailAddress($defaultEmailAddress)) { |
|
| 297 | - return $defaultEmailAddress; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - // in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain' |
|
| 301 | - return $user_part.'@localhost.localdomain'; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Make a human file size (2048 to 2 kB) |
|
| 306 | - * @param int $bytes file size in bytes |
|
| 307 | - * @return string a human readable file size |
|
| 308 | - * @since 4.0.0 |
|
| 309 | - */ |
|
| 310 | - public static function humanFileSize($bytes) { |
|
| 311 | - return \OC_Helper::humanFileSize($bytes); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * Make a computer file size (2 kB to 2048) |
|
| 316 | - * @param string $str file size in a fancy format |
|
| 317 | - * @return float a file size in bytes |
|
| 318 | - * |
|
| 319 | - * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418 |
|
| 320 | - * @since 4.0.0 |
|
| 321 | - */ |
|
| 322 | - public static function computerFileSize($str) { |
|
| 323 | - return \OC_Helper::computerFileSize($str); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * connects a function to a hook |
|
| 328 | - * |
|
| 329 | - * @param string $signalClass class name of emitter |
|
| 330 | - * @param string $signalName name of signal |
|
| 331 | - * @param string|object $slotClass class name of slot |
|
| 332 | - * @param string $slotName name of slot |
|
| 333 | - * @return bool |
|
| 334 | - * |
|
| 335 | - * This function makes it very easy to connect to use hooks. |
|
| 336 | - * |
|
| 337 | - * TODO: write example |
|
| 338 | - * @since 4.0.0 |
|
| 339 | - * @deprecated 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::addListener |
|
| 340 | - */ |
|
| 341 | - public static function connectHook($signalClass, $signalName, $slotClass, $slotName) { |
|
| 342 | - return \OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - /** |
|
| 346 | - * Emits a signal. To get data from the slot use references! |
|
| 347 | - * @param string $signalclass class name of emitter |
|
| 348 | - * @param string $signalname name of signal |
|
| 349 | - * @param array $params default: array() array with additional data |
|
| 350 | - * @return bool true if slots exists or false if not |
|
| 351 | - * |
|
| 352 | - * TODO: write example |
|
| 353 | - * @since 4.0.0 |
|
| 354 | - * @deprecated 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::dispatchTypedEvent |
|
| 355 | - */ |
|
| 356 | - public static function emitHook($signalclass, $signalname, $params = []) { |
|
| 357 | - return \OC_Hook::emit($signalclass, $signalname, $params); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - /** |
|
| 361 | - * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare |
|
| 362 | - * multiple OC_Template elements which invoke `callRegister`. If the value |
|
| 363 | - * would not be cached these unit-tests would fail. |
|
| 364 | - * @var string |
|
| 365 | - */ |
|
| 366 | - private static $token = ''; |
|
| 367 | - |
|
| 368 | - /** |
|
| 369 | - * Register an get/post call. This is important to prevent CSRF attacks |
|
| 370 | - * @since 4.5.0 |
|
| 371 | - */ |
|
| 372 | - public static function callRegister() { |
|
| 373 | - if (self::$token === '') { |
|
| 374 | - self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue(); |
|
| 375 | - } |
|
| 376 | - return self::$token; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * Used to sanitize HTML |
|
| 381 | - * |
|
| 382 | - * This function is used to sanitize HTML and should be applied on any |
|
| 383 | - * string or array of strings before displaying it on a web page. |
|
| 384 | - * |
|
| 385 | - * @param string|array $value |
|
| 386 | - * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
| 387 | - * @since 4.5.0 |
|
| 388 | - */ |
|
| 389 | - public static function sanitizeHTML($value) { |
|
| 390 | - return \OC_Util::sanitizeHTML($value); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * Public function to encode url parameters |
|
| 395 | - * |
|
| 396 | - * This function is used to encode path to file before output. |
|
| 397 | - * Encoding is done according to RFC 3986 with one exception: |
|
| 398 | - * Character '/' is preserved as is. |
|
| 399 | - * |
|
| 400 | - * @param string $component part of URI to encode |
|
| 401 | - * @return string |
|
| 402 | - * @since 6.0.0 |
|
| 403 | - */ |
|
| 404 | - public static function encodePath($component) { |
|
| 405 | - return \OC_Util::encodePath($component); |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. |
|
| 410 | - * |
|
| 411 | - * @param array $input The array to work on |
|
| 412 | - * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default) |
|
| 413 | - * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 |
|
| 414 | - * @return array |
|
| 415 | - * @since 4.5.0 |
|
| 416 | - */ |
|
| 417 | - public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') { |
|
| 418 | - return \OC_Helper::mb_array_change_key_case($input, $case, $encoding); |
|
| 419 | - } |
|
| 420 | - |
|
| 421 | - /** |
|
| 422 | - * performs a search in a nested array |
|
| 423 | - * |
|
| 424 | - * @param array $haystack the array to be searched |
|
| 425 | - * @param string $needle the search string |
|
| 426 | - * @param mixed $index optional, only search this key name |
|
| 427 | - * @return mixed the key of the matching field, otherwise false |
|
| 428 | - * @since 4.5.0 |
|
| 429 | - * @deprecated 15.0.0 |
|
| 430 | - */ |
|
| 431 | - public static function recursiveArraySearch($haystack, $needle, $index = null) { |
|
| 432 | - return \OC_Helper::recursiveArraySearch($haystack, $needle, $index); |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - /** |
|
| 436 | - * calculates the maximum upload size respecting system settings, free space and user quota |
|
| 437 | - * |
|
| 438 | - * @param string $dir the current folder where the user currently operates |
|
| 439 | - * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly |
|
| 440 | - * @return int number of bytes representing |
|
| 441 | - * @since 5.0.0 |
|
| 442 | - */ |
|
| 443 | - public static function maxUploadFilesize($dir, $free = null) { |
|
| 444 | - return \OC_Helper::maxUploadFilesize($dir, $free); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * Calculate free space left within user quota |
|
| 449 | - * @param string $dir the current folder where the user currently operates |
|
| 450 | - * @return int number of bytes representing |
|
| 451 | - * @since 7.0.0 |
|
| 452 | - */ |
|
| 453 | - public static function freeSpace($dir) { |
|
| 454 | - return \OC_Helper::freeSpace($dir); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - /** |
|
| 458 | - * Calculate PHP upload limit |
|
| 459 | - * |
|
| 460 | - * @return int number of bytes representing |
|
| 461 | - * @since 7.0.0 |
|
| 462 | - */ |
|
| 463 | - public static function uploadLimit() { |
|
| 464 | - return \OC_Helper::uploadLimit(); |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Returns whether the given file name is valid |
|
| 469 | - * @param string $file file name to check |
|
| 470 | - * @return bool true if the file name is valid, false otherwise |
|
| 471 | - * @deprecated 8.1.0 use \OC\Files\View::verifyPath() |
|
| 472 | - * @since 7.0.0 |
|
| 473 | - * @suppress PhanDeprecatedFunction |
|
| 474 | - */ |
|
| 475 | - public static function isValidFileName($file) { |
|
| 476 | - return \OC_Util::isValidFileName($file); |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - /** |
|
| 480 | - * Compare two strings to provide a natural sort |
|
| 481 | - * @param string $a first string to compare |
|
| 482 | - * @param string $b second string to compare |
|
| 483 | - * @return int -1 if $b comes before $a, 1 if $a comes before $b |
|
| 484 | - * or 0 if the strings are identical |
|
| 485 | - * @since 7.0.0 |
|
| 486 | - */ |
|
| 487 | - public static function naturalSortCompare($a, $b) { |
|
| 488 | - return \OC\NaturalSort::getInstance()->compare($a, $b); |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * check if a password is required for each public link |
|
| 493 | - * @return boolean |
|
| 494 | - * @since 7.0.0 |
|
| 495 | - */ |
|
| 496 | - public static function isPublicLinkPasswordRequired() { |
|
| 497 | - return \OC_Util::isPublicLinkPasswordRequired(); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - /** |
|
| 501 | - * check if share API enforces a default expire date |
|
| 502 | - * @return boolean |
|
| 503 | - * @since 8.0.0 |
|
| 504 | - */ |
|
| 505 | - public static function isDefaultExpireDateEnforced() { |
|
| 506 | - return \OC_Util::isDefaultExpireDateEnforced(); |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - protected static $needUpgradeCache = null; |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * Checks whether the current version needs upgrade. |
|
| 513 | - * |
|
| 514 | - * @return bool true if upgrade is needed, false otherwise |
|
| 515 | - * @since 7.0.0 |
|
| 516 | - */ |
|
| 517 | - public static function needUpgrade() { |
|
| 518 | - if (!isset(self::$needUpgradeCache)) { |
|
| 519 | - self::$needUpgradeCache = \OC_Util::needUpgrade(\OC::$server->getSystemConfig()); |
|
| 520 | - } |
|
| 521 | - return self::$needUpgradeCache; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - /** |
|
| 525 | - * is this Internet explorer ? |
|
| 526 | - * |
|
| 527 | - * @return boolean |
|
| 528 | - * @since 14.0.0 |
|
| 529 | - */ |
|
| 530 | - public static function isIe() { |
|
| 531 | - return \OC_Util::isIe(); |
|
| 532 | - } |
|
| 61 | + /** |
|
| 62 | + * @deprecated 14.0.0 use \OCP\ILogger::DEBUG |
|
| 63 | + */ |
|
| 64 | + public const DEBUG = 0; |
|
| 65 | + /** |
|
| 66 | + * @deprecated 14.0.0 use \OCP\ILogger::INFO |
|
| 67 | + */ |
|
| 68 | + public const INFO = 1; |
|
| 69 | + /** |
|
| 70 | + * @deprecated 14.0.0 use \OCP\ILogger::WARN |
|
| 71 | + */ |
|
| 72 | + public const WARN = 2; |
|
| 73 | + /** |
|
| 74 | + * @deprecated 14.0.0 use \OCP\ILogger::ERROR |
|
| 75 | + */ |
|
| 76 | + public const ERROR = 3; |
|
| 77 | + /** |
|
| 78 | + * @deprecated 14.0.0 use \OCP\ILogger::FATAL |
|
| 79 | + */ |
|
| 80 | + public const FATAL = 4; |
|
| 81 | + |
|
| 82 | + /** \OCP\Share\IManager */ |
|
| 83 | + private static $shareManager; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * get the current installed version of Nextcloud |
|
| 87 | + * @return array |
|
| 88 | + * @since 4.0.0 |
|
| 89 | + */ |
|
| 90 | + public static function getVersion() { |
|
| 91 | + return \OC_Util::getVersion(); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @since 17.0.0 |
|
| 96 | + */ |
|
| 97 | + public static function hasExtendedSupport(): bool { |
|
| 98 | + try { |
|
| 99 | + /** @var \OCP\Support\Subscription\IRegistry */ |
|
| 100 | + $subscriptionRegistry = \OC::$server->query(\OCP\Support\Subscription\IRegistry::class); |
|
| 101 | + return $subscriptionRegistry->delegateHasExtendedSupport(); |
|
| 102 | + } catch (AppFramework\QueryException $e) { |
|
| 103 | + } |
|
| 104 | + return \OC::$server->getConfig()->getSystemValueBool('extendedSupport', false); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Set current update channel |
|
| 109 | + * @param string $channel |
|
| 110 | + * @since 8.1.0 |
|
| 111 | + */ |
|
| 112 | + public static function setChannel($channel) { |
|
| 113 | + \OC::$server->getConfig()->setSystemValue('updater.release.channel', $channel); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Get current update channel |
|
| 118 | + * @return string |
|
| 119 | + * @since 8.1.0 |
|
| 120 | + */ |
|
| 121 | + public static function getChannel() { |
|
| 122 | + return \OC_Util::getChannel(); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * write a message in the log |
|
| 127 | + * @param string $app |
|
| 128 | + * @param string $message |
|
| 129 | + * @param int $level |
|
| 130 | + * @since 4.0.0 |
|
| 131 | + * @deprecated 13.0.0 use log of \OCP\ILogger |
|
| 132 | + */ |
|
| 133 | + public static function writeLog($app, $message, $level) { |
|
| 134 | + $context = ['app' => $app]; |
|
| 135 | + \OC::$server->getLogger()->log($level, $message, $context); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * check if sharing is disabled for the current user |
|
| 140 | + * |
|
| 141 | + * @return boolean |
|
| 142 | + * @since 7.0.0 |
|
| 143 | + * @deprecated 9.1.0 Use \OC::$server->getShareManager()->sharingDisabledForUser |
|
| 144 | + */ |
|
| 145 | + public static function isSharingDisabledForUser() { |
|
| 146 | + if (self::$shareManager === null) { |
|
| 147 | + self::$shareManager = \OC::$server->getShareManager(); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + $user = \OC::$server->getUserSession()->getUser(); |
|
| 151 | + if ($user !== null) { |
|
| 152 | + $user = $user->getUID(); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + return self::$shareManager->sharingDisabledForUser($user); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * get l10n object |
|
| 160 | + * @param string $application |
|
| 161 | + * @param string|null $language |
|
| 162 | + * @return \OCP\IL10N |
|
| 163 | + * @since 6.0.0 - parameter $language was added in 8.0.0 |
|
| 164 | + */ |
|
| 165 | + public static function getL10N($application, $language = null) { |
|
| 166 | + return \OC::$server->getL10N($application, $language); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * add a css file |
|
| 171 | + * @param string $application |
|
| 172 | + * @param string $file |
|
| 173 | + * @since 4.0.0 |
|
| 174 | + */ |
|
| 175 | + public static function addStyle($application, $file = null) { |
|
| 176 | + \OC_Util::addStyle($application, $file); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * add a javascript file |
|
| 181 | + * @param string $application |
|
| 182 | + * @param string $file |
|
| 183 | + * @since 4.0.0 |
|
| 184 | + */ |
|
| 185 | + public static function addScript($application, $file = null) { |
|
| 186 | + \OC_Util::addScript($application, $file); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Add a translation JS file |
|
| 191 | + * @param string $application application id |
|
| 192 | + * @param string $languageCode language code, defaults to the current locale |
|
| 193 | + * @since 8.0.0 |
|
| 194 | + */ |
|
| 195 | + public static function addTranslations($application, $languageCode = null) { |
|
| 196 | + \OC_Util::addTranslations($application, $languageCode); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Add a custom element to the header |
|
| 201 | + * If $text is null then the element will be written as empty element. |
|
| 202 | + * So use "" to get a closing tag. |
|
| 203 | + * @param string $tag tag name of the element |
|
| 204 | + * @param array $attributes array of attributes for the element |
|
| 205 | + * @param string $text the text content for the element |
|
| 206 | + * @since 4.0.0 |
|
| 207 | + */ |
|
| 208 | + public static function addHeader($tag, $attributes, $text = null) { |
|
| 209 | + \OC_Util::addHeader($tag, $attributes, $text); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Creates an absolute url to the given app and file. |
|
| 214 | + * @param string $app app |
|
| 215 | + * @param string $file file |
|
| 216 | + * @param array $args array with param=>value, will be appended to the returned url |
|
| 217 | + * The value of $args will be urlencoded |
|
| 218 | + * @return string the url |
|
| 219 | + * @since 4.0.0 - parameter $args was added in 4.5.0 |
|
| 220 | + */ |
|
| 221 | + public static function linkToAbsolute($app, $file, $args = []) { |
|
| 222 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 223 | + return $urlGenerator->getAbsoluteURL( |
|
| 224 | + $urlGenerator->linkTo($app, $file, $args) |
|
| 225 | + ); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Creates an absolute url for remote use. |
|
| 230 | + * @param string $service id |
|
| 231 | + * @return string the url |
|
| 232 | + * @since 4.0.0 |
|
| 233 | + */ |
|
| 234 | + public static function linkToRemote($service) { |
|
| 235 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 236 | + $remoteBase = $urlGenerator->linkTo('', 'remote.php') . '/' . $service; |
|
| 237 | + return $urlGenerator->getAbsoluteURL( |
|
| 238 | + $remoteBase . (($service[strlen($service) - 1] != '/') ? '/' : '') |
|
| 239 | + ); |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Creates an absolute url for public use |
|
| 244 | + * @param string $service id |
|
| 245 | + * @return string the url |
|
| 246 | + * @since 4.5.0 |
|
| 247 | + * @deprecated 15.0.0 - use OCP\IURLGenerator |
|
| 248 | + */ |
|
| 249 | + public static function linkToPublic($service) { |
|
| 250 | + $urlGenerator = \OC::$server->getURLGenerator(); |
|
| 251 | + if ($service === 'files') { |
|
| 252 | + return $urlGenerator->getAbsoluteURL('/s'); |
|
| 253 | + } |
|
| 254 | + return $urlGenerator->getAbsoluteURL($urlGenerator->linkTo('', 'public.php').'?service='.$service); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Returns the server host name without an eventual port number |
|
| 259 | + * @return string the server hostname |
|
| 260 | + * @since 5.0.0 |
|
| 261 | + */ |
|
| 262 | + public static function getServerHostName() { |
|
| 263 | + $host_name = \OC::$server->getRequest()->getServerHost(); |
|
| 264 | + // strip away port number (if existing) |
|
| 265 | + $colon_pos = strpos($host_name, ':'); |
|
| 266 | + if ($colon_pos != false) { |
|
| 267 | + $host_name = substr($host_name, 0, $colon_pos); |
|
| 268 | + } |
|
| 269 | + return $host_name; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Returns the default email address |
|
| 274 | + * @param string $user_part the user part of the address |
|
| 275 | + * @return string the default email address |
|
| 276 | + * |
|
| 277 | + * Assembles a default email address (using the server hostname |
|
| 278 | + * and the given user part, and returns it |
|
| 279 | + * Example: when given lostpassword-noreply as $user_part param, |
|
| 280 | + * and is currently accessed via http(s)://example.com/, |
|
| 281 | + * it would return '[email protected]' |
|
| 282 | + * |
|
| 283 | + * If the configuration value 'mail_from_address' is set in |
|
| 284 | + * config.php, this value will override the $user_part that |
|
| 285 | + * is passed to this function |
|
| 286 | + * @since 5.0.0 |
|
| 287 | + */ |
|
| 288 | + public static function getDefaultEmailAddress($user_part) { |
|
| 289 | + $config = \OC::$server->getConfig(); |
|
| 290 | + $user_part = $config->getSystemValue('mail_from_address', $user_part); |
|
| 291 | + $host_name = self::getServerHostName(); |
|
| 292 | + $host_name = $config->getSystemValue('mail_domain', $host_name); |
|
| 293 | + $defaultEmailAddress = $user_part.'@'.$host_name; |
|
| 294 | + |
|
| 295 | + $mailer = \OC::$server->getMailer(); |
|
| 296 | + if ($mailer->validateMailAddress($defaultEmailAddress)) { |
|
| 297 | + return $defaultEmailAddress; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + // in case we cannot build a valid email address from the hostname let's fallback to 'localhost.localdomain' |
|
| 301 | + return $user_part.'@localhost.localdomain'; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Make a human file size (2048 to 2 kB) |
|
| 306 | + * @param int $bytes file size in bytes |
|
| 307 | + * @return string a human readable file size |
|
| 308 | + * @since 4.0.0 |
|
| 309 | + */ |
|
| 310 | + public static function humanFileSize($bytes) { |
|
| 311 | + return \OC_Helper::humanFileSize($bytes); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * Make a computer file size (2 kB to 2048) |
|
| 316 | + * @param string $str file size in a fancy format |
|
| 317 | + * @return float a file size in bytes |
|
| 318 | + * |
|
| 319 | + * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418 |
|
| 320 | + * @since 4.0.0 |
|
| 321 | + */ |
|
| 322 | + public static function computerFileSize($str) { |
|
| 323 | + return \OC_Helper::computerFileSize($str); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * connects a function to a hook |
|
| 328 | + * |
|
| 329 | + * @param string $signalClass class name of emitter |
|
| 330 | + * @param string $signalName name of signal |
|
| 331 | + * @param string|object $slotClass class name of slot |
|
| 332 | + * @param string $slotName name of slot |
|
| 333 | + * @return bool |
|
| 334 | + * |
|
| 335 | + * This function makes it very easy to connect to use hooks. |
|
| 336 | + * |
|
| 337 | + * TODO: write example |
|
| 338 | + * @since 4.0.0 |
|
| 339 | + * @deprecated 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::addListener |
|
| 340 | + */ |
|
| 341 | + public static function connectHook($signalClass, $signalName, $slotClass, $slotName) { |
|
| 342 | + return \OC_Hook::connect($signalClass, $signalName, $slotClass, $slotName); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + /** |
|
| 346 | + * Emits a signal. To get data from the slot use references! |
|
| 347 | + * @param string $signalclass class name of emitter |
|
| 348 | + * @param string $signalname name of signal |
|
| 349 | + * @param array $params default: array() array with additional data |
|
| 350 | + * @return bool true if slots exists or false if not |
|
| 351 | + * |
|
| 352 | + * TODO: write example |
|
| 353 | + * @since 4.0.0 |
|
| 354 | + * @deprecated 21.0.0 use \OCP\EventDispatcher\IEventDispatcher::dispatchTypedEvent |
|
| 355 | + */ |
|
| 356 | + public static function emitHook($signalclass, $signalname, $params = []) { |
|
| 357 | + return \OC_Hook::emit($signalclass, $signalname, $params); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + /** |
|
| 361 | + * Cached encrypted CSRF token. Some static unit-tests of ownCloud compare |
|
| 362 | + * multiple OC_Template elements which invoke `callRegister`. If the value |
|
| 363 | + * would not be cached these unit-tests would fail. |
|
| 364 | + * @var string |
|
| 365 | + */ |
|
| 366 | + private static $token = ''; |
|
| 367 | + |
|
| 368 | + /** |
|
| 369 | + * Register an get/post call. This is important to prevent CSRF attacks |
|
| 370 | + * @since 4.5.0 |
|
| 371 | + */ |
|
| 372 | + public static function callRegister() { |
|
| 373 | + if (self::$token === '') { |
|
| 374 | + self::$token = \OC::$server->getCsrfTokenManager()->getToken()->getEncryptedValue(); |
|
| 375 | + } |
|
| 376 | + return self::$token; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Used to sanitize HTML |
|
| 381 | + * |
|
| 382 | + * This function is used to sanitize HTML and should be applied on any |
|
| 383 | + * string or array of strings before displaying it on a web page. |
|
| 384 | + * |
|
| 385 | + * @param string|array $value |
|
| 386 | + * @return string|array an array of sanitized strings or a single sanitized string, depends on the input parameter. |
|
| 387 | + * @since 4.5.0 |
|
| 388 | + */ |
|
| 389 | + public static function sanitizeHTML($value) { |
|
| 390 | + return \OC_Util::sanitizeHTML($value); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * Public function to encode url parameters |
|
| 395 | + * |
|
| 396 | + * This function is used to encode path to file before output. |
|
| 397 | + * Encoding is done according to RFC 3986 with one exception: |
|
| 398 | + * Character '/' is preserved as is. |
|
| 399 | + * |
|
| 400 | + * @param string $component part of URI to encode |
|
| 401 | + * @return string |
|
| 402 | + * @since 6.0.0 |
|
| 403 | + */ |
|
| 404 | + public static function encodePath($component) { |
|
| 405 | + return \OC_Util::encodePath($component); |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * Returns an array with all keys from input lowercased or uppercased. Numbered indices are left as is. |
|
| 410 | + * |
|
| 411 | + * @param array $input The array to work on |
|
| 412 | + * @param int $case Either MB_CASE_UPPER or MB_CASE_LOWER (default) |
|
| 413 | + * @param string $encoding The encoding parameter is the character encoding. Defaults to UTF-8 |
|
| 414 | + * @return array |
|
| 415 | + * @since 4.5.0 |
|
| 416 | + */ |
|
| 417 | + public static function mb_array_change_key_case($input, $case = MB_CASE_LOWER, $encoding = 'UTF-8') { |
|
| 418 | + return \OC_Helper::mb_array_change_key_case($input, $case, $encoding); |
|
| 419 | + } |
|
| 420 | + |
|
| 421 | + /** |
|
| 422 | + * performs a search in a nested array |
|
| 423 | + * |
|
| 424 | + * @param array $haystack the array to be searched |
|
| 425 | + * @param string $needle the search string |
|
| 426 | + * @param mixed $index optional, only search this key name |
|
| 427 | + * @return mixed the key of the matching field, otherwise false |
|
| 428 | + * @since 4.5.0 |
|
| 429 | + * @deprecated 15.0.0 |
|
| 430 | + */ |
|
| 431 | + public static function recursiveArraySearch($haystack, $needle, $index = null) { |
|
| 432 | + return \OC_Helper::recursiveArraySearch($haystack, $needle, $index); |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + /** |
|
| 436 | + * calculates the maximum upload size respecting system settings, free space and user quota |
|
| 437 | + * |
|
| 438 | + * @param string $dir the current folder where the user currently operates |
|
| 439 | + * @param int $free the number of bytes free on the storage holding $dir, if not set this will be received from the storage directly |
|
| 440 | + * @return int number of bytes representing |
|
| 441 | + * @since 5.0.0 |
|
| 442 | + */ |
|
| 443 | + public static function maxUploadFilesize($dir, $free = null) { |
|
| 444 | + return \OC_Helper::maxUploadFilesize($dir, $free); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * Calculate free space left within user quota |
|
| 449 | + * @param string $dir the current folder where the user currently operates |
|
| 450 | + * @return int number of bytes representing |
|
| 451 | + * @since 7.0.0 |
|
| 452 | + */ |
|
| 453 | + public static function freeSpace($dir) { |
|
| 454 | + return \OC_Helper::freeSpace($dir); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + /** |
|
| 458 | + * Calculate PHP upload limit |
|
| 459 | + * |
|
| 460 | + * @return int number of bytes representing |
|
| 461 | + * @since 7.0.0 |
|
| 462 | + */ |
|
| 463 | + public static function uploadLimit() { |
|
| 464 | + return \OC_Helper::uploadLimit(); |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Returns whether the given file name is valid |
|
| 469 | + * @param string $file file name to check |
|
| 470 | + * @return bool true if the file name is valid, false otherwise |
|
| 471 | + * @deprecated 8.1.0 use \OC\Files\View::verifyPath() |
|
| 472 | + * @since 7.0.0 |
|
| 473 | + * @suppress PhanDeprecatedFunction |
|
| 474 | + */ |
|
| 475 | + public static function isValidFileName($file) { |
|
| 476 | + return \OC_Util::isValidFileName($file); |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + /** |
|
| 480 | + * Compare two strings to provide a natural sort |
|
| 481 | + * @param string $a first string to compare |
|
| 482 | + * @param string $b second string to compare |
|
| 483 | + * @return int -1 if $b comes before $a, 1 if $a comes before $b |
|
| 484 | + * or 0 if the strings are identical |
|
| 485 | + * @since 7.0.0 |
|
| 486 | + */ |
|
| 487 | + public static function naturalSortCompare($a, $b) { |
|
| 488 | + return \OC\NaturalSort::getInstance()->compare($a, $b); |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * check if a password is required for each public link |
|
| 493 | + * @return boolean |
|
| 494 | + * @since 7.0.0 |
|
| 495 | + */ |
|
| 496 | + public static function isPublicLinkPasswordRequired() { |
|
| 497 | + return \OC_Util::isPublicLinkPasswordRequired(); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + /** |
|
| 501 | + * check if share API enforces a default expire date |
|
| 502 | + * @return boolean |
|
| 503 | + * @since 8.0.0 |
|
| 504 | + */ |
|
| 505 | + public static function isDefaultExpireDateEnforced() { |
|
| 506 | + return \OC_Util::isDefaultExpireDateEnforced(); |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + protected static $needUpgradeCache = null; |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * Checks whether the current version needs upgrade. |
|
| 513 | + * |
|
| 514 | + * @return bool true if upgrade is needed, false otherwise |
|
| 515 | + * @since 7.0.0 |
|
| 516 | + */ |
|
| 517 | + public static function needUpgrade() { |
|
| 518 | + if (!isset(self::$needUpgradeCache)) { |
|
| 519 | + self::$needUpgradeCache = \OC_Util::needUpgrade(\OC::$server->getSystemConfig()); |
|
| 520 | + } |
|
| 521 | + return self::$needUpgradeCache; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + /** |
|
| 525 | + * is this Internet explorer ? |
|
| 526 | + * |
|
| 527 | + * @return boolean |
|
| 528 | + * @since 14.0.0 |
|
| 529 | + */ |
|
| 530 | + public static function isIe() { |
|
| 531 | + return \OC_Util::isIe(); |
|
| 532 | + } |
|
| 533 | 533 | } |
@@ -28,39 +28,39 @@ |
||
| 28 | 28 | * @since 8.2.0 |
| 29 | 29 | */ |
| 30 | 30 | interface ICompositeExpression { |
| 31 | - /** |
|
| 32 | - * Adds multiple parts to composite expression. |
|
| 33 | - * |
|
| 34 | - * @param array $parts |
|
| 35 | - * |
|
| 36 | - * @return ICompositeExpression |
|
| 37 | - * @since 8.2.0 |
|
| 38 | - */ |
|
| 39 | - public function addMultiple(array $parts = []); |
|
| 31 | + /** |
|
| 32 | + * Adds multiple parts to composite expression. |
|
| 33 | + * |
|
| 34 | + * @param array $parts |
|
| 35 | + * |
|
| 36 | + * @return ICompositeExpression |
|
| 37 | + * @since 8.2.0 |
|
| 38 | + */ |
|
| 39 | + public function addMultiple(array $parts = []); |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Adds an expression to composite expression. |
|
| 43 | - * |
|
| 44 | - * @param mixed $part |
|
| 45 | - * |
|
| 46 | - * @return ICompositeExpression |
|
| 47 | - * @since 8.2.0 |
|
| 48 | - */ |
|
| 49 | - public function add($part); |
|
| 41 | + /** |
|
| 42 | + * Adds an expression to composite expression. |
|
| 43 | + * |
|
| 44 | + * @param mixed $part |
|
| 45 | + * |
|
| 46 | + * @return ICompositeExpression |
|
| 47 | + * @since 8.2.0 |
|
| 48 | + */ |
|
| 49 | + public function add($part); |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Retrieves the amount of expressions on composite expression. |
|
| 53 | - * |
|
| 54 | - * @return integer |
|
| 55 | - * @since 8.2.0 |
|
| 56 | - */ |
|
| 57 | - public function count(); |
|
| 51 | + /** |
|
| 52 | + * Retrieves the amount of expressions on composite expression. |
|
| 53 | + * |
|
| 54 | + * @return integer |
|
| 55 | + * @since 8.2.0 |
|
| 56 | + */ |
|
| 57 | + public function count(); |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Returns the type of this composite expression (AND/OR). |
|
| 61 | - * |
|
| 62 | - * @return string |
|
| 63 | - * @since 8.2.0 |
|
| 64 | - */ |
|
| 65 | - public function getType(); |
|
| 59 | + /** |
|
| 60 | + * Returns the type of this composite expression (AND/OR). |
|
| 61 | + * |
|
| 62 | + * @return string |
|
| 63 | + * @since 8.2.0 |
|
| 64 | + */ |
|
| 65 | + public function getType(); |
|
| 66 | 66 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | // default responders |
| 80 | 80 | $this->responders = [ |
| 81 | - 'json' => function ($data) { |
|
| 81 | + 'json' => function($data) { |
|
| 82 | 82 | if ($data instanceof DataResponse) { |
| 83 | 83 | $response = new JSONResponse( |
| 84 | 84 | $data->getData(), |
@@ -153,6 +153,6 @@ discard block |
||
| 153 | 153 | return $responder($response); |
| 154 | 154 | } |
| 155 | 155 | throw new \DomainException('No responder registered for format '. |
| 156 | - $format . '!'); |
|
| 156 | + $format.'!'); |
|
| 157 | 157 | } |
| 158 | 158 | } |
@@ -45,122 +45,122 @@ |
||
| 45 | 45 | */ |
| 46 | 46 | abstract class Controller { |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * app name |
|
| 50 | - * @var string |
|
| 51 | - * @since 7.0.0 |
|
| 52 | - */ |
|
| 53 | - protected $appName; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * current request |
|
| 57 | - * @var \OCP\IRequest |
|
| 58 | - * @since 6.0.0 |
|
| 59 | - */ |
|
| 60 | - protected $request; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @var array |
|
| 64 | - * @since 7.0.0 |
|
| 65 | - */ |
|
| 66 | - private $responders; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * constructor of the controller |
|
| 70 | - * @param string $appName the name of the app |
|
| 71 | - * @param IRequest $request an instance of the request |
|
| 72 | - * @since 6.0.0 - parameter $appName was added in 7.0.0 - parameter $app was removed in 7.0.0 |
|
| 73 | - */ |
|
| 74 | - public function __construct($appName, |
|
| 75 | - IRequest $request) { |
|
| 76 | - $this->appName = $appName; |
|
| 77 | - $this->request = $request; |
|
| 78 | - |
|
| 79 | - // default responders |
|
| 80 | - $this->responders = [ |
|
| 81 | - 'json' => function ($data) { |
|
| 82 | - if ($data instanceof DataResponse) { |
|
| 83 | - $response = new JSONResponse( |
|
| 84 | - $data->getData(), |
|
| 85 | - $data->getStatus() |
|
| 86 | - ); |
|
| 87 | - $dataHeaders = $data->getHeaders(); |
|
| 88 | - $headers = $response->getHeaders(); |
|
| 89 | - // do not overwrite Content-Type if it already exists |
|
| 90 | - if (isset($dataHeaders['Content-Type'])) { |
|
| 91 | - unset($headers['Content-Type']); |
|
| 92 | - } |
|
| 93 | - $response->setHeaders(array_merge($dataHeaders, $headers)); |
|
| 94 | - |
|
| 95 | - if ($data->getETag() !== null) { |
|
| 96 | - $response->setETag($data->getETag()); |
|
| 97 | - } |
|
| 98 | - if ($data->getLastModified() !== null) { |
|
| 99 | - $response->setLastModified($data->getLastModified()); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - return $response; |
|
| 103 | - } |
|
| 104 | - return new JSONResponse($data); |
|
| 105 | - } |
|
| 106 | - ]; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Parses an HTTP accept header and returns the supported responder type |
|
| 112 | - * @param string $acceptHeader |
|
| 113 | - * @param string $default |
|
| 114 | - * @return string the responder type |
|
| 115 | - * @since 7.0.0 |
|
| 116 | - * @since 9.1.0 Added default parameter |
|
| 117 | - */ |
|
| 118 | - public function getResponderByHTTPHeader($acceptHeader, $default = 'json') { |
|
| 119 | - $headers = explode(',', $acceptHeader); |
|
| 120 | - |
|
| 121 | - // return the first matching responder |
|
| 122 | - foreach ($headers as $header) { |
|
| 123 | - $header = strtolower(trim($header)); |
|
| 124 | - |
|
| 125 | - $responder = str_replace('application/', '', $header); |
|
| 126 | - |
|
| 127 | - if (array_key_exists($responder, $this->responders)) { |
|
| 128 | - return $responder; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - // no matching header return default |
|
| 133 | - return $default; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Registers a formatter for a type |
|
| 139 | - * @param string $format |
|
| 140 | - * @param \Closure $responder |
|
| 141 | - * @since 7.0.0 |
|
| 142 | - */ |
|
| 143 | - protected function registerResponder($format, \Closure $responder) { |
|
| 144 | - $this->responders[$format] = $responder; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Serializes and formats a response |
|
| 150 | - * @param mixed $response the value that was returned from a controller and |
|
| 151 | - * is not a Response instance |
|
| 152 | - * @param string $format the format for which a formatter has been registered |
|
| 153 | - * @throws \DomainException if format does not match a registered formatter |
|
| 154 | - * @return Response |
|
| 155 | - * @since 7.0.0 |
|
| 156 | - */ |
|
| 157 | - public function buildResponse($response, $format = 'json') { |
|
| 158 | - if (array_key_exists($format, $this->responders)) { |
|
| 159 | - $responder = $this->responders[$format]; |
|
| 160 | - |
|
| 161 | - return $responder($response); |
|
| 162 | - } |
|
| 163 | - throw new \DomainException('No responder registered for format '. |
|
| 164 | - $format . '!'); |
|
| 165 | - } |
|
| 48 | + /** |
|
| 49 | + * app name |
|
| 50 | + * @var string |
|
| 51 | + * @since 7.0.0 |
|
| 52 | + */ |
|
| 53 | + protected $appName; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * current request |
|
| 57 | + * @var \OCP\IRequest |
|
| 58 | + * @since 6.0.0 |
|
| 59 | + */ |
|
| 60 | + protected $request; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @var array |
|
| 64 | + * @since 7.0.0 |
|
| 65 | + */ |
|
| 66 | + private $responders; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * constructor of the controller |
|
| 70 | + * @param string $appName the name of the app |
|
| 71 | + * @param IRequest $request an instance of the request |
|
| 72 | + * @since 6.0.0 - parameter $appName was added in 7.0.0 - parameter $app was removed in 7.0.0 |
|
| 73 | + */ |
|
| 74 | + public function __construct($appName, |
|
| 75 | + IRequest $request) { |
|
| 76 | + $this->appName = $appName; |
|
| 77 | + $this->request = $request; |
|
| 78 | + |
|
| 79 | + // default responders |
|
| 80 | + $this->responders = [ |
|
| 81 | + 'json' => function ($data) { |
|
| 82 | + if ($data instanceof DataResponse) { |
|
| 83 | + $response = new JSONResponse( |
|
| 84 | + $data->getData(), |
|
| 85 | + $data->getStatus() |
|
| 86 | + ); |
|
| 87 | + $dataHeaders = $data->getHeaders(); |
|
| 88 | + $headers = $response->getHeaders(); |
|
| 89 | + // do not overwrite Content-Type if it already exists |
|
| 90 | + if (isset($dataHeaders['Content-Type'])) { |
|
| 91 | + unset($headers['Content-Type']); |
|
| 92 | + } |
|
| 93 | + $response->setHeaders(array_merge($dataHeaders, $headers)); |
|
| 94 | + |
|
| 95 | + if ($data->getETag() !== null) { |
|
| 96 | + $response->setETag($data->getETag()); |
|
| 97 | + } |
|
| 98 | + if ($data->getLastModified() !== null) { |
|
| 99 | + $response->setLastModified($data->getLastModified()); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + return $response; |
|
| 103 | + } |
|
| 104 | + return new JSONResponse($data); |
|
| 105 | + } |
|
| 106 | + ]; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Parses an HTTP accept header and returns the supported responder type |
|
| 112 | + * @param string $acceptHeader |
|
| 113 | + * @param string $default |
|
| 114 | + * @return string the responder type |
|
| 115 | + * @since 7.0.0 |
|
| 116 | + * @since 9.1.0 Added default parameter |
|
| 117 | + */ |
|
| 118 | + public function getResponderByHTTPHeader($acceptHeader, $default = 'json') { |
|
| 119 | + $headers = explode(',', $acceptHeader); |
|
| 120 | + |
|
| 121 | + // return the first matching responder |
|
| 122 | + foreach ($headers as $header) { |
|
| 123 | + $header = strtolower(trim($header)); |
|
| 124 | + |
|
| 125 | + $responder = str_replace('application/', '', $header); |
|
| 126 | + |
|
| 127 | + if (array_key_exists($responder, $this->responders)) { |
|
| 128 | + return $responder; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + // no matching header return default |
|
| 133 | + return $default; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Registers a formatter for a type |
|
| 139 | + * @param string $format |
|
| 140 | + * @param \Closure $responder |
|
| 141 | + * @since 7.0.0 |
|
| 142 | + */ |
|
| 143 | + protected function registerResponder($format, \Closure $responder) { |
|
| 144 | + $this->responders[$format] = $responder; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Serializes and formats a response |
|
| 150 | + * @param mixed $response the value that was returned from a controller and |
|
| 151 | + * is not a Response instance |
|
| 152 | + * @param string $format the format for which a formatter has been registered |
|
| 153 | + * @throws \DomainException if format does not match a registered formatter |
|
| 154 | + * @return Response |
|
| 155 | + * @since 7.0.0 |
|
| 156 | + */ |
|
| 157 | + public function buildResponse($response, $format = 'json') { |
|
| 158 | + if (array_key_exists($format, $this->responders)) { |
|
| 159 | + $responder = $this->responders[$format]; |
|
| 160 | + |
|
| 161 | + return $responder($response); |
|
| 162 | + } |
|
| 163 | + throw new \DomainException('No responder registered for format '. |
|
| 164 | + $format . '!'); |
|
| 165 | + } |
|
| 166 | 166 | } |
@@ -42,67 +42,67 @@ |
||
| 42 | 42 | abstract class Middleware { |
| 43 | 43 | |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * This is being run in normal order before the controller is being |
|
| 47 | - * called which allows several modifications and checks |
|
| 48 | - * |
|
| 49 | - * @param Controller $controller the controller that is being called |
|
| 50 | - * @param string $methodName the name of the method that will be called on |
|
| 51 | - * the controller |
|
| 52 | - * @since 6.0.0 |
|
| 53 | - */ |
|
| 54 | - public function beforeController($controller, $methodName) { |
|
| 55 | - } |
|
| 45 | + /** |
|
| 46 | + * This is being run in normal order before the controller is being |
|
| 47 | + * called which allows several modifications and checks |
|
| 48 | + * |
|
| 49 | + * @param Controller $controller the controller that is being called |
|
| 50 | + * @param string $methodName the name of the method that will be called on |
|
| 51 | + * the controller |
|
| 52 | + * @since 6.0.0 |
|
| 53 | + */ |
|
| 54 | + public function beforeController($controller, $methodName) { |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * This is being run when either the beforeController method or the |
|
| 60 | - * controller method itself is throwing an exception. The middleware is |
|
| 61 | - * asked in reverse order to handle the exception and to return a response. |
|
| 62 | - * If the response is null, it is assumed that the exception could not be |
|
| 63 | - * handled and the error will be thrown again |
|
| 64 | - * |
|
| 65 | - * @param Controller $controller the controller that is being called |
|
| 66 | - * @param string $methodName the name of the method that will be called on |
|
| 67 | - * the controller |
|
| 68 | - * @param \Exception $exception the thrown exception |
|
| 69 | - * @throws \Exception the passed in exception if it can't handle it |
|
| 70 | - * @return Response a Response object in case that the exception was handled |
|
| 71 | - * @since 6.0.0 |
|
| 72 | - */ |
|
| 73 | - public function afterException($controller, $methodName, \Exception $exception) { |
|
| 74 | - throw $exception; |
|
| 75 | - } |
|
| 58 | + /** |
|
| 59 | + * This is being run when either the beforeController method or the |
|
| 60 | + * controller method itself is throwing an exception. The middleware is |
|
| 61 | + * asked in reverse order to handle the exception and to return a response. |
|
| 62 | + * If the response is null, it is assumed that the exception could not be |
|
| 63 | + * handled and the error will be thrown again |
|
| 64 | + * |
|
| 65 | + * @param Controller $controller the controller that is being called |
|
| 66 | + * @param string $methodName the name of the method that will be called on |
|
| 67 | + * the controller |
|
| 68 | + * @param \Exception $exception the thrown exception |
|
| 69 | + * @throws \Exception the passed in exception if it can't handle it |
|
| 70 | + * @return Response a Response object in case that the exception was handled |
|
| 71 | + * @since 6.0.0 |
|
| 72 | + */ |
|
| 73 | + public function afterException($controller, $methodName, \Exception $exception) { |
|
| 74 | + throw $exception; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * This is being run after a successful controllermethod call and allows |
|
| 80 | - * the manipulation of a Response object. The middleware is run in reverse order |
|
| 81 | - * |
|
| 82 | - * @param Controller $controller the controller that is being called |
|
| 83 | - * @param string $methodName the name of the method that will be called on |
|
| 84 | - * the controller |
|
| 85 | - * @param Response $response the generated response from the controller |
|
| 86 | - * @return Response a Response object |
|
| 87 | - * @since 6.0.0 |
|
| 88 | - */ |
|
| 89 | - public function afterController($controller, $methodName, Response $response) { |
|
| 90 | - return $response; |
|
| 91 | - } |
|
| 78 | + /** |
|
| 79 | + * This is being run after a successful controllermethod call and allows |
|
| 80 | + * the manipulation of a Response object. The middleware is run in reverse order |
|
| 81 | + * |
|
| 82 | + * @param Controller $controller the controller that is being called |
|
| 83 | + * @param string $methodName the name of the method that will be called on |
|
| 84 | + * the controller |
|
| 85 | + * @param Response $response the generated response from the controller |
|
| 86 | + * @return Response a Response object |
|
| 87 | + * @since 6.0.0 |
|
| 88 | + */ |
|
| 89 | + public function afterController($controller, $methodName, Response $response) { |
|
| 90 | + return $response; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * This is being run after the response object has been rendered and |
|
| 96 | - * allows the manipulation of the output. The middleware is run in reverse order |
|
| 97 | - * |
|
| 98 | - * @param Controller $controller the controller that is being called |
|
| 99 | - * @param string $methodName the name of the method that will be called on |
|
| 100 | - * the controller |
|
| 101 | - * @param string $output the generated output from a response |
|
| 102 | - * @return string the output that should be printed |
|
| 103 | - * @since 6.0.0 |
|
| 104 | - */ |
|
| 105 | - public function beforeOutput($controller, $methodName, $output) { |
|
| 106 | - return $output; |
|
| 107 | - } |
|
| 94 | + /** |
|
| 95 | + * This is being run after the response object has been rendered and |
|
| 96 | + * allows the manipulation of the output. The middleware is run in reverse order |
|
| 97 | + * |
|
| 98 | + * @param Controller $controller the controller that is being called |
|
| 99 | + * @param string $methodName the name of the method that will be called on |
|
| 100 | + * the controller |
|
| 101 | + * @param string $output the generated output from a response |
|
| 102 | + * @return string the output that should be printed |
|
| 103 | + * @since 6.0.0 |
|
| 104 | + */ |
|
| 105 | + public function beforeOutput($controller, $methodName, $output) { |
|
| 106 | + return $output; |
|
| 107 | + } |
|
| 108 | 108 | } |
@@ -32,14 +32,14 @@ |
||
| 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 | } |
@@ -32,14 +32,14 @@ |
||
| 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 | } |