MediaWiki  master
SimpleCallbacks.php
Go to the documentation of this file.
1 <?php
2 
4 
7 
17 class SimpleCallbacks implements Callbacks {
18 
20  private $params;
21 
23  private $files;
24 
26  private $conditions = [];
27 
32  public function __construct( array $params, array $files = [] ) {
33  $this->params = $params;
34  $this->files = $files;
35  }
36 
37  public function hasParam( $name, array $options ) {
38  return isset( $this->params[$name] );
39  }
40 
41  public function getValue( $name, $default, array $options ) {
42  return $this->params[$name] ?? $default;
43  }
44 
45  public function hasUpload( $name, array $options ) {
46  return isset( $this->files[$name] );
47  }
48 
49  public function getUploadedFile( $name, array $options ) {
50  $file = $this->files[$name] ?? null;
51  if ( $file && !$file instanceof UploadedFile ) {
52  $file = new UploadedFile( $file );
53  $this->files[$name] = $file;
54  }
55  return $file;
56  }
57 
58  public function recordCondition(
59  DataMessageValue $message, $name, $value, array $settings, array $options
60  ) {
61  $this->conditions[] = [
62  'message' => $message,
63  'name' => $name,
64  'value' => $value,
65  'settings' => $settings,
66  ];
67  }
68 
73  public function getRecordedConditions() {
74  return $this->conditions;
75  }
76 
80  public function clearRecordedConditions() {
81  $this->conditions = [];
82  }
83 
84  public function useHighLimits( array $options ) {
85  return !empty( $options['useHighLimits'] );
86  }
87 
88 }
Wikimedia\ParamValidator
Definition: Callbacks.php:3
Wikimedia\ParamValidator\SimpleCallbacks\useHighLimits
useHighLimits(array $options)
Indicate whether "high limits" should be used.
Definition: SimpleCallbacks.php:84
Wikimedia\ParamValidator\Callbacks
Interface defining callbacks needed by ParamValidator.
Definition: Callbacks.php:21
Wikimedia\ParamValidator\SimpleCallbacks\$params
string string[][] $params
$_GET/$_POST data
Definition: SimpleCallbacks.php:20
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
Wikimedia\ParamValidator\SimpleCallbacks\getUploadedFile
getUploadedFile( $name, array $options)
Fetch data for a file upload.
Definition: SimpleCallbacks.php:49
Wikimedia\ParamValidator\SimpleCallbacks\clearRecordedConditions
clearRecordedConditions()
Clear any recorded conditions.
Definition: SimpleCallbacks.php:80
Wikimedia\ParamValidator\SimpleCallbacks\recordCondition
recordCondition(DataMessageValue $message, $name, $value, array $settings, array $options)
Record non-fatal conditions.
Definition: SimpleCallbacks.php:58
Wikimedia\ParamValidator\SimpleCallbacks\hasParam
hasParam( $name, array $options)
Test if a parameter exists in the request.
Definition: SimpleCallbacks.php:37
Wikimedia\ParamValidator\SimpleCallbacks\getRecordedConditions
getRecordedConditions()
Fetch any recorded conditions.
Definition: SimpleCallbacks.php:73
Wikimedia\Message\DataMessageValue
Value object representing a message for i18n with alternative machine-readable data.
Definition: DataMessageValue.php:21
Wikimedia\ParamValidator\SimpleCallbacks
Simple Callbacks implementation for $_GET/$_POST/$_FILES data.
Definition: SimpleCallbacks.php:17
Wikimedia\ParamValidator\SimpleCallbacks\__construct
__construct(array $params, array $files=[])
Definition: SimpleCallbacks.php:32
Wikimedia\ParamValidator\SimpleCallbacks\getValue
getValue( $name, $default, array $options)
Fetch a value from the request.
Definition: SimpleCallbacks.php:41
Wikimedia\ParamValidator\SimpleCallbacks\$conditions
array[] $conditions
Any recorded conditions.
Definition: SimpleCallbacks.php:26
Wikimedia\ParamValidator\SimpleCallbacks\$files
array UploadedFile[] $files
$_FILES data or UploadedFile instances
Definition: SimpleCallbacks.php:23
Wikimedia\ParamValidator\SimpleCallbacks\hasUpload
hasUpload( $name, array $options)
Test if a parameter exists as an upload in the request.
Definition: SimpleCallbacks.php:45
Wikimedia\ParamValidator\Util\UploadedFile
A simple implementation of UploadedFileInterface.
Definition: UploadedFile.php:20