-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
Signed-off-by: Maxence Lange <[email protected]>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2024 Maxence Lange <[email protected]> | ||
* | ||
* @author Maxence Lange <[email protected]> | ||
* | ||
* @license AGPL-3.0 or later | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OC\AppFramework\ConfigValues; | ||
|
||
use OCP\AppFramework\ConfigValues\IConfigValue; | ||
|
||
abstract class AConfigValue implements IConfigValue { | ||
private ?string $default = null; | ||
private bool $lazy = false; | ||
private bool $sensitive = false; | ||
private bool $deprecated = false; | ||
|
||
public function __construct( | ||
private string $key, | ||
private int $valueType | ||
) { | ||
} | ||
|
||
abstract public function getConfigType(): string; | ||
|
||
public function getKey(): string { | ||
return $this->key; | ||
} | ||
|
||
public function getValueType(): int { | ||
return $this->valueType; | ||
} | ||
|
||
public function withDefaultString(string $default): self { | ||
$this->default = $default; | ||
return $this; | ||
} | ||
|
||
public function withDefaultInt(int $default): self { | ||
$this->default = (string) $default; | ||
return $this; | ||
} | ||
|
||
public function withDefaultFloat(float $default): self { | ||
$this->default = (string) $default; | ||
return $this; | ||
} | ||
|
||
public function withDefaultBool(bool $default): self { | ||
$this->default = ($default) ? '1' : '0'; | ||
return $this; | ||
} | ||
|
||
public function withDefaultArray(array $default): self { | ||
$this->default = json_encode($default); | ||
return $this; | ||
} | ||
|
||
public function getDefault(): string { | ||
Check failure Code scanning / Psalm InvalidNullableReturnType Error
The declared return type 'string' for OC\AppFramework\ConfigValues\AConfigValue::getDefault is not nullable, but 'null|string' contains null
Check failure on line 76 in lib/private/AppFramework/ConfigValues/AConfigValue.php GitHub Actions / static-code-analysisInvalidNullableReturnType
|
||
return $this->default; | ||
Check failure Code scanning / Psalm NullableReturnStatement Error
The declared return type 'string' for OC\AppFramework\ConfigValues\AConfigValue::getDefault is not nullable, but the function returns 'null|string'
Check failure on line 77 in lib/private/AppFramework/ConfigValues/AConfigValue.php GitHub Actions / static-code-analysisNullableReturnStatement
|
||
} | ||
|
||
public function asLazy(bool $lazy = true): self { | ||
$this->lazy = $lazy; | ||
return $this; | ||
} | ||
|
||
public function isLazy(): bool { | ||
return $this->lazy; | ||
} | ||
|
||
public function asSensitive(bool $sensitive = true): self { | ||
$this->sensitive = $sensitive; | ||
return $this; | ||
} | ||
|
||
public function isSensitive(): bool { | ||
return $this->sensitive; | ||
} | ||
|
||
public function asDeprecated(bool $deprecated = true): self { | ||
$this->deprecated = $deprecated; | ||
return $this; | ||
} | ||
|
||
public function isDeprecated(): bool { | ||
return $this->deprecated; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2024 Maxence Lange <[email protected]> | ||
* | ||
* @author Maxence Lange <[email protected]> | ||
* | ||
* @license AGPL-3.0 or later | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OC\AppFramework\ConfigValues; | ||
|
||
class AppConfigValue extends AConfigValue { | ||
public const TYPE = 'AppConfig'; | ||
|
||
public function getConfigType(): string { | ||
return self::TYPE; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2024 Maxence Lange <[email protected]> | ||
* | ||
* @author Maxence Lange <[email protected]> | ||
* | ||
* @license AGPL-3.0 or later | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OC\AppFramework\ConfigValues; | ||
|
||
class UserPreferenceValue extends AConfigValue { | ||
public const TYPE = 'UserPreference'; | ||
|
||
public function getConfigType(): string { | ||
return self::TYPE; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2024 Maxence Lange <[email protected]> | ||
* | ||
* @author Maxence Lange <[email protected]> | ||
* | ||
* @license AGPL-3.0 or later | ||
* | ||
* This code is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License, version 3, | ||
* as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License, version 3, | ||
* along with this program. If not, see <http://www.gnu.org/licenses/> | ||
* | ||
*/ | ||
|
||
namespace OCP\AppFramework\ConfigValues; | ||
|
||
interface IConfigValue { | ||
Check failure on line 27 in lib/public/AppFramework/ConfigValues/IConfigValue.php GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
public const TYPE_STRING = 1; | ||
Check failure on line 28 in lib/public/AppFramework/ConfigValues/IConfigValue.php GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
public const TYPE_INT = 2; | ||
Check failure on line 29 in lib/public/AppFramework/ConfigValues/IConfigValue.php GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
public const TYPE_FLOAT = 3; | ||
Check failure on line 30 in lib/public/AppFramework/ConfigValues/IConfigValue.php GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
public const TYPE_BOOL = 4; | ||
Check failure on line 31 in lib/public/AppFramework/ConfigValues/IConfigValue.php GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
public const TYPE_ARRAY = 5; | ||
Check failure on line 32 in lib/public/AppFramework/ConfigValues/IConfigValue.php GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
|
||
public function getConfigType(): string; | ||
Check failure on line 34 in lib/public/AppFramework/ConfigValues/IConfigValue.php GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
|
||
public function getKey(): string; | ||
Check failure on line 36 in lib/public/AppFramework/ConfigValues/IConfigValue.php GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
public function getValueType(): int; | ||
Check failure on line 37 in lib/public/AppFramework/ConfigValues/IConfigValue.php GitHub Actions / static-code-analysis-ocpInvalidDocblock
|
||
|
||
public function withDefaultString(string $default): self; | ||
public function withDefaultInt(int $default): self; | ||
public function withDefaultFloat(float $default): self; | ||
public function withDefaultBool(bool $default): self; | ||
public function withDefaultArray(array $default): self; | ||
public function getDefault(): ?string; | ||
|
||
public function asLazy(bool $lazy = true): self; | ||
public function isLazy(): bool; | ||
public function asSensitive(bool $sensitive = true): self; | ||
public function isSensitive(): bool; | ||
public function asDeprecated(bool $deprecated = true): self; | ||
public function isDeprecated(): bool; | ||
} |