54 $mparams = array_merge( [
56 'url' =>
'http://localhost:7231/',
57 'domain' =>
'localhost',
59 'forwardCookies' =>
false,
61 'parsoidCompat' =>
false,
66 if ( substr( $mparams[
'url'], -1 ) !==
'/' ) {
67 $mparams[
'url'] .=
'/';
72 $mparams[
'domain'] = preg_replace(
73 '/^((https?:)?\/\/)?([^\/:]+?)(:\d+)?\/?$/',
78 parent::__construct( $mparams );
85 public function onRequests( array $reqs, Closure $idGenFunc ) {
86 if ( $this->params[
'parsoidCompat'] ) {
91 foreach ( $reqs as $key => $req ) {
92 if ( $this->params[
'fixedUrl'] ) {
93 $version = explode(
'/', $req[
'url'] )[1];
95 str_replace(
'#version#', $version, $this->params[
'url'] ) .
96 preg_replace(
'#^local/v./#',
'', $req[
'url'] );
99 $req[
'url'] = preg_replace(
'#^local/#', $this->params[
'domain'] .
'/', $req[
'url'] );
101 $req[
'url'] = $this->params[
'url'] . $req[
'url'];
105 if ( $this->params[
'HTTPProxy'] ) {
106 $req[
'proxy'] = $this->params[
'HTTPProxy'];
108 if ( $this->params[
'timeout'] !=
null ) {
109 $req[
'reqTimeout'] = $this->params[
'timeout'];
111 if ( $this->params[
'forwardCookies'] ) {
112 $req[
'headers'][
'Cookie'] = $this->params[
'forwardCookies'];
114 $result[$key] = $req;
129 foreach ( $reqs as $key => $req ) {
130 $version = explode(
'/', $req[
'url'] )[1];
131 if ( $version ===
'v3' ) {
134 throw new Exception(
"Only Parsoid v3 is supported." );
160 $parts = explode(
'/', $req[
'url'] );
161 [ $targetWiki, $version, ] = $parts;
162 if ( $targetWiki !==
'local' ) {
163 throw new Exception(
"Only 'local' target wiki is currently supported" );
164 } elseif ( $version !==
'v3' ) {
165 throw new Exception(
"Version mismatch: should not happen." );
168 $req[
'url'] = preg_replace(
'#^local/v3/#', $this->params[
'domain'] .
'/v1/', $req[
'url'] );
170 $req[
'url'] = $this->params[
'url'] . $req[
'url'];
172 if ( $this->params[
'HTTPProxy'] ) {
173 $req[
'proxy'] = $this->params[
'HTTPProxy'];
175 if ( $this->params[
'timeout'] !=
null ) {
176 $req[
'reqTimeout'] = $this->params[
'timeout'];
178 if ( $this->params[
'forwardCookies'] ) {
179 $req[
'headers'][
'Cookie'] = $this->params[
'forwardCookies'];
Virtual HTTP service client for RESTBase.
onRequests(array $reqs, Closure $idGenFunc)
Prepare virtual HTTP(S) requests (for this service) for execution.This method should mangle any of th...
onParsoidRequests(array $reqs, Closure $idGeneratorFunc)
Remaps Parsoid v3 requests to RESTBase v1 requests.
onParsoid3Request(array $req, Closure $idGeneratorFunc)
Remap a Parsoid v3 request to a RESTBase v1 request.
__construct(array $params)
Example RESTBase v1 requests: GET /local/v1/page/html/{title}{/revision} POST /local/v1/transform/htm...
Virtual HTTP service instance that can be mounted on to a VirtualRESTService.
array $params
Key/value map.