summaryrefslogtreecommitdiff
path: root/www/wiki/vendor/param-processor/param-processor/src/ParameterTypes.php
diff options
context:
space:
mode:
Diffstat (limited to 'www/wiki/vendor/param-processor/param-processor/src/ParameterTypes.php')
-rw-r--r--www/wiki/vendor/param-processor/param-processor/src/ParameterTypes.php71
1 files changed, 62 insertions, 9 deletions
diff --git a/www/wiki/vendor/param-processor/param-processor/src/ParameterTypes.php b/www/wiki/vendor/param-processor/param-processor/src/ParameterTypes.php
index ca4e66bc..4f984e51 100644
--- a/www/wiki/vendor/param-processor/param-processor/src/ParameterTypes.php
+++ b/www/wiki/vendor/param-processor/param-processor/src/ParameterTypes.php
@@ -4,8 +4,9 @@ declare( strict_types = 1 );
namespace ParamProcessor;
-use ParamProcessor\Definition\DimensionParam;
use ParamProcessor\Definition\StringParam;
+use ParamProcessor\PackagePrivate\DimensionParser;
+use ParamProcessor\PackagePrivate\ParamType;
use ValueParsers\BoolParser;
use ValueParsers\FloatParser;
use ValueParsers\IntParser;
@@ -14,37 +15,89 @@ use ValueValidators\RangeValidator;
use ValueValidators\StringValidator;
/**
- * @since 1.4
- *
* @licence GNU GPL v2+
* @author Jeroen De Dauw < jeroendedauw@gmail.com >
*/
class ParameterTypes {
+ /**
+ * @since 1.7
+ */
+ public const BOOLEAN = 'boolean';
+ public const FLOAT = 'float';
+ public const INTEGER = 'integer';
+ public const STRING = 'string';
+ public const DIMENSION = 'dimension';
+
+ /**
+ * @var ParamType[]
+ */
+ private $types = [];
+
+ /**
+ * @param array[] $typeSpecs
+ */
+ public function __construct( array $typeSpecs = [] ) {
+ foreach ( $typeSpecs as $typeName => $typeSpec ) {
+ $this->addType( $typeName, $typeSpec );
+ }
+ }
+
+ /**
+ * @since 1.8
+ */
+ public function addType( string $typeName, array $typeSpec ) {
+ $this->types[$typeName] = ParamType::newFromArray( $typeName, $typeSpec );
+ }
+
+ /**
+ * Package private
+ */
+ public function hasType( string $typeName ): bool {
+ return array_key_exists( $typeName, $this->types );
+ }
+
+ /**
+ * Package private
+ */
+ public function getType( string $typeName ): ParamType {
+ return $this->types[$typeName];
+ }
+
+ /**
+ * @since 1.8
+ */
+ public static function newCoreTypes(): self {
+ return new self( self::getCoreTypes() );
+ }
+
+ /**
+ * @since 1.4
+ */
public static function getCoreTypes(): array {
return [
- 'boolean' => [
+ self::BOOLEAN => [
'string-parser' => BoolParser::class,
'validation-callback' => 'is_bool',
],
- 'float' => [
+ self::FLOAT => [
'string-parser' => FloatParser::class,
'validation-callback' => function( $value ) {
return is_float( $value ) || is_int( $value );
},
'validator' => RangeValidator::class,
],
- 'integer' => [
+ self::INTEGER => [
'string-parser' => IntParser::class,
'validation-callback' => 'is_int',
'validator' => RangeValidator::class,
],
- 'string' => [
+ self::STRING => [
'validator' => StringValidator::class,
'definition' => StringParam::class,
],
- 'dimension' => [
- 'definition' => DimensionParam::class,
+ self::DIMENSION => [
+ 'string-parser' => DimensionParser::class,
'validator' => DimensionValidator::class,
],
];