@@ -28,41 +28,41 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | trait LegacyDependencyCheckPolyfill { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @return class-string<IStorage> |
|
| 33 | - */ |
|
| 34 | - abstract public function getStorageClass(); |
|
| 31 | + /** |
|
| 32 | + * @return class-string<IStorage> |
|
| 33 | + */ |
|
| 34 | + abstract public function getStorageClass(); |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Check if object is valid for use |
|
| 38 | - * |
|
| 39 | - * @return MissingDependency[] Unsatisfied dependencies |
|
| 40 | - */ |
|
| 41 | - public function checkDependencies() { |
|
| 42 | - $ret = []; |
|
| 36 | + /** |
|
| 37 | + * Check if object is valid for use |
|
| 38 | + * |
|
| 39 | + * @return MissingDependency[] Unsatisfied dependencies |
|
| 40 | + */ |
|
| 41 | + public function checkDependencies() { |
|
| 42 | + $ret = []; |
|
| 43 | 43 | |
| 44 | - $result = call_user_func([$this->getStorageClass(), 'checkDependencies']); |
|
| 45 | - if ($result !== true) { |
|
| 46 | - if (!is_array($result)) { |
|
| 47 | - $result = [$result]; |
|
| 48 | - } |
|
| 49 | - foreach ($result as $key => $value) { |
|
| 50 | - if (!($value instanceof MissingDependency)) { |
|
| 51 | - $module = null; |
|
| 52 | - $message = null; |
|
| 53 | - if (is_numeric($key)) { |
|
| 54 | - $module = $value; |
|
| 55 | - } else { |
|
| 56 | - $module = $key; |
|
| 57 | - $message = $value; |
|
| 58 | - } |
|
| 59 | - $value = new MissingDependency($module); |
|
| 60 | - $value->setMessage($message); |
|
| 61 | - } |
|
| 62 | - $ret[] = $value; |
|
| 63 | - } |
|
| 64 | - } |
|
| 44 | + $result = call_user_func([$this->getStorageClass(), 'checkDependencies']); |
|
| 45 | + if ($result !== true) { |
|
| 46 | + if (!is_array($result)) { |
|
| 47 | + $result = [$result]; |
|
| 48 | + } |
|
| 49 | + foreach ($result as $key => $value) { |
|
| 50 | + if (!($value instanceof MissingDependency)) { |
|
| 51 | + $module = null; |
|
| 52 | + $message = null; |
|
| 53 | + if (is_numeric($key)) { |
|
| 54 | + $module = $value; |
|
| 55 | + } else { |
|
| 56 | + $module = $key; |
|
| 57 | + $message = $value; |
|
| 58 | + } |
|
| 59 | + $value = new MissingDependency($module); |
|
| 60 | + $value->setMessage($message); |
|
| 61 | + } |
|
| 62 | + $ret[] = $value; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - return $ret; |
|
| 67 | - } |
|
| 66 | + return $ret; |
|
| 67 | + } |
|
| 68 | 68 | } |
@@ -21,36 +21,36 @@ |
||
| 21 | 21 | |
| 22 | 22 | interface IFrontendDefinition { |
| 23 | 23 | |
| 24 | - public function getText(): string; |
|
| 24 | + public function getText(): string; |
|
| 25 | 25 | |
| 26 | - public function setText(string $text): self; |
|
| 26 | + public function setText(string $text): self; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @return array<string, DefinitionParameter> |
|
| 30 | - */ |
|
| 31 | - public function getParameters(): array; |
|
| 28 | + /** |
|
| 29 | + * @return array<string, DefinitionParameter> |
|
| 30 | + */ |
|
| 31 | + public function getParameters(): array; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param list<DefinitionParameter> $parameters |
|
| 35 | - */ |
|
| 36 | - public function addParameters(array $parameters): self; |
|
| 33 | + /** |
|
| 34 | + * @param list<DefinitionParameter> $parameters |
|
| 35 | + */ |
|
| 36 | + public function addParameters(array $parameters): self; |
|
| 37 | 37 | |
| 38 | - public function addParameter(DefinitionParameter $parameter): self; |
|
| 38 | + public function addParameter(DefinitionParameter $parameter): self; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @return string[] |
|
| 42 | - */ |
|
| 43 | - public function getCustomJs(): array; |
|
| 40 | + /** |
|
| 41 | + * @return string[] |
|
| 42 | + */ |
|
| 43 | + public function getCustomJs(): array; |
|
| 44 | 44 | |
| 45 | - public function addCustomJs(string $custom): self; |
|
| 45 | + public function addCustomJs(string $custom): self; |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Serialize into JSON for client-side JS |
|
| 49 | - */ |
|
| 50 | - public function jsonSerializeDefinition(): array; |
|
| 47 | + /** |
|
| 48 | + * Serialize into JSON for client-side JS |
|
| 49 | + */ |
|
| 50 | + public function jsonSerializeDefinition(): array; |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Check if parameters are satisfied in a StorageConfig |
|
| 54 | - */ |
|
| 55 | - public function validateStorageDefinition(StorageConfig $storage): bool; |
|
| 52 | + /** |
|
| 53 | + * Check if parameters are satisfied in a StorageConfig |
|
| 54 | + */ |
|
| 55 | + public function validateStorageDefinition(StorageConfig $storage): bool; |
|
| 56 | 56 | } |
@@ -59,102 +59,102 @@ |
||
| 59 | 59 | * Object can affect storage mounting |
| 60 | 60 | */ |
| 61 | 61 | class Backend implements \JsonSerializable, IIdentifier, IFrontendDefinition { |
| 62 | - use VisibilityTrait; |
|
| 63 | - use FrontendDefinitionTrait; |
|
| 64 | - use PriorityTrait; |
|
| 65 | - use DependencyTrait; |
|
| 66 | - use StorageModifierTrait; |
|
| 67 | - use IdentifierTrait; |
|
| 68 | - |
|
| 69 | - /** @var string storage class */ |
|
| 70 | - private $storageClass; |
|
| 71 | - |
|
| 72 | - /** @var array 'scheme' => true, supported authentication schemes */ |
|
| 73 | - private $authSchemes = []; |
|
| 74 | - |
|
| 75 | - /** @var AuthMechanism|callable authentication mechanism fallback */ |
|
| 76 | - private $legacyAuthMechanism; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * @return class-string<IStorage> |
|
| 80 | - */ |
|
| 81 | - public function getStorageClass() { |
|
| 82 | - return $this->storageClass; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @param string $class |
|
| 87 | - * @return $this |
|
| 88 | - */ |
|
| 89 | - public function setStorageClass($class) { |
|
| 90 | - $this->storageClass = $class; |
|
| 91 | - return $this; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @return array |
|
| 96 | - */ |
|
| 97 | - public function getAuthSchemes() { |
|
| 98 | - if (empty($this->authSchemes)) { |
|
| 99 | - return [AuthMechanism::SCHEME_NULL => true]; |
|
| 100 | - } |
|
| 101 | - return $this->authSchemes; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @param string $scheme |
|
| 106 | - * @return self |
|
| 107 | - */ |
|
| 108 | - public function addAuthScheme($scheme) { |
|
| 109 | - $this->authSchemes[$scheme] = true; |
|
| 110 | - return $this; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @param array $parameters storage parameters, for dynamic mechanism selection |
|
| 115 | - * @return AuthMechanism |
|
| 116 | - */ |
|
| 117 | - public function getLegacyAuthMechanism(array $parameters = []) { |
|
| 118 | - if (is_callable($this->legacyAuthMechanism)) { |
|
| 119 | - return call_user_func($this->legacyAuthMechanism, $parameters); |
|
| 120 | - } |
|
| 121 | - return $this->legacyAuthMechanism; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - public function setLegacyAuthMechanism(AuthMechanism $authMechanism): self { |
|
| 125 | - $this->legacyAuthMechanism = $authMechanism; |
|
| 126 | - return $this; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @param callable $callback dynamic auth mechanism selection |
|
| 131 | - */ |
|
| 132 | - public function setLegacyAuthMechanismCallback(callable $callback): self { |
|
| 133 | - $this->legacyAuthMechanism = $callback; |
|
| 134 | - return $this; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Serialize into JSON for client-side JS |
|
| 139 | - */ |
|
| 140 | - public function jsonSerialize(): array { |
|
| 141 | - $data = $this->jsonSerializeDefinition(); |
|
| 142 | - $data += $this->jsonSerializeIdentifier(); |
|
| 143 | - |
|
| 144 | - $data['backend'] = $data['name']; // legacy compat |
|
| 145 | - $data['priority'] = $this->getPriority(); |
|
| 146 | - $data['authSchemes'] = $this->getAuthSchemes(); |
|
| 147 | - |
|
| 148 | - return $data; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Check if parameters are satisfied in a StorageConfig |
|
| 153 | - * |
|
| 154 | - * @param StorageConfig $storage |
|
| 155 | - * @return bool |
|
| 156 | - */ |
|
| 157 | - public function validateStorage(StorageConfig $storage) { |
|
| 158 | - return $this->validateStorageDefinition($storage); |
|
| 159 | - } |
|
| 62 | + use VisibilityTrait; |
|
| 63 | + use FrontendDefinitionTrait; |
|
| 64 | + use PriorityTrait; |
|
| 65 | + use DependencyTrait; |
|
| 66 | + use StorageModifierTrait; |
|
| 67 | + use IdentifierTrait; |
|
| 68 | + |
|
| 69 | + /** @var string storage class */ |
|
| 70 | + private $storageClass; |
|
| 71 | + |
|
| 72 | + /** @var array 'scheme' => true, supported authentication schemes */ |
|
| 73 | + private $authSchemes = []; |
|
| 74 | + |
|
| 75 | + /** @var AuthMechanism|callable authentication mechanism fallback */ |
|
| 76 | + private $legacyAuthMechanism; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * @return class-string<IStorage> |
|
| 80 | + */ |
|
| 81 | + public function getStorageClass() { |
|
| 82 | + return $this->storageClass; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @param string $class |
|
| 87 | + * @return $this |
|
| 88 | + */ |
|
| 89 | + public function setStorageClass($class) { |
|
| 90 | + $this->storageClass = $class; |
|
| 91 | + return $this; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @return array |
|
| 96 | + */ |
|
| 97 | + public function getAuthSchemes() { |
|
| 98 | + if (empty($this->authSchemes)) { |
|
| 99 | + return [AuthMechanism::SCHEME_NULL => true]; |
|
| 100 | + } |
|
| 101 | + return $this->authSchemes; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @param string $scheme |
|
| 106 | + * @return self |
|
| 107 | + */ |
|
| 108 | + public function addAuthScheme($scheme) { |
|
| 109 | + $this->authSchemes[$scheme] = true; |
|
| 110 | + return $this; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @param array $parameters storage parameters, for dynamic mechanism selection |
|
| 115 | + * @return AuthMechanism |
|
| 116 | + */ |
|
| 117 | + public function getLegacyAuthMechanism(array $parameters = []) { |
|
| 118 | + if (is_callable($this->legacyAuthMechanism)) { |
|
| 119 | + return call_user_func($this->legacyAuthMechanism, $parameters); |
|
| 120 | + } |
|
| 121 | + return $this->legacyAuthMechanism; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + public function setLegacyAuthMechanism(AuthMechanism $authMechanism): self { |
|
| 125 | + $this->legacyAuthMechanism = $authMechanism; |
|
| 126 | + return $this; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @param callable $callback dynamic auth mechanism selection |
|
| 131 | + */ |
|
| 132 | + public function setLegacyAuthMechanismCallback(callable $callback): self { |
|
| 133 | + $this->legacyAuthMechanism = $callback; |
|
| 134 | + return $this; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Serialize into JSON for client-side JS |
|
| 139 | + */ |
|
| 140 | + public function jsonSerialize(): array { |
|
| 141 | + $data = $this->jsonSerializeDefinition(); |
|
| 142 | + $data += $this->jsonSerializeIdentifier(); |
|
| 143 | + |
|
| 144 | + $data['backend'] = $data['name']; // legacy compat |
|
| 145 | + $data['priority'] = $this->getPriority(); |
|
| 146 | + $data['authSchemes'] = $this->getAuthSchemes(); |
|
| 147 | + |
|
| 148 | + return $data; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Check if parameters are satisfied in a StorageConfig |
|
| 153 | + * |
|
| 154 | + * @param StorageConfig $storage |
|
| 155 | + * @return bool |
|
| 156 | + */ |
|
| 157 | + public function validateStorage(StorageConfig $storage) { |
|
| 158 | + return $this->validateStorageDefinition($storage); |
|
| 159 | + } |
|
| 160 | 160 | } |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | |
| 22 | 22 | interface IIdentifier { |
| 23 | 23 | |
| 24 | - public function getIdentifier(): string; |
|
| 24 | + public function getIdentifier(): string; |
|
| 25 | 25 | |
| 26 | - public function setIdentifier(string $identifier): self; |
|
| 26 | + public function setIdentifier(string $identifier): self; |
|
| 27 | 27 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | $mounts = $this->globalService->getStorageForAllUsers(); |
| 88 | 88 | $userId = self::ALL; |
| 89 | 89 | } else { |
| 90 | - $userId = (string)$input->getArgument('user_id'); |
|
| 90 | + $userId = (string) $input->getArgument('user_id'); |
|
| 91 | 91 | $storageService = $this->getStorageService($userId); |
| 92 | 92 | $mounts = $storageService->getAllStorages(); |
| 93 | 93 | } |
@@ -140,11 +140,11 @@ discard block |
||
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { |
| 143 | - $keys = array_map(function ($header) { |
|
| 143 | + $keys = array_map(function($header) { |
|
| 144 | 144 | return strtolower(str_replace(' ', '_', $header)); |
| 145 | 145 | }, $headers); |
| 146 | 146 | |
| 147 | - $pairs = array_map(function (StorageConfig $config) use ($keys, $userId) { |
|
| 147 | + $pairs = array_map(function(StorageConfig $config) use ($keys, $userId) { |
|
| 148 | 148 | $values = [ |
| 149 | 149 | $config->getId(), |
| 150 | 150 | $config->getMountPoint(), |
@@ -178,23 +178,23 @@ discard block |
||
| 178 | 178 | 'encoding_compatibility' => false, |
| 179 | 179 | 'readonly' => false, |
| 180 | 180 | ]; |
| 181 | - $rows = array_map(function (StorageConfig $config) use ($userId, $defaultMountOptions, $full) { |
|
| 181 | + $rows = array_map(function(StorageConfig $config) use ($userId, $defaultMountOptions, $full) { |
|
| 182 | 182 | $storageConfig = $config->getBackendOptions(); |
| 183 | 183 | $keys = array_keys($storageConfig); |
| 184 | 184 | $values = array_values($storageConfig); |
| 185 | 185 | |
| 186 | 186 | if (!$full) { |
| 187 | - $values = array_map(function ($value) { |
|
| 187 | + $values = array_map(function($value) { |
|
| 188 | 188 | if (is_string($value) && strlen($value) > 32) { |
| 189 | - return substr($value, 0, 6) . '...' . substr($value, -6, 6); |
|
| 189 | + return substr($value, 0, 6).'...'.substr($value, -6, 6); |
|
| 190 | 190 | } else { |
| 191 | 191 | return $value; |
| 192 | 192 | } |
| 193 | 193 | }, $values); |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - $configStrings = array_map(function ($key, $value) { |
|
| 197 | - return $key . ': ' . json_encode($value); |
|
| 196 | + $configStrings = array_map(function($key, $value) { |
|
| 197 | + return $key.': '.json_encode($value); |
|
| 198 | 198 | }, $keys, $values); |
| 199 | 199 | $configString = implode(', ', $configStrings); |
| 200 | 200 | |
@@ -208,8 +208,8 @@ discard block |
||
| 208 | 208 | $keys = array_keys($mountOptions); |
| 209 | 209 | $values = array_values($mountOptions); |
| 210 | 210 | |
| 211 | - $optionsStrings = array_map(function ($key, $value) { |
|
| 212 | - return $key . ': ' . json_encode($value); |
|
| 211 | + $optionsStrings = array_map(function($key, $value) { |
|
| 212 | + return $key.': '.json_encode($value); |
|
| 213 | 213 | }, $keys, $values); |
| 214 | 214 | $optionsString = implode(', ', $optionsStrings); |
| 215 | 215 | |
@@ -21,218 +21,218 @@ |
||
| 21 | 21 | use Symfony\Component\Console\Output\OutputInterface; |
| 22 | 22 | |
| 23 | 23 | class ListCommand extends Base { |
| 24 | - public const ALL = -1; |
|
| 25 | - |
|
| 26 | - public function __construct( |
|
| 27 | - protected GlobalStoragesService $globalService, |
|
| 28 | - protected UserStoragesService $userService, |
|
| 29 | - protected IUserSession $userSession, |
|
| 30 | - protected IUserManager $userManager, |
|
| 31 | - ) { |
|
| 32 | - parent::__construct(); |
|
| 33 | - } |
|
| 34 | - |
|
| 35 | - protected function configure(): void { |
|
| 36 | - $this |
|
| 37 | - ->setName('files_external:list') |
|
| 38 | - ->setDescription('List configured admin or personal mounts') |
|
| 39 | - ->addArgument( |
|
| 40 | - 'user_id', |
|
| 41 | - InputArgument::OPTIONAL, |
|
| 42 | - 'user id to list the personal mounts for, if no user is provided admin mounts will be listed' |
|
| 43 | - )->addOption( |
|
| 44 | - 'show-password', |
|
| 45 | - '', |
|
| 46 | - InputOption::VALUE_NONE, |
|
| 47 | - 'show passwords and secrets' |
|
| 48 | - )->addOption( |
|
| 49 | - 'full', |
|
| 50 | - null, |
|
| 51 | - InputOption::VALUE_NONE, |
|
| 52 | - 'don\'t truncate long values in table output' |
|
| 53 | - )->addOption( |
|
| 54 | - 'all', |
|
| 55 | - 'a', |
|
| 56 | - InputOption::VALUE_NONE, |
|
| 57 | - 'show both system wide mounts and all personal mounts' |
|
| 58 | - ); |
|
| 59 | - parent::configure(); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 63 | - /** @var StorageConfig[] $mounts */ |
|
| 64 | - if ($input->getOption('all')) { |
|
| 65 | - $mounts = $this->globalService->getStorageForAllUsers(); |
|
| 66 | - $userId = self::ALL; |
|
| 67 | - } else { |
|
| 68 | - $userId = (string)$input->getArgument('user_id'); |
|
| 69 | - $storageService = $this->getStorageService($userId); |
|
| 70 | - $mounts = $storageService->getAllStorages(); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - $this->listMounts($userId, $mounts, $input, $output); |
|
| 74 | - return self::SUCCESS; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @param ?string|ListCommand::ALL $userId |
|
| 79 | - * @param StorageConfig[] $mounts |
|
| 80 | - */ |
|
| 81 | - public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output): void { |
|
| 82 | - $outputType = $input->getOption('output'); |
|
| 83 | - if (count($mounts) === 0) { |
|
| 84 | - if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { |
|
| 85 | - $output->writeln('[]'); |
|
| 86 | - } else { |
|
| 87 | - if ($userId === self::ALL) { |
|
| 88 | - $output->writeln('<info>No mounts configured</info>'); |
|
| 89 | - } elseif ($userId) { |
|
| 90 | - $output->writeln("<info>No mounts configured by $userId</info>"); |
|
| 91 | - } else { |
|
| 92 | - $output->writeln('<info>No admin mounts configured</info>'); |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - return; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - $headers = ['Mount ID', 'Mount Point', 'Storage', 'Authentication Type', 'Configuration', 'Options']; |
|
| 99 | - |
|
| 100 | - if (!$userId || $userId === self::ALL) { |
|
| 101 | - $headers[] = 'Applicable Users'; |
|
| 102 | - $headers[] = 'Applicable Groups'; |
|
| 103 | - } |
|
| 104 | - if ($userId === self::ALL) { |
|
| 105 | - $headers[] = 'Type'; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - if (!$input->getOption('show-password')) { |
|
| 109 | - $hideKeys = ['key', 'bucket', 'secret', 'password', 'refresh_token', 'token', 'client_secret', 'public_key', 'private_key']; |
|
| 110 | - foreach ($mounts as $mount) { |
|
| 111 | - $config = $mount->getBackendOptions(); |
|
| 112 | - foreach ($config as $key => $value) { |
|
| 113 | - if (in_array($key, $hideKeys)) { |
|
| 114 | - $mount->setBackendOption($key, '***REMOVED SENSITIVE VALUE***'); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { |
|
| 121 | - $keys = array_map(function ($header) { |
|
| 122 | - return strtolower(str_replace(' ', '_', $header)); |
|
| 123 | - }, $headers); |
|
| 124 | - |
|
| 125 | - $pairs = array_map(function (StorageConfig $config) use ($keys, $userId) { |
|
| 126 | - $values = [ |
|
| 127 | - $config->getId(), |
|
| 128 | - $config->getMountPoint(), |
|
| 129 | - $config->getBackend()->getStorageClass(), |
|
| 130 | - $config->getAuthMechanism()->getIdentifier(), |
|
| 131 | - $config->getBackendOptions(), |
|
| 132 | - $config->getMountOptions() |
|
| 133 | - ]; |
|
| 134 | - if (!$userId || $userId === self::ALL) { |
|
| 135 | - $values[] = $config->getApplicableUsers(); |
|
| 136 | - $values[] = $config->getApplicableGroups(); |
|
| 137 | - } |
|
| 138 | - if ($userId === self::ALL) { |
|
| 139 | - $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'admin' : 'personal'; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return array_combine($keys, $values); |
|
| 143 | - }, $mounts); |
|
| 144 | - if ($outputType === self::OUTPUT_FORMAT_JSON) { |
|
| 145 | - $output->writeln(json_encode(array_values($pairs))); |
|
| 146 | - } else { |
|
| 147 | - $output->writeln(json_encode(array_values($pairs), JSON_PRETTY_PRINT)); |
|
| 148 | - } |
|
| 149 | - } else { |
|
| 150 | - $full = $input->getOption('full'); |
|
| 151 | - $defaultMountOptions = [ |
|
| 152 | - 'encrypt' => true, |
|
| 153 | - 'previews' => true, |
|
| 154 | - 'filesystem_check_changes' => 1, |
|
| 155 | - 'enable_sharing' => false, |
|
| 156 | - 'encoding_compatibility' => false, |
|
| 157 | - 'readonly' => false, |
|
| 158 | - ]; |
|
| 159 | - $rows = array_map(function (StorageConfig $config) use ($userId, $defaultMountOptions, $full) { |
|
| 160 | - $storageConfig = $config->getBackendOptions(); |
|
| 161 | - $keys = array_keys($storageConfig); |
|
| 162 | - $values = array_values($storageConfig); |
|
| 163 | - |
|
| 164 | - if (!$full) { |
|
| 165 | - $values = array_map(function ($value) { |
|
| 166 | - if (is_string($value) && strlen($value) > 32) { |
|
| 167 | - return substr($value, 0, 6) . '...' . substr($value, -6, 6); |
|
| 168 | - } else { |
|
| 169 | - return $value; |
|
| 170 | - } |
|
| 171 | - }, $values); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - $configStrings = array_map(function ($key, $value) { |
|
| 175 | - return $key . ': ' . json_encode($value); |
|
| 176 | - }, $keys, $values); |
|
| 177 | - $configString = implode(', ', $configStrings); |
|
| 178 | - |
|
| 179 | - $mountOptions = $config->getMountOptions(); |
|
| 180 | - // hide defaults |
|
| 181 | - foreach ($mountOptions as $key => $value) { |
|
| 182 | - if ($value === $defaultMountOptions[$key]) { |
|
| 183 | - unset($mountOptions[$key]); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - $keys = array_keys($mountOptions); |
|
| 187 | - $values = array_values($mountOptions); |
|
| 188 | - |
|
| 189 | - $optionsStrings = array_map(function ($key, $value) { |
|
| 190 | - return $key . ': ' . json_encode($value); |
|
| 191 | - }, $keys, $values); |
|
| 192 | - $optionsString = implode(', ', $optionsStrings); |
|
| 193 | - |
|
| 194 | - $values = [ |
|
| 195 | - $config->getId(), |
|
| 196 | - $config->getMountPoint(), |
|
| 197 | - $config->getBackend()->getText(), |
|
| 198 | - $config->getAuthMechanism()->getText(), |
|
| 199 | - $configString, |
|
| 200 | - $optionsString |
|
| 201 | - ]; |
|
| 202 | - |
|
| 203 | - if (!$userId || $userId === self::ALL) { |
|
| 204 | - $applicableUsers = implode(', ', $config->getApplicableUsers()); |
|
| 205 | - $applicableGroups = implode(', ', $config->getApplicableGroups()); |
|
| 206 | - if ($applicableUsers === '' && $applicableGroups === '') { |
|
| 207 | - $applicableUsers = 'All'; |
|
| 208 | - } |
|
| 209 | - $values[] = $applicableUsers; |
|
| 210 | - $values[] = $applicableGroups; |
|
| 211 | - } |
|
| 212 | - if ($userId === self::ALL) { |
|
| 213 | - $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'Admin' : 'Personal'; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - return $values; |
|
| 217 | - }, $mounts); |
|
| 218 | - |
|
| 219 | - $table = new Table($output); |
|
| 220 | - $table->setHeaders($headers); |
|
| 221 | - $table->setRows($rows); |
|
| 222 | - $table->render(); |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - protected function getStorageService(string $userId): StoragesService { |
|
| 227 | - if (empty($userId)) { |
|
| 228 | - return $this->globalService; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - $user = $this->userManager->get($userId); |
|
| 232 | - if (is_null($user)) { |
|
| 233 | - throw new NoUserException("user $userId not found"); |
|
| 234 | - } |
|
| 235 | - $this->userSession->setUser($user); |
|
| 236 | - return $this->userService; |
|
| 237 | - } |
|
| 24 | + public const ALL = -1; |
|
| 25 | + |
|
| 26 | + public function __construct( |
|
| 27 | + protected GlobalStoragesService $globalService, |
|
| 28 | + protected UserStoragesService $userService, |
|
| 29 | + protected IUserSession $userSession, |
|
| 30 | + protected IUserManager $userManager, |
|
| 31 | + ) { |
|
| 32 | + parent::__construct(); |
|
| 33 | + } |
|
| 34 | + |
|
| 35 | + protected function configure(): void { |
|
| 36 | + $this |
|
| 37 | + ->setName('files_external:list') |
|
| 38 | + ->setDescription('List configured admin or personal mounts') |
|
| 39 | + ->addArgument( |
|
| 40 | + 'user_id', |
|
| 41 | + InputArgument::OPTIONAL, |
|
| 42 | + 'user id to list the personal mounts for, if no user is provided admin mounts will be listed' |
|
| 43 | + )->addOption( |
|
| 44 | + 'show-password', |
|
| 45 | + '', |
|
| 46 | + InputOption::VALUE_NONE, |
|
| 47 | + 'show passwords and secrets' |
|
| 48 | + )->addOption( |
|
| 49 | + 'full', |
|
| 50 | + null, |
|
| 51 | + InputOption::VALUE_NONE, |
|
| 52 | + 'don\'t truncate long values in table output' |
|
| 53 | + )->addOption( |
|
| 54 | + 'all', |
|
| 55 | + 'a', |
|
| 56 | + InputOption::VALUE_NONE, |
|
| 57 | + 'show both system wide mounts and all personal mounts' |
|
| 58 | + ); |
|
| 59 | + parent::configure(); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
| 63 | + /** @var StorageConfig[] $mounts */ |
|
| 64 | + if ($input->getOption('all')) { |
|
| 65 | + $mounts = $this->globalService->getStorageForAllUsers(); |
|
| 66 | + $userId = self::ALL; |
|
| 67 | + } else { |
|
| 68 | + $userId = (string)$input->getArgument('user_id'); |
|
| 69 | + $storageService = $this->getStorageService($userId); |
|
| 70 | + $mounts = $storageService->getAllStorages(); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + $this->listMounts($userId, $mounts, $input, $output); |
|
| 74 | + return self::SUCCESS; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @param ?string|ListCommand::ALL $userId |
|
| 79 | + * @param StorageConfig[] $mounts |
|
| 80 | + */ |
|
| 81 | + public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output): void { |
|
| 82 | + $outputType = $input->getOption('output'); |
|
| 83 | + if (count($mounts) === 0) { |
|
| 84 | + if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { |
|
| 85 | + $output->writeln('[]'); |
|
| 86 | + } else { |
|
| 87 | + if ($userId === self::ALL) { |
|
| 88 | + $output->writeln('<info>No mounts configured</info>'); |
|
| 89 | + } elseif ($userId) { |
|
| 90 | + $output->writeln("<info>No mounts configured by $userId</info>"); |
|
| 91 | + } else { |
|
| 92 | + $output->writeln('<info>No admin mounts configured</info>'); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + return; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + $headers = ['Mount ID', 'Mount Point', 'Storage', 'Authentication Type', 'Configuration', 'Options']; |
|
| 99 | + |
|
| 100 | + if (!$userId || $userId === self::ALL) { |
|
| 101 | + $headers[] = 'Applicable Users'; |
|
| 102 | + $headers[] = 'Applicable Groups'; |
|
| 103 | + } |
|
| 104 | + if ($userId === self::ALL) { |
|
| 105 | + $headers[] = 'Type'; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + if (!$input->getOption('show-password')) { |
|
| 109 | + $hideKeys = ['key', 'bucket', 'secret', 'password', 'refresh_token', 'token', 'client_secret', 'public_key', 'private_key']; |
|
| 110 | + foreach ($mounts as $mount) { |
|
| 111 | + $config = $mount->getBackendOptions(); |
|
| 112 | + foreach ($config as $key => $value) { |
|
| 113 | + if (in_array($key, $hideKeys)) { |
|
| 114 | + $mount->setBackendOption($key, '***REMOVED SENSITIVE VALUE***'); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) { |
|
| 121 | + $keys = array_map(function ($header) { |
|
| 122 | + return strtolower(str_replace(' ', '_', $header)); |
|
| 123 | + }, $headers); |
|
| 124 | + |
|
| 125 | + $pairs = array_map(function (StorageConfig $config) use ($keys, $userId) { |
|
| 126 | + $values = [ |
|
| 127 | + $config->getId(), |
|
| 128 | + $config->getMountPoint(), |
|
| 129 | + $config->getBackend()->getStorageClass(), |
|
| 130 | + $config->getAuthMechanism()->getIdentifier(), |
|
| 131 | + $config->getBackendOptions(), |
|
| 132 | + $config->getMountOptions() |
|
| 133 | + ]; |
|
| 134 | + if (!$userId || $userId === self::ALL) { |
|
| 135 | + $values[] = $config->getApplicableUsers(); |
|
| 136 | + $values[] = $config->getApplicableGroups(); |
|
| 137 | + } |
|
| 138 | + if ($userId === self::ALL) { |
|
| 139 | + $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'admin' : 'personal'; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return array_combine($keys, $values); |
|
| 143 | + }, $mounts); |
|
| 144 | + if ($outputType === self::OUTPUT_FORMAT_JSON) { |
|
| 145 | + $output->writeln(json_encode(array_values($pairs))); |
|
| 146 | + } else { |
|
| 147 | + $output->writeln(json_encode(array_values($pairs), JSON_PRETTY_PRINT)); |
|
| 148 | + } |
|
| 149 | + } else { |
|
| 150 | + $full = $input->getOption('full'); |
|
| 151 | + $defaultMountOptions = [ |
|
| 152 | + 'encrypt' => true, |
|
| 153 | + 'previews' => true, |
|
| 154 | + 'filesystem_check_changes' => 1, |
|
| 155 | + 'enable_sharing' => false, |
|
| 156 | + 'encoding_compatibility' => false, |
|
| 157 | + 'readonly' => false, |
|
| 158 | + ]; |
|
| 159 | + $rows = array_map(function (StorageConfig $config) use ($userId, $defaultMountOptions, $full) { |
|
| 160 | + $storageConfig = $config->getBackendOptions(); |
|
| 161 | + $keys = array_keys($storageConfig); |
|
| 162 | + $values = array_values($storageConfig); |
|
| 163 | + |
|
| 164 | + if (!$full) { |
|
| 165 | + $values = array_map(function ($value) { |
|
| 166 | + if (is_string($value) && strlen($value) > 32) { |
|
| 167 | + return substr($value, 0, 6) . '...' . substr($value, -6, 6); |
|
| 168 | + } else { |
|
| 169 | + return $value; |
|
| 170 | + } |
|
| 171 | + }, $values); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + $configStrings = array_map(function ($key, $value) { |
|
| 175 | + return $key . ': ' . json_encode($value); |
|
| 176 | + }, $keys, $values); |
|
| 177 | + $configString = implode(', ', $configStrings); |
|
| 178 | + |
|
| 179 | + $mountOptions = $config->getMountOptions(); |
|
| 180 | + // hide defaults |
|
| 181 | + foreach ($mountOptions as $key => $value) { |
|
| 182 | + if ($value === $defaultMountOptions[$key]) { |
|
| 183 | + unset($mountOptions[$key]); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + $keys = array_keys($mountOptions); |
|
| 187 | + $values = array_values($mountOptions); |
|
| 188 | + |
|
| 189 | + $optionsStrings = array_map(function ($key, $value) { |
|
| 190 | + return $key . ': ' . json_encode($value); |
|
| 191 | + }, $keys, $values); |
|
| 192 | + $optionsString = implode(', ', $optionsStrings); |
|
| 193 | + |
|
| 194 | + $values = [ |
|
| 195 | + $config->getId(), |
|
| 196 | + $config->getMountPoint(), |
|
| 197 | + $config->getBackend()->getText(), |
|
| 198 | + $config->getAuthMechanism()->getText(), |
|
| 199 | + $configString, |
|
| 200 | + $optionsString |
|
| 201 | + ]; |
|
| 202 | + |
|
| 203 | + if (!$userId || $userId === self::ALL) { |
|
| 204 | + $applicableUsers = implode(', ', $config->getApplicableUsers()); |
|
| 205 | + $applicableGroups = implode(', ', $config->getApplicableGroups()); |
|
| 206 | + if ($applicableUsers === '' && $applicableGroups === '') { |
|
| 207 | + $applicableUsers = 'All'; |
|
| 208 | + } |
|
| 209 | + $values[] = $applicableUsers; |
|
| 210 | + $values[] = $applicableGroups; |
|
| 211 | + } |
|
| 212 | + if ($userId === self::ALL) { |
|
| 213 | + $values[] = $config->getType() === StorageConfig::MOUNT_TYPE_ADMIN ? 'Admin' : 'Personal'; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + return $values; |
|
| 217 | + }, $mounts); |
|
| 218 | + |
|
| 219 | + $table = new Table($output); |
|
| 220 | + $table->setHeaders($headers); |
|
| 221 | + $table->setRows($rows); |
|
| 222 | + $table->render(); |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + protected function getStorageService(string $userId): StoragesService { |
|
| 227 | + if (empty($userId)) { |
|
| 228 | + return $this->globalService; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + $user = $this->userManager->get($userId); |
|
| 232 | + if (is_null($user)) { |
|
| 233 | + throw new NoUserException("user $userId not found"); |
|
| 234 | + } |
|
| 235 | + $this->userSession->setUser($user); |
|
| 236 | + return $this->userService; |
|
| 237 | + } |
|
| 238 | 238 | } |
@@ -32,13 +32,13 @@ |
||
| 32 | 32 | * @since 26.0.0 |
| 33 | 33 | */ |
| 34 | 34 | interface IAssertion { |
| 35 | - /** |
|
| 36 | - * This method throws a localized exception when user limits are exceeded, |
|
| 37 | - * if applicable. Notifications are also created in that case. It is a |
|
| 38 | - * shorthand for a check against IRegistry::delegateIsHardUserLimitReached(). |
|
| 39 | - * |
|
| 40 | - * @throws HintException |
|
| 41 | - * @since 26.0.0 |
|
| 42 | - */ |
|
| 43 | - public function createUserIsLegit(): void; |
|
| 35 | + /** |
|
| 36 | + * This method throws a localized exception when user limits are exceeded, |
|
| 37 | + * if applicable. Notifications are also created in that case. It is a |
|
| 38 | + * shorthand for a check against IRegistry::delegateIsHardUserLimitReached(). |
|
| 39 | + * |
|
| 40 | + * @throws HintException |
|
| 41 | + * @since 26.0.0 |
|
| 42 | + */ |
|
| 43 | + public function createUserIsLegit(): void; |
|
| 44 | 44 | } |
@@ -30,10 +30,10 @@ |
||
| 30 | 30 | * @since 24.0.7 |
| 31 | 31 | */ |
| 32 | 32 | interface ICountMappedUsersBackend { |
| 33 | - /** |
|
| 34 | - * @since 24.0.7 |
|
| 35 | - * |
|
| 36 | - * @return int The number of users already mapped to a Nextcloud account |
|
| 37 | - */ |
|
| 38 | - public function countMappedUsers(): int; |
|
| 33 | + /** |
|
| 34 | + * @since 24.0.7 |
|
| 35 | + * |
|
| 36 | + * @return int The number of users already mapped to a Nextcloud account |
|
| 37 | + */ |
|
| 38 | + public function countMappedUsers(): int; |
|
| 39 | 39 | } |
@@ -62,9 +62,9 @@ |
||
| 62 | 62 | } |
| 63 | 63 | /* Replace by normalized form */ |
| 64 | 64 | if ($parsedIp instanceof IPv6) { |
| 65 | - $ip = (string)($parsedIp->toIPv4() ?? $parsedIp); |
|
| 65 | + $ip = (string) ($parsedIp->toIPv4() ?? $parsedIp); |
|
| 66 | 66 | } else { |
| 67 | - $ip = (string)$parsedIp; |
|
| 67 | + $ip = (string) $parsedIp; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
@@ -21,41 +21,41 @@ |
||
| 21 | 21 | * @internal |
| 22 | 22 | */ |
| 23 | 23 | class IpAddressClassifier { |
| 24 | - private const LOCAL_ADDRESS_RANGES = [ |
|
| 25 | - '100.64.0.0/10', // See RFC 6598 |
|
| 26 | - '192.0.0.0/24', // See RFC 6890 |
|
| 27 | - ]; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Check host identifier for local IPv4 and IPv6 address ranges |
|
| 31 | - * |
|
| 32 | - * Hostnames are not considered local. Use the HostnameClassifier for those. |
|
| 33 | - */ |
|
| 34 | - public function isLocalAddress(string $ip): bool { |
|
| 35 | - $parsedIp = Factory::parseAddressString( |
|
| 36 | - $ip, |
|
| 37 | - ParseStringFlag::IPV4_MAYBE_NON_DECIMAL | ParseStringFlag::IPV4ADDRESS_MAYBE_NON_QUAD_DOTTED | ParseStringFlag::MAY_INCLUDE_ZONEID |
|
| 38 | - ); |
|
| 39 | - if ($parsedIp === null) { |
|
| 40 | - /* Not an IP */ |
|
| 41 | - return false; |
|
| 42 | - } |
|
| 43 | - /* Replace by normalized form */ |
|
| 44 | - if ($parsedIp instanceof IPv6) { |
|
| 45 | - $ip = (string)($parsedIp->toIPv4() ?? $parsedIp); |
|
| 46 | - } else { |
|
| 47 | - $ip = (string)$parsedIp; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 51 | - /* Range address */ |
|
| 52 | - return true; |
|
| 53 | - } |
|
| 54 | - if (IpUtils::checkIp($ip, self::LOCAL_ADDRESS_RANGES)) { |
|
| 55 | - /* Within local range */ |
|
| 56 | - return true; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - return false; |
|
| 60 | - } |
|
| 24 | + private const LOCAL_ADDRESS_RANGES = [ |
|
| 25 | + '100.64.0.0/10', // See RFC 6598 |
|
| 26 | + '192.0.0.0/24', // See RFC 6890 |
|
| 27 | + ]; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Check host identifier for local IPv4 and IPv6 address ranges |
|
| 31 | + * |
|
| 32 | + * Hostnames are not considered local. Use the HostnameClassifier for those. |
|
| 33 | + */ |
|
| 34 | + public function isLocalAddress(string $ip): bool { |
|
| 35 | + $parsedIp = Factory::parseAddressString( |
|
| 36 | + $ip, |
|
| 37 | + ParseStringFlag::IPV4_MAYBE_NON_DECIMAL | ParseStringFlag::IPV4ADDRESS_MAYBE_NON_QUAD_DOTTED | ParseStringFlag::MAY_INCLUDE_ZONEID |
|
| 38 | + ); |
|
| 39 | + if ($parsedIp === null) { |
|
| 40 | + /* Not an IP */ |
|
| 41 | + return false; |
|
| 42 | + } |
|
| 43 | + /* Replace by normalized form */ |
|
| 44 | + if ($parsedIp instanceof IPv6) { |
|
| 45 | + $ip = (string)($parsedIp->toIPv4() ?? $parsedIp); |
|
| 46 | + } else { |
|
| 47 | + $ip = (string)$parsedIp; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 51 | + /* Range address */ |
|
| 52 | + return true; |
|
| 53 | + } |
|
| 54 | + if (IpUtils::checkIp($ip, self::LOCAL_ADDRESS_RANGES)) { |
|
| 55 | + /* Within local range */ |
|
| 56 | + return true; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + return false; |
|
| 60 | + } |
|
| 61 | 61 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | public function onShutdown(): void { |
| 56 | 56 | $error = error_get_last(); |
| 57 | 57 | if ($error) { |
| 58 | - $msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line']; |
|
| 58 | + $msg = $error['message'].' at '.$error['file'].'#'.$error['line']; |
|
| 59 | 59 | $this->logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | public function onException(Throwable $exception): void { |
| 67 | 67 | $class = get_class($exception); |
| 68 | 68 | $msg = $exception->getMessage(); |
| 69 | - $msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine(); |
|
| 69 | + $msg = "$class: $msg at ".$exception->getFile().'#'.$exception->getLine(); |
|
| 70 | 70 | $this->logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
| 71 | 71 | } |
| 72 | 72 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | if (!(error_reporting() & $number)) { |
| 78 | 78 | return true; |
| 79 | 79 | } |
| 80 | - $msg = $message . ' at ' . $file . '#' . $line; |
|
| 80 | + $msg = $message.' at '.$file.'#'.$line; |
|
| 81 | 81 | $e = new Error(self::removePassword($msg)); |
| 82 | 82 | $this->logger->log(self::errnoToLogLevel($number), $e->getMessage(), ['app' => 'PHP']); |
| 83 | 83 | return true; |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | * Recoverable handler which catch all errors, warnings and notices |
| 88 | 88 | */ |
| 89 | 89 | public function onAll(int $number, string $message, string $file, int $line): bool { |
| 90 | - $msg = $message . ' at ' . $file . '#' . $line; |
|
| 90 | + $msg = $message.' at '.$file.'#'.$line; |
|
| 91 | 91 | $e = new Error(self::removePassword($msg)); |
| 92 | 92 | $this->logger->log(self::errnoToLogLevel($number), $e->getMessage(), ['app' => 'PHP']); |
| 93 | 93 | return true; |
@@ -14,68 +14,68 @@ |
||
| 14 | 14 | use Throwable; |
| 15 | 15 | |
| 16 | 16 | class ErrorHandler { |
| 17 | - public function __construct( |
|
| 18 | - private LoggerInterface $logger, |
|
| 19 | - ) { |
|
| 20 | - } |
|
| 17 | + public function __construct( |
|
| 18 | + private LoggerInterface $logger, |
|
| 19 | + ) { |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Remove password in URLs |
|
| 24 | - */ |
|
| 25 | - private static function removePassword(string $msg): string { |
|
| 26 | - return preg_replace('#//(.*):(.*)@#', '//xxx:xxx@', $msg); |
|
| 27 | - } |
|
| 22 | + /** |
|
| 23 | + * Remove password in URLs |
|
| 24 | + */ |
|
| 25 | + private static function removePassword(string $msg): string { |
|
| 26 | + return preg_replace('#//(.*):(.*)@#', '//xxx:xxx@', $msg); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Fatal errors handler |
|
| 31 | - */ |
|
| 32 | - public function onShutdown(): void { |
|
| 33 | - $error = error_get_last(); |
|
| 34 | - if ($error) { |
|
| 35 | - $msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line']; |
|
| 36 | - $this->logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
|
| 37 | - } |
|
| 38 | - } |
|
| 29 | + /** |
|
| 30 | + * Fatal errors handler |
|
| 31 | + */ |
|
| 32 | + public function onShutdown(): void { |
|
| 33 | + $error = error_get_last(); |
|
| 34 | + if ($error) { |
|
| 35 | + $msg = $error['message'] . ' at ' . $error['file'] . '#' . $error['line']; |
|
| 36 | + $this->logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Uncaught exception handler |
|
| 42 | - */ |
|
| 43 | - public function onException(Throwable $exception): void { |
|
| 44 | - $class = get_class($exception); |
|
| 45 | - $msg = $exception->getMessage(); |
|
| 46 | - $msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine(); |
|
| 47 | - $this->logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
|
| 48 | - } |
|
| 40 | + /** |
|
| 41 | + * Uncaught exception handler |
|
| 42 | + */ |
|
| 43 | + public function onException(Throwable $exception): void { |
|
| 44 | + $class = get_class($exception); |
|
| 45 | + $msg = $exception->getMessage(); |
|
| 46 | + $msg = "$class: $msg at " . $exception->getFile() . '#' . $exception->getLine(); |
|
| 47 | + $this->logger->critical(self::removePassword($msg), ['app' => 'PHP']); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Recoverable errors handler |
|
| 52 | - */ |
|
| 53 | - public function onError(int $number, string $message, string $file, int $line): bool { |
|
| 54 | - if (!(error_reporting() & $number)) { |
|
| 55 | - return true; |
|
| 56 | - } |
|
| 57 | - $msg = $message . ' at ' . $file . '#' . $line; |
|
| 58 | - $e = new Error(self::removePassword($msg)); |
|
| 59 | - $this->logger->log(self::errnoToLogLevel($number), $e->getMessage(), ['app' => 'PHP']); |
|
| 60 | - return true; |
|
| 61 | - } |
|
| 50 | + /** |
|
| 51 | + * Recoverable errors handler |
|
| 52 | + */ |
|
| 53 | + public function onError(int $number, string $message, string $file, int $line): bool { |
|
| 54 | + if (!(error_reporting() & $number)) { |
|
| 55 | + return true; |
|
| 56 | + } |
|
| 57 | + $msg = $message . ' at ' . $file . '#' . $line; |
|
| 58 | + $e = new Error(self::removePassword($msg)); |
|
| 59 | + $this->logger->log(self::errnoToLogLevel($number), $e->getMessage(), ['app' => 'PHP']); |
|
| 60 | + return true; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * Recoverable handler which catch all errors, warnings and notices |
|
| 65 | - */ |
|
| 66 | - public function onAll(int $number, string $message, string $file, int $line): bool { |
|
| 67 | - $msg = $message . ' at ' . $file . '#' . $line; |
|
| 68 | - $e = new Error(self::removePassword($msg)); |
|
| 69 | - $this->logger->log(self::errnoToLogLevel($number), $e->getMessage(), ['app' => 'PHP']); |
|
| 70 | - return true; |
|
| 71 | - } |
|
| 63 | + /** |
|
| 64 | + * Recoverable handler which catch all errors, warnings and notices |
|
| 65 | + */ |
|
| 66 | + public function onAll(int $number, string $message, string $file, int $line): bool { |
|
| 67 | + $msg = $message . ' at ' . $file . '#' . $line; |
|
| 68 | + $e = new Error(self::removePassword($msg)); |
|
| 69 | + $this->logger->log(self::errnoToLogLevel($number), $e->getMessage(), ['app' => 'PHP']); |
|
| 70 | + return true; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - private static function errnoToLogLevel(int $errno): int { |
|
| 74 | - return match ($errno) { |
|
| 75 | - E_WARNING, E_USER_WARNING => ILogger::WARN, |
|
| 76 | - E_DEPRECATED, E_USER_DEPRECATED => ILogger::DEBUG, |
|
| 77 | - E_NOTICE, E_USER_NOTICE => ILogger::INFO, |
|
| 78 | - default => ILogger::ERROR, |
|
| 79 | - }; |
|
| 80 | - } |
|
| 73 | + private static function errnoToLogLevel(int $errno): int { |
|
| 74 | + return match ($errno) { |
|
| 75 | + E_WARNING, E_USER_WARNING => ILogger::WARN, |
|
| 76 | + E_DEPRECATED, E_USER_DEPRECATED => ILogger::DEBUG, |
|
| 77 | + E_NOTICE, E_USER_NOTICE => ILogger::INFO, |
|
| 78 | + default => ILogger::ERROR, |
|
| 79 | + }; |
|
| 80 | + } |
|
| 81 | 81 | } |