MediaWiki REL1_35
VirtualRESTService.php
Go to the documentation of this file.
1<?php
36abstract class VirtualRESTService {
38 protected $params = [];
39
43 public function __construct( array $params ) {
44 $this->params = $params;
45 }
46
53 public function getName() {
54 return $this->params['name'] ?? static::class;
55 }
56
79 public function onRequests( array $reqs, Closure $idGeneratorFunc ) {
80 $result = [];
81 foreach ( $reqs as $key => $req ) {
82 // The default encoding treats the URL as a REST style path that uses
83 // forward slash as a hierarchical delimiter (and never otherwise).
84 // Subclasses can override this, and should be documented in any case.
85 $parts = array_map( 'rawurlencode', explode( '/', $req['url'] ) );
86 $req['url'] = $this->params['baseUrl'] . '/' . implode( '/', $parts );
87 $result[$key] = $req;
88 }
89 return $result;
90 }
91
114 public function onResponses( array $reqs, Closure $idGeneratorFunc ) {
115 return $reqs;
116 }
117}
Virtual HTTP service instance that can be mounted on to a VirtualRESTService.
array $params
Key/value map.
onResponses(array $reqs, Closure $idGeneratorFunc)
Mangle or replace virtual HTTP(S) requests which have been responded to.
__construct(array $params)
onRequests(array $reqs, Closure $idGeneratorFunc)
Prepare virtual HTTP(S) requests (for this service) for execution.
getName()
Return the name of this service, in a form suitable for error reporting or debugging.