MediaWiki REL1_35
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...

Collaboration diagram for MediaWiki\Rest\Router:

Public Member Functions

 __construct ( $routeFiles, $extraRoutes, $baseUrl, $rootPath, BagOStuff $cacheBag, ResponseFactory $responseFactory, BasicAuthorizerInterface $basicAuth, ObjectFactory $objectFactory, Validator $restValidator, HookContainer $hookContainer=null)
 
 execute (RequestInterface $request)
 Find the handler for a request and execute it.
 
 getRouteUrl ( $route, $pathParams=[], $queryParams=[])
 Returns a full URL for the given route.
 

Private Member Functions

 createHandler (RequestInterface $request, array $spec)
 Create a handler from its spec.
 
 executeHandler ( $handler)
 Execute a fully-constructed handler.
 
 fetchCacheData ()
 Get the cache data, or false if it is missing or invalid.
 
 getAllRoutes ()
 Get an iterator for all defined routes, including loading the routes from the JSON files.
 
 getCacheKey ()
 
 getConfigHash ()
 Get a config version hash for cache invalidation.
 
 getMatchers ()
 Get an array of PathMatcher objects indexed by HTTP method.
 
 getRelativePath ( $path)
 Remove the path prefix $this->rootPath.
 
 getRouteFileTimestamps ()
 Get an array of last modification times of the defined route files.
 
 getRoutesFromFiles ()
 Load the defined JSON files and return the merged routes.
 

Private Attributes

string $baseUrl
 
BasicAuthorizerInterface $basicAuth
 
BagOStuff $cacheBag
 
string null $configHash
 
array $extraRoutes
 
HookContainer $hookContainer
 
PathMatcher[] null $matchers
 Path matchers by method.
 
ObjectFactory $objectFactory
 
ResponseFactory $responseFactory
 
Validator $restValidator
 
string $rootPath
 
string[] $routeFiles
 
int[] null $routeFileTimestamps
 
array null $routesFromFiles
 

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 20 of file Router.php.

Constructor & Destructor Documentation

◆ __construct()

Member Function Documentation

◆ createHandler()

MediaWiki\Rest\Router::createHandler ( RequestInterface  $request,
array  $spec 
)
private

Create a handler from its spec.

Parameters
RequestInterface$request
array$spec
Returns
Handler

Definition at line 332 of file Router.php.

Referenced by MediaWiki\Rest\Router\execute().

◆ execute()

◆ executeHandler()

MediaWiki\Rest\Router::executeHandler (   $handler)
private

Execute a fully-constructed handler.

Parameters
Handler$handler
Returns
ResponseInterface

Definition at line 348 of file Router.php.

Referenced by MediaWiki\Rest\Router\execute().

◆ fetchCacheData()

MediaWiki\Rest\Router::fetchCacheData ( )
private

Get the cache data, or false if it is missing or invalid.

Returns
bool|array

Definition at line 103 of file Router.php.

References MediaWiki\Rest\Router\getCacheKey(), and MediaWiki\Rest\Router\getConfigHash().

Referenced by MediaWiki\Rest\Router\getMatchers().

◆ getAllRoutes()

MediaWiki\Rest\Router::getAllRoutes ( )
private

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

Returns
AppendIterator

Definition at line 177 of file Router.php.

References MediaWiki\Rest\Router\getRoutesFromFiles().

Referenced by MediaWiki\Rest\Router\getMatchers().

◆ getCacheKey()

MediaWiki\Rest\Router::getCacheKey ( )
private
Returns
string The cache key

Definition at line 116 of file Router.php.

Referenced by MediaWiki\Rest\Router\fetchCacheData(), and MediaWiki\Rest\Router\getMatchers().

◆ getConfigHash()

MediaWiki\Rest\Router::getConfigHash ( )
private

Get a config version hash for cache invalidation.

Returns
string

Definition at line 125 of file Router.php.

References MediaWiki\Rest\Router\$configHash, and MediaWiki\Rest\Router\getRouteFileTimestamps().

Referenced by MediaWiki\Rest\Router\fetchCacheData(), and MediaWiki\Rest\Router\getMatchers().

◆ getMatchers()

◆ getRelativePath()

MediaWiki\Rest\Router::getRelativePath (   $path)
private

Remove the path prefix $this->rootPath.

Return the part of the path with the prefix removed, or false if the prefix did not match.

Parameters
string$path
Returns
false|string

Definition at line 229 of file Router.php.

References $path.

Referenced by MediaWiki\Rest\Router\execute().

◆ getRouteFileTimestamps()

MediaWiki\Rest\Router::getRouteFileTimestamps ( )
private

Get an array of last modification times of the defined route files.

Returns
int[] Last modification times

Definition at line 161 of file Router.php.

References MediaWiki\Rest\Router\$routeFileTimestamps.

Referenced by MediaWiki\Rest\Router\getConfigHash().

◆ getRoutesFromFiles()

MediaWiki\Rest\Router::getRoutesFromFiles ( )
private

Load the defined JSON files and return the merged routes.

Returns
array

Definition at line 140 of file Router.php.

References MediaWiki\Rest\Router\$routesFromFiles.

Referenced by MediaWiki\Rest\Router\getAllRoutes().

◆ getRouteUrl()

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

Returns a full URL for the given route.

Intended for use in redirects.

Parameters
string$route
array$pathParams
array$queryParams
Returns
false|string

Definition at line 248 of file Router.php.

References wfAppendQuery().

Member Data Documentation

◆ $baseUrl

string MediaWiki\Rest\Router::$baseUrl
private

Definition at line 34 of file Router.php.

Referenced by MediaWiki\Rest\Router\__construct().

◆ $basicAuth

BasicAuthorizerInterface MediaWiki\Rest\Router::$basicAuth
private

Definition at line 52 of file Router.php.

Referenced by MediaWiki\Rest\Router\__construct().

◆ $cacheBag

BagOStuff MediaWiki\Rest\Router::$cacheBag
private

Definition at line 40 of file Router.php.

Referenced by MediaWiki\Rest\Router\__construct().

◆ $configHash

string null MediaWiki\Rest\Router::$configHash
private

Definition at line 46 of file Router.php.

Referenced by MediaWiki\Rest\Router\getConfigHash().

◆ $extraRoutes

array MediaWiki\Rest\Router::$extraRoutes
private

Definition at line 25 of file Router.php.

Referenced by MediaWiki\Rest\Router\__construct().

◆ $hookContainer

HookContainer MediaWiki\Rest\Router::$hookContainer
private

Definition at line 61 of file Router.php.

Referenced by MediaWiki\Rest\Router\__construct().

◆ $matchers

PathMatcher [] null MediaWiki\Rest\Router::$matchers
private

Path matchers by method.

Definition at line 43 of file Router.php.

Referenced by MediaWiki\Rest\Router\execute(), and MediaWiki\Rest\Router\getMatchers().

◆ $objectFactory

ObjectFactory MediaWiki\Rest\Router::$objectFactory
private

Definition at line 55 of file Router.php.

Referenced by MediaWiki\Rest\Router\__construct().

◆ $responseFactory

ResponseFactory MediaWiki\Rest\Router::$responseFactory
private

Definition at line 49 of file Router.php.

Referenced by MediaWiki\Rest\Router\__construct().

◆ $restValidator

Validator MediaWiki\Rest\Router::$restValidator
private

Definition at line 58 of file Router.php.

Referenced by MediaWiki\Rest\Router\__construct().

◆ $rootPath

string MediaWiki\Rest\Router::$rootPath
private

Definition at line 37 of file Router.php.

Referenced by MediaWiki\Rest\Router\__construct().

◆ $routeFiles

string [] MediaWiki\Rest\Router::$routeFiles
private

Definition at line 22 of file Router.php.

Referenced by MediaWiki\Rest\Router\__construct().

◆ $routeFileTimestamps

int [] null MediaWiki\Rest\Router::$routeFileTimestamps
private

Definition at line 31 of file Router.php.

Referenced by MediaWiki\Rest\Router\getRouteFileTimestamps().

◆ $routesFromFiles

array null MediaWiki\Rest\Router::$routesFromFiles
private

Definition at line 28 of file Router.php.

Referenced by MediaWiki\Rest\Router\getRoutesFromFiles().


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