MediaWiki 1.42.0
MediaWiki\Rest\Router Class Reference

The REST router is responsible for gathering handler configuration, matching an input path and HTTP method against the defined routes, and constructing and executing the relevant handler for a request. More...

Public Member Functions

 __construct ( $routeFiles, $extraRoutes, ServiceOptions $options, BagOStuff $cacheBag, ResponseFactory $responseFactory, BasicAuthorizerInterface $basicAuth, Authority $authority, ObjectFactory $objectFactory, Validator $restValidator, ErrorReporter $errorReporter, HookContainer $hookContainer, Session $session)
 
 execute (RequestInterface $request)
 Find the handler for a request and execute it.
 
 getAllRoutes ()
 Get an iterator for all defined routes, including loading the routes from the JSON files.
 
 getPrivateRouteUrl (string $route, array $pathParams=[], array $queryParams=[])
 Returns a full private URL for the given route.
 
 getRoutePath (string $route, array $pathParams=[], array $queryParams=[])
 Returns the path part of the route URL for the given route, including the root path.
 
 getRouteUrl (string $route, array $pathParams=[], array $queryParams=[])
 Returns a full URL for the given route.
 
 instantiateHandlerObject (array $spec)
 Creates a handler from the given spec, but does not initialize it.
 
 setCors (CorsUtils $cors)
 
 setStats (StatsdDataFactoryInterface $stats)
 

Protected Member Functions

 substPathParams (string $route, array $pathParams)
 

Detailed Description

The REST router is responsible for gathering handler configuration, matching an input path and HTTP method against the defined routes, and constructing and executing the relevant handler for a request.

Definition at line 28 of file Router.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Rest\Router::__construct ( $routeFiles,
$extraRoutes,
ServiceOptions $options,
BagOStuff $cacheBag,
ResponseFactory $responseFactory,
BasicAuthorizerInterface $basicAuth,
Authority $authority,
ObjectFactory $objectFactory,
Validator $restValidator,
ErrorReporter $errorReporter,
HookContainer $hookContainer,
Session $session )
Parameters
string[]$routeFilesList of names of JSON files containing routes
array$extraRoutesExtension route array
ServiceOptions$options
BagOStuff$cacheBagA cache in which to store the matcher trees
ResponseFactory$responseFactory
BasicAuthorizerInterface$basicAuth
Authority$authority
ObjectFactory$objectFactory
Validator$restValidator
ErrorReporter$errorReporter
HookContainer$hookContainer
Session$session
Access: internal

Definition at line 122 of file Router.php.

References MediaWiki\Config\ServiceOptions\assertRequiredOptions(), MediaWiki\MainConfigNames\CanonicalServer, MediaWiki\Config\ServiceOptions\get(), MediaWiki\MainConfigNames\InternalServer, and MediaWiki\MainConfigNames\RestPath.

Member Function Documentation

◆ execute()

MediaWiki\Rest\Router::execute ( RequestInterface $request)

Find the handler for a request and execute it.

Parameters
RequestInterface$request
Returns
ResponseInterface

Definition at line 390 of file Router.php.

References $path, MediaWiki\Rest\RequestInterface\getMethod(), MediaWiki\Rest\RequestInterface\getUri(), and MediaWiki\Rest\RequestInterface\setPathParams().

◆ getAllRoutes()

MediaWiki\Rest\Router::getAllRoutes ( )

Get an iterator for all defined routes, including loading the routes from the JSON files.

Stability: unstable
Returns
AppendIterator

Definition at line 238 of file Router.php.

◆ getPrivateRouteUrl()

MediaWiki\Rest\Router::getPrivateRouteUrl ( string $route,
array $pathParams = [],
array $queryParams = [] )

Returns a full private URL for the given route.

Private URLs are for use within the local subnet, they may use host names or ports or paths that are not publicly accessible. Intended for use in redirects and when including links to endpoints in output.

Note
Only private endpoints should use this method for redirects or links to include on the response! Public endpoints should not expose the URLs of private endpoints to the public!
Since
1.39
See also
getRouteUrl
Parameters
string$route
array$pathParams
array$queryParams
Returns
string

Definition at line 359 of file Router.php.

◆ getRoutePath()

MediaWiki\Rest\Router::getRoutePath ( string $route,
array $pathParams = [],
array $queryParams = [] )

Returns the path part of the route URL for the given route, including the root path.

Intended for use in relative redirects.

Since
1.42
Parameters
string$route
array$pathParams
array$queryParams
Returns
string
See also
getPrivateRouteUrl

Definition at line 310 of file Router.php.

◆ getRouteUrl()

MediaWiki\Rest\Router::getRouteUrl ( string $route,
array $pathParams = [],
array $queryParams = [] )

Returns a full URL for the given route.

Intended for use in redirects and when including links to endpoints in output.

Parameters
string$route
array$pathParams
array$queryParams
Returns
string
See also
getPrivateRouteUrl

Definition at line 332 of file Router.php.

◆ instantiateHandlerObject()

MediaWiki\Rest\Router::instantiateHandlerObject ( array $spec)

Creates a handler from the given spec, but does not initialize it.

Parameters
array$spec
Returns
Handler

Definition at line 519 of file Router.php.

◆ setCors()

MediaWiki\Rest\Router::setCors ( CorsUtils $cors)
Parameters
CorsUtils$cors
Returns
self

Definition at line 582 of file Router.php.

◆ setStats()

MediaWiki\Rest\Router::setStats ( StatsdDataFactoryInterface $stats)
Parameters
StatsdDataFactoryInterface$stats
Returns
self

Definition at line 593 of file Router.php.

◆ substPathParams()

MediaWiki\Rest\Router::substPathParams ( string $route,
array $pathParams )
protected
Parameters
string$route
array$pathParams
Returns
string

Definition at line 373 of file Router.php.


The documentation for this class was generated from the following file: