diff options
Diffstat (limited to 'www/wiki/vendor/param-processor/param-processor/src/Processor.php')
-rw-r--r-- | www/wiki/vendor/param-processor/param-processor/src/Processor.php | 92 |
1 files changed, 36 insertions, 56 deletions
diff --git a/www/wiki/vendor/param-processor/param-processor/src/Processor.php b/www/wiki/vendor/param-processor/param-processor/src/Processor.php index a6f2cb46..73a8d67a 100644 --- a/www/wiki/vendor/param-processor/param-processor/src/Processor.php +++ b/www/wiki/vendor/param-processor/param-processor/src/Processor.php @@ -2,6 +2,8 @@ namespace ParamProcessor; +use ParamProcessor\PackagePrivate\Param; + /** * Class for parameter validation of a single parser hook or other parametrized construct. * @@ -41,7 +43,7 @@ class Processor { private $paramsToHandle = []; /** - * @var IParamDefinition[] + * @var ParamDefinition[] */ private $paramDefinitions = []; @@ -58,10 +60,6 @@ class Processor { /** * Constructs and returns a Validator object based on the default options. - * - * @since 1.0 - * - * @return Processor */ public static function newDefault(): self { return new Processor( new Options() ); @@ -69,12 +67,6 @@ class Processor { /** * Constructs and returns a Validator object based on the provided options. - * - * @since 1.0 - * - * @param Options $options - * - * @return Processor */ public static function newFromOptions( Options $options ): self { return new Processor( $options ); @@ -82,10 +74,6 @@ class Processor { /** * Returns the options used by this Validator object. - * - * @since 1.0 - * - * @return Options */ public function getOptions(): Options { return $this->options; @@ -98,18 +86,14 @@ class Processor { * @since 0.4 * * @param string[] $rawParams - * @param array $parameterDefinitions + * @param ParamDefinition[]|array[] $parameterDefinitions DEPRECATED! Use @see setParameterDefinitions instead * @param array $defaultParams array of strings or array of arrays to define which parameters can be used unnamed. * The second value in array-form is reserved for flags. Currently, Processor::PARAM_UNNAMED determines that * the parameter has no name which can be used to set it. Therefore all these parameters must be set before * any named parameter. The effect is, that '=' within the string won't confuse the parameter anymore like * it would happen with default parameters that still have a name as well. */ - public function setFunctionParams( array $rawParams, array $parameterDefinitions, array $defaultParams = [] ) { - $parameters = []; - - $nr = 0; - $defaultNr = 0; + public function setFunctionParams( array $rawParams, array $parameterDefinitions = [], array $defaultParams = [] ) { $lastUnnamedDefaultNr = -1; /* @@ -118,7 +102,7 @@ class Processor { * after the first named param. Wouldn't be possible to determine which unnamed value * belongs to which parameter otherwise. */ - for( $i = count( $defaultParams ) - 1; $i >= 0 ; $i-- ) { + for( $i = count( $defaultParams ) - 1; $i >= 0; $i-- ) { $dflt = $defaultParams[$i]; if( is_array( $dflt ) && !empty( $dflt[1] ) && ( $dflt[1] | self::PARAM_UNNAMED ) ) { $lastUnnamedDefaultNr = $i; @@ -126,6 +110,10 @@ class Processor { } } + $parameters = []; + $nr = 0; + $defaultNr = 0; + foreach ( $rawParams as $arg ) { // Only take into account strings. If the value is not a string, // it is not a raw parameter, and can not be parsed correctly in all cases. @@ -150,9 +138,6 @@ class Processor { ]; $defaultNr++; } - else { - // It might be nice to have some sort of warning or error here, as the value is simply ignored. - } } else { $paramName = trim( strtolower( $parts[0] ) ); @@ -167,7 +152,9 @@ class Processor { $newDefaults = []; foreach( $defaultParams as $defaultParam ) { - if ( $defaultParam != $paramName ) $newDefaults[] = $defaultParam; + if ( $defaultParam != $paramName ) { + $newDefaults[] = $defaultParam; + } } $defaultParams = $newDefaults; @@ -181,13 +168,21 @@ class Processor { } /** + * @since 1.6.0 + * @param ParamDefinition[] $paramDefinitions + */ + public function setParameterDefinitions( array $paramDefinitions ) { + $this->paramDefinitions = $paramDefinitions; + } + + /** * Loops through a list of provided parameters, resolves aliasing and stores errors * for unknown parameters and optionally for parameter overriding. * * @param array $parameters Parameter name as key, parameter value as value - * @param IParamDefinition[] $paramDefinitions List of parameter definitions. Either ParamDefinition objects or equivalent arrays. + * @param ParamDefinition[]|array[] $paramDefinitions DEPRECATED! Use @see setParameterDefinitions instead */ - public function setParameters( array $parameters, array $paramDefinitions ) { + public function setParameters( array $parameters, array $paramDefinitions = [] ) { $this->paramDefinitions = ParamDefinition::getCleanDefinitions( $paramDefinitions ); // Loop through all the user provided parameters, and distinguish between those that are allowed and those that are not. @@ -208,10 +203,10 @@ class Processor { /** * @param string $message - * @param mixed $tags string or array + * @param string[] $tags * @param integer $severity */ - private function registerNewError( $message, $tags = [], $severity = ProcessingError::SEVERITY_NORMAL ) { + private function registerNewError( string $message, array $tags = [], int $severity = ProcessingError::SEVERITY_NORMAL ) { $this->registerError( new ProcessingError( $message, @@ -247,7 +242,7 @@ class Processor { foreach ( $this->rawParameters as $paramName => $paramValue ) { $this->registerNewError( $paramName . ' is not a valid parameter', // TODO - $paramName + [ $paramName ] ); } } @@ -262,9 +257,6 @@ class Processor { $this->params = []; } - /** - * @var Param $parameter - */ foreach ( $this->params as $parameter ) { // TODO $processedParam = new ProcessedParam( @@ -289,9 +281,6 @@ class Processor { ); } - /** - * Does the actual parameter processing. - */ private function doParamProcessing() { $this->errors = []; @@ -361,7 +350,7 @@ class Processor { } /** - * @param IParamDefinition[] $paramDefinitions + * @param ParamDefinition[] $paramDefinitions * @param string[] $paramsToHandle * * @return array @@ -376,8 +365,8 @@ class Processor { throw new \UnexpectedValueException( 'Unexpected parameter name "' . $paramName . '"' ); } - if ( !is_object( $paramDefinitions[$paramName] ) || !( $paramDefinitions[$paramName] instanceof IParamDefinition ) ) { - throw new \UnexpectedValueException( 'Parameter "' . $paramName . '" is not a IParamDefinition' ); + if ( !is_object( $paramDefinitions[$paramName] ) || !( $paramDefinitions[$paramName] instanceof ParamDefinition ) ) { + throw new \UnexpectedValueException( 'Parameter "' . $paramName . '" is not a ParamDefinition' ); } // Only include dependencies that are in the list of parameters to handle. @@ -420,34 +409,24 @@ class Processor { } /** - * Returns the parameters. - * - * @since 0.4 * @deprecated since 1.0 - * - * @return IParam[] + * @return Param[] */ public function getParameters(): array { return $this->params; } /** - * Returns a single parameter. - * - * @since 0.4 * @deprecated since 1.0 - * - * @param string $parameterName The name of the parameter to return - * - * @return IParam */ - public function getParameter( string $parameterName ): IParam { + public function getParameter( string $parameterName ): Param { return $this->params[$parameterName]; } /** * Returns an associative array with the parameter names as key and their * corresponding values as value. + * @deprecated since 1.7 - use processParameters() return value */ public function getParameterValues(): array { $parameters = []; @@ -460,6 +439,7 @@ class Processor { } /** + * @deprecated since 1.7 - use processParameters() return value * @return ProcessingError[] */ public function getErrors(): array { @@ -467,6 +447,7 @@ class Processor { } /** + * @deprecated since 1.7 - use processParameters() return value * @return string[] */ public function getErrorMessages(): array { @@ -480,15 +461,14 @@ class Processor { } /** - * Returns if there where any errors during validation. + * @deprecated since 1.7 - use processParameters() return value */ public function hasErrors(): bool { return !empty( $this->errors ); } /** - * Returns false when there are no fatal errors or an ProcessingError when one is found. - * + * @deprecated since 1.7 - use processParameters() return value * @return ProcessingError|boolean false */ public function hasFatalError() { |