MediaWiki master
|
A REST module represents a collection of endpoints. More...
Inherited by MediaWiki\Rest\Module\MatcherBasedModule.
Public Member Functions | |
__construct (Router $router, string $pathPrefix, ResponseFactory $responseFactory, BasicAuthorizerInterface $basicAuth, ObjectFactory $objectFactory, Validator $restValidator, ErrorReporter $errorReporter) | |
execute (string $path, RequestInterface $request) | |
Find the handler for a request and execute it. | |
getAllowedMethods (string $relPath) | |
Get the allowed methods for a path. | |
getCacheData () | |
Return data that can later be used to initialize a new instance of this module in a fast and efficient way. | |
getDefinedPaths () | |
getHandlerForPath (string $path, RequestInterface $request, bool $initForExecute=false) | |
Create a Handler for the given path, taking into account the request method. | |
getOpenApiInfo () | |
Return an array with data to be included in an OpenAPI "info" object describing this module. | |
getPathPrefix () | |
getRouter () | |
initFromCacheData (array $cacheData) | |
Initialize from the given cache data if possible. | |
setCors (CorsUtils $cors) | |
setStats (StatsFactory $stats) | |
Static Public Member Functions | |
static | loadJsonFile (string $fileName) |
Loads a module specification from a file. | |
Public Attributes | |
const | CACHE_CONFIG_HASH_KEY = 'CONFIG-HASH' |
Protected Member Functions | |
executeHandler (Handler $handler) | |
Execute a fully-constructed handler. | |
findHandlerMatch (string $path, string $requestMethod) | |
Determines which handler to use for the given path and returns an array describing the handler and initialization context. | |
instantiateHandlerObject (array $spec) | |
Creates a handler from the given spec, but does not initialize it. | |
throwNoMatch (string $path, string $method, array $allowed) | |
Implementations of getHandlerForPath() should call this method when they cannot handle the requested path. | |
Protected Attributes | |
string | $pathPrefix |
ResponseFactory | $responseFactory |
A REST module represents a collection of endpoints.
The module object is responsible for generating a response for a given request. This is typically done by routing requests to the appropriate request handler.
Definition at line 33 of file Module.php.
MediaWiki\Rest\Module\Module::__construct | ( | Router | $router, |
string | $pathPrefix, | ||
ResponseFactory | $responseFactory, | ||
BasicAuthorizerInterface | $basicAuth, | ||
ObjectFactory | $objectFactory, | ||
Validator | $restValidator, | ||
ErrorReporter | $errorReporter ) |
Router | $router | |
string | $pathPrefix | |
ResponseFactory | $responseFactory | |
BasicAuthorizerInterface | $basicAuth | |
ObjectFactory | $objectFactory | |
Validator | $restValidator | |
ErrorReporter | $errorReporter |
Definition at line 60 of file Module.php.
References MediaWiki\Rest\Module\Module\$pathPrefix, and MediaWiki\Rest\Module\Module\$responseFactory.
MediaWiki\Rest\Module\Module::execute | ( | string | $path, |
RequestInterface | $request ) |
Find the handler for a request and execute it.
Definition at line 262 of file Module.php.
|
protected |
Execute a fully-constructed handler.
HttpException |
Definition at line 365 of file Module.php.
|
abstractprotected |
Determines which handler to use for the given path and returns an array describing the handler and initialization context.
string | $path | |
string | $requestMethod |
handler
or spec
field must be set.Reimplemented in MediaWiki\Rest\Module\MatcherBasedModule.
|
abstract |
Get the allowed methods for a path.
Useful to check for 405 wrong method and for generating OpenAPI specs.
string | $relPath | A concrete request path. |
Reimplemented in MediaWiki\Rest\Module\MatcherBasedModule.
|
abstract |
Return data that can later be used to initialize a new instance of this module in a fast and efficient way.
Reimplemented in MediaWiki\Rest\Module\MatcherBasedModule.
|
abstract |
Reimplemented in MediaWiki\Rest\Module\ExtraRoutesModule, and MediaWiki\Rest\Module\SpecBasedModule.
MediaWiki\Rest\Module\Module::getHandlerForPath | ( | string | $path, |
RequestInterface | $request, | ||
bool | $initForExecute = false ) |
Create a Handler for the given path, taking into account the request method.
If $prepExecution is true, the handler's prepareForExecute() method will be called, which will call postInitSetup(). The $request object will be updated with any path parameters and parsed body data.
string | $path | |
RequestInterface | $request | The request to handle. If $forExecution is true, this will be updated with the path parameters and parsed body data as appropriate. |
bool | $initForExecute | Whether the handler and the request should be prepared for execution. Callers that only need the Handler object for access to meta-data should set this to false. |
HttpException | If no handler was found |
Definition at line 135 of file Module.php.
MediaWiki\Rest\Module\Module::getOpenApiInfo | ( | ) |
Return an array with data to be included in an OpenAPI "info" object describing this module.
Reimplemented in MediaWiki\Rest\Module\SpecBasedModule.
Definition at line 462 of file Module.php.
MediaWiki\Rest\Module\Module::getPathPrefix | ( | ) |
Definition at line 80 of file Module.php.
MediaWiki\Rest\Module\Module::getRouter | ( | ) |
Definition at line 189 of file Module.php.
|
abstract |
Initialize from the given cache data if possible.
This allows fast initialization based on data that was cached during a previous invocation of the module.
Implementations are responsible for verifying that the cache data matches the information provided to the constructor, to protect against a situation where configuration was updated in a way that affects the operation of the module.
array | $cacheData | Data generated by getCacheData(), implementations are free to choose the format. |
Reimplemented in MediaWiki\Rest\Module\MatcherBasedModule.
|
protected |
Creates a handler from the given spec, but does not initialize it.
Definition at line 351 of file Module.php.
|
static |
Loads a module specification from a file.
This method does not know or care about the structure of the file other than that it must be JSON and contain a list or map (that is, a JSON array or object).
string | $fileName |
ModuleConfigurationException |
Definition at line 436 of file Module.php.
MediaWiki\Rest\Module\Module::setCors | ( | CorsUtils | $cors | ) |
MediaWiki\Rest\Module\Module::setStats | ( | StatsFactory | $stats | ) |
StatsFactory | $stats |
Definition at line 416 of file Module.php.
|
protected |
Implementations of getHandlerForPath() should call this method when they cannot handle the requested path.
string | $path | The requested path |
string | $method | The HTTP method of the current request |
string[] | $allowed | The allowed HTTP methods allowed by the path |
HttpException |
Definition at line 232 of file Module.php.
|
protected |
Definition at line 40 of file Module.php.
Referenced by MediaWiki\Rest\Module\Module\__construct(), and MediaWiki\Rest\Module\SpecBasedModule\__construct().
|
protected |
Definition at line 41 of file Module.php.
Referenced by MediaWiki\Rest\Module\ExtraRoutesModule\__construct(), MediaWiki\Rest\Module\Module\__construct(), and MediaWiki\Rest\Module\SpecBasedModule\__construct().
const MediaWiki\Rest\Module\Module::CACHE_CONFIG_HASH_KEY = 'CONFIG-HASH' |
Definition at line 38 of file Module.php.