wiki.techinc.nl/includes/libs/ParamValidator/Callbacks.php
Brad Jorsch aa0720d37c ParamValidator: Use MessageValue!
Trying to get away with returning a single code and parameter-list that
was supposed to represent both human-readable and machine-readable data
was a mistake.

This patch converts it to use DataMessageValue, which represents the two
separately and also provides guidance for supplying translations of all
the error codes.

This also eliminates the "describeSettings()" method that was trying to
serve multiple use cases (in terms of the Action API, action=paraminfo
and action=help). It's replaced by two methods that each serve one of
the use cases. Also some of the functionality was moved out of the
TypeDef base class into ParamValidator, to better match where the
constants themselves live.

Also I wound up creating a NumericDef base class so FloatDef can share
the same range-checking logic that IntegerDef has. I probably should
have done that as a separate patch, but untangling it now would be too
much work.

Bug: T235801
Change-Id: Iea6d4a1d05bb4b92d60415b0f03ff9d3dc99a80b
2019-11-01 15:49:31 -04:00

85 lines
2.6 KiB
PHP

<?php
namespace Wikimedia\ParamValidator;
use Psr\Http\Message\UploadedFileInterface;
use Wikimedia\Message\DataMessageValue;
/**
* Interface defining callbacks needed by ParamValidator
*
* The user of ParamValidator is expected to pass an object implementing this
* interface to ParamValidator's constructor.
*
* All methods in this interface accept an "options array". This is the same `$options`
* passed to ParamValidator::getValue(), ParamValidator::validateValue(), and the like
* and is intended for communication of non-global state.
*
* @since 1.34
* @unstable
*/
interface Callbacks {
/**
* Test if a parameter exists in the request
* @param string $name Parameter name
* @param array $options Options array
* @return bool True if present, false if absent.
* Return false for file upload parameters.
*/
public function hasParam( $name, array $options );
/**
* Fetch a value from the request
*
* Return `$default` for file-upload parameters.
*
* @param string $name Parameter name to fetch
* @param mixed $default Default value to return if the parameter is unset.
* @param array $options Options array
* @return string|string[]|mixed A string or string[] if the parameter was found,
* or $default if it was not.
*/
public function getValue( $name, $default, array $options );
/**
* Test if a parameter exists as an upload in the request
* @param string $name Parameter name
* @param array $options Options array
* @return bool True if present, false if absent.
*/
public function hasUpload( $name, array $options );
/**
* Fetch data for a file upload
* @param string $name Parameter name of the upload
* @param array $options Options array
* @return UploadedFileInterface|null Uploaded file, or null if there is no file for $name.
*/
public function getUploadedFile( $name, array $options );
/**
* Record non-fatal conditions.
* @param DataMessageValue $message Failure message
* @param string $name Parameter name
* @param mixed $value Parameter value
* @param array $settings Parameter settings array
* @param array $options Options array
*/
public function recordCondition(
DataMessageValue $message, $name, $value, array $settings, array $options
);
/**
* Indicate whether "high limits" should be used.
*
* Some settings have multiple limits, one for "normal" users and a higher
* one for "privileged" users. This is used to determine which class the
* current user is in when necessary.
*
* @param array $options Options array
* @return bool Whether the current user is privileged to use high limits
*/
public function useHighLimits( array $options );
}