2018-05-22 23:23:20 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Wikimedia\ParamValidator;
|
|
|
|
|
|
|
|
|
|
use Psr\Http\Message\UploadedFileInterface;
|
2019-09-12 17:44:11 +00:00
|
|
|
use Wikimedia\Message\DataMessageValue;
|
2018-05-22 23:23:20 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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
|
2019-11-01 17:48:59 +00:00
|
|
|
* @unstable
|
2018-05-22 23:23:20 +00:00
|
|
|
*/
|
|
|
|
|
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.
|
2019-09-12 17:44:11 +00:00
|
|
|
* @param DataMessageValue $message Failure message
|
|
|
|
|
* @param string $name Parameter name
|
|
|
|
|
* @param mixed $value Parameter value
|
|
|
|
|
* @param array $settings Parameter settings array
|
2018-05-22 23:23:20 +00:00
|
|
|
* @param array $options Options array
|
|
|
|
|
*/
|
2019-09-12 17:44:11 +00:00
|
|
|
public function recordCondition(
|
|
|
|
|
DataMessageValue $message, $name, $value, array $settings, array $options
|
|
|
|
|
);
|
2018-05-22 23:23:20 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 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 );
|
|
|
|
|
|
|
|
|
|
}
|