53 $mparams = array_merge( [
55 'url' =>
'http://localhost:7231/',
56 'domain' =>
'localhost',
58 'forwardCookies' =>
false,
60 'parsoidCompat' =>
false,
64 if ( substr( $mparams[
'url'], -1 ) !==
'/' ) {
65 $mparams[
'url'] .=
'/';
70 $mparams[
'domain'] = preg_replace(
71 '/^(https?:\/\/)?([^\/:]+?)(:\d+)?\/?$/',
75 parent::__construct( $mparams );
78 public function onRequests( array $reqs, Closure $idGenFunc ) {
79 if ( $this->params[
'parsoidCompat'] ) {
84 foreach ( $reqs as $key => $req ) {
85 if ( $this->params[
'fixedUrl'] ) {
86 $version = explode(
'/', $req[
'url'] )[1];
88 str_replace(
'#version#', $version, $this->params[
'url'] ) .
89 preg_replace(
'#^local/v./#',
'', $req[
'url'] );
92 $req[
'url'] = preg_replace(
'#^local/#', $this->params[
'domain'] .
'/', $req[
'url'] );
94 $req[
'url'] = $this->params[
'url'] . $req[
'url'];
98 if ( $this->params[
'HTTPProxy'] ) {
99 $req[
'proxy'] = $this->params[
'HTTPProxy'];
101 if ( $this->params[
'timeout'] !=
null ) {
102 $req[
'reqTimeout'] = $this->params[
'timeout'];
104 if ( $this->params[
'forwardCookies'] ) {
105 $req[
'headers'][
'Cookie'] = $this->params[
'forwardCookies'];
107 $result[$key] = $req;
122 foreach ( $reqs as $key => $req ) {
123 $version = explode(
'/', $req[
'url'] )[1];
124 if ( $version ===
'v3' ) {
127 throw new Exception(
"Only Parsoid v3 is supported." );
153 $parts = explode(
'/', $req[
'url'] );
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.
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.