MediaWiki REL1_37
ParamValidatorCallbacks.php
Go to the documentation of this file.
1<?php
2
4
5use InvalidArgumentException;
8use Psr\Http\Message\UploadedFileInterface;
11
13
15 private $authority;
16
18 private $request;
19
20 public function __construct(
23 ) {
24 $this->request = $request;
25 $this->authority = $authority;
26 }
27
33 private function getParamsFromSource( $source ) {
34 switch ( $source ) {
35 case 'path':
36 return $this->request->getPathParams();
37
38 case 'query':
39 return $this->request->getQueryParams();
40
41 case 'post':
42 return $this->request->getPostParams();
43
44 default:
45 throw new InvalidArgumentException( __METHOD__ . ": Invalid source '$source'" );
46 }
47 }
48
49 public function hasParam( $name, array $options ) {
50 $params = $this->getParamsFromSource( $options['source'] );
51 return isset( $params[$name] );
52 }
53
54 public function getValue( $name, $default, array $options ) {
55 $params = $this->getParamsFromSource( $options['source'] );
56 return $params[$name] ?? $default;
57 // @todo Should normalization to NFC UTF-8 be done here (much like in the
58 // action API and the rest of MW), or should it be left to handlers to
59 // do whatever normalization they need?
60 }
61
62 public function hasUpload( $name, array $options ) {
63 if ( $options['source'] !== 'post' ) {
64 return false;
65 }
66 return $this->getUploadedFile( $name, $options ) !== null;
67 }
68
69 public function getUploadedFile( $name, array $options ) {
70 if ( $options['source'] !== 'post' ) {
71 return null;
72 }
73 $upload = $this->request->getUploadedFiles()[$name] ?? null;
74 return $upload instanceof UploadedFileInterface ? $upload : null;
75 }
76
77 public function recordCondition(
78 DataMessageValue $message, $name, $value, array $settings, array $options
79 ) {
80 // @todo Figure out how to handle warnings
81 }
82
83 public function useHighLimits( array $options ) {
84 return $this->authority->isAllowed( 'apihighlimits' );
85 }
86
87}
getValue( $name, $default, array $options)
Fetch a value from the request.
getParamsFromSource( $source)
Get the raw parameters from a source in the request.
__construct(RequestInterface $request, Authority $authority)
hasParam( $name, array $options)
Test if a parameter exists in the request.
useHighLimits(array $options)
Indicate whether "high limits" should be used.
recordCondition(DataMessageValue $message, $name, $value, array $settings, array $options)
Record non-fatal conditions.
getUploadedFile( $name, array $options)
Fetch data for a file upload.
hasUpload( $name, array $options)
Test if a parameter exists as an upload in the request.
Value object representing a message for i18n with alternative machine-readable data.
This interface represents the authority associated the current execution context, such as a web reque...
Definition Authority.php:37
A request interface similar to PSR-7's ServerRequestInterface.
Interface defining callbacks needed by ParamValidator.
Definition Callbacks.php:21
$source