MediaWiki master
SimpleCallbacks.php
Go to the documentation of this file.
1<?php
2
4
7
17class 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
38 public function hasParam( $name, array $options ) {
39 return isset( $this->params[$name] );
40 }
41
43 public function getValue( $name, $default, array $options ) {
44 return $this->params[$name] ?? $default;
45 }
46
48 public function hasUpload( $name, array $options ) {
49 return isset( $this->files[$name] );
50 }
51
53 public function getUploadedFile( $name, array $options ) {
54 $file = $this->files[$name] ?? null;
55 if ( $file && !$file instanceof UploadedFile ) {
56 $file = new UploadedFile( $file );
57 $this->files[$name] = $file;
58 }
59 // @phan-suppress-next-line PhanTypeMismatchReturnNullable False positive
60 return $file;
61 }
62
64 public function recordCondition(
65 DataMessageValue $message, $name, $value, array $settings, array $options
66 ) {
67 $this->conditions[] = [
68 'message' => $message,
69 'name' => $name,
70 'value' => $value,
71 'settings' => $settings,
72 ];
73 }
74
79 public function getRecordedConditions() {
80 return $this->conditions;
81 }
82
86 public function clearRecordedConditions() {
87 $this->conditions = [];
88 }
89
91 public function useHighLimits( array $options ) {
92 return !empty( $options['useHighLimits'] );
93 }
94
95}
Value object representing a message for i18n with alternative machine-readable data.
Simple Callbacks implementation for $_GET/$_POST/$_FILES data.
__construct(array $params, array $files=[])
useHighLimits(array $options)
Indicate whether "high limits" should be used.Some settings have multiple limits, one for "normal" us...
recordCondition(DataMessageValue $message, $name, $value, array $settings, array $options)
Record non-fatal conditions.
hasParam( $name, array $options)
Test if a parameter exists in the request.bool True if present, false if absent. Return false for fil...
getUploadedFile( $name, array $options)
Fetch data for a file upload.UploadedFileInterface|null Uploaded file, or null if there is no file fo...
getValue( $name, $default, array $options)
Fetch a value from the request.Return $default for file-upload parameters.string|string[]|mixed A str...
clearRecordedConditions()
Clear any recorded conditions.
getRecordedConditions()
Fetch any recorded conditions.
hasUpload( $name, array $options)
Test if a parameter exists as an upload in the request.bool True if present, false if absent.
A simple implementation of UploadedFileInterface.
Interface defining callbacks needed by ParamValidator.
Definition Callbacks.php:21