MediaWiki  master
VirtualRESTService.php
Go to the documentation of this file.
1 <?php
36 abstract 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 }
VirtualRESTService\onResponses
onResponses(array $reqs, Closure $idGeneratorFunc)
Mangle or replace virtual HTTP(S) requests which have been responded to.
Definition: VirtualRESTService.php:114
VirtualRESTService\__construct
__construct(array $params)
Definition: VirtualRESTService.php:43
VirtualRESTService\getName
getName()
Return the name of this service, in a form suitable for error reporting or debugging.
Definition: VirtualRESTService.php:53
VirtualRESTService\onRequests
onRequests(array $reqs, Closure $idGeneratorFunc)
Prepare virtual HTTP(S) requests (for this service) for execution.
Definition: VirtualRESTService.php:79
VirtualRESTService
Virtual HTTP service instance that can be mounted on to a VirtualRESTService.
Definition: VirtualRESTService.php:36
VirtualRESTService\$params
array $params
Key/value map.
Definition: VirtualRESTService.php:38