|
MediaWiki master
|
The REST router is responsible for gathering module configuration, matching an input path against the defined modules, and constructing and executing the relevant module for a request. More...
Public Member Functions | |
| __construct (private readonly ModuleManager $moduleManager, private readonly array $extraRoutes, private readonly ServiceOptions $options, private readonly BagOStuff $cacheBag, private readonly array $textFormatters, private readonly bool $showExceptionDetails, private readonly BasicAuthorizerInterface $basicAuth, private readonly Authority $authority, private readonly ObjectFactory $objectFactory, private readonly Validator $restValidator, private ErrorReporter $errorReporter, private readonly HookContainer $hookContainer, private readonly Session $session, private readonly UrlUtils $urlUtils, private readonly JsonLocalizer $jsonLocalizer,) | |
| execute (RequestInterface $request) | |
| getModule (string $name) | |
| Returns an uninitialized module by name. | |
| getModuleBaseUrl (string $moduleId) | |
| Gets the absolute base URL for a given module ID. | |
| getModuleForPath (string $fullPath) | |
| Returns an uninitialized module by full path. | |
| getModuleForRequest (RequestInterface $request, ?string $name) | |
| Returns a module suitable for handling the given request. | |
| getModuleIds () | |
| getModuleManager () | |
| getModuleResponseFactoryByName (string $moduleName, RequestInterface $request) | |
| Like getModuleResponseFactory(), but for the module with the given name: the ResponseFactory that module would use for this request, with the error format selected by the module's errorSchemaVersion or, if the request asks for it, the RESTBase-compatible format (see isRestbaseCompatEnabled()). | |
| getModuleSpecUrl (string $moduleId) | |
| Gets the absolute OpenAPI specification URL for a given module ID. | |
| getPrivateRouteUrl (string $pathWithModulePrefix, array $pathParams=[], array $queryParams=[]) | |
| getRoutePath (string $pathWithModulePrefix, array $pathParams=[], array $queryParams=[]) | |
| getRouteUrl (string $pathWithModulePrefix, array $pathParams=[], array $queryParams=[]) | |
| isRestbaseCompatEnabled (RequestInterface $request) | |
| prepareHandler (Handler $handler) | |
| Prepare the handler by injecting relevant service objects and state into $handler. | |
| setCors (CorsUtils $cors) | |
| setStats (StatsFactory $stats) | |
Static Public Member Functions | |
| static | substPathParams (string $route, array $pathParams) |
| Substitute parameters into a template string, following the requirements for path parameters: Spaces are encoded as %20 (not +) and slashes are encoded as %2F, other characters with special meaning are encoded as they would be for query parameters. | |
Public Attributes | |
| const | CONSTRUCTOR_OPTIONS |
| const | DEFAULT_ERROR_SCHEMA = '1.0' |
| const | ROUTE_MODULE_SPEC = '/specs/v0/module/{module}' |
The REST router is responsible for gathering module configuration, matching an input path against the defined modules, and constructing and executing the relevant module for a request.
Definition at line 34 of file Router.php.
| MediaWiki\Rest\Router::__construct | ( | private readonly ModuleManager | $moduleManager, |
| private readonly array | $extraRoutes, | ||
| private readonly ServiceOptions | $options, | ||
| private readonly BagOStuff | $cacheBag, | ||
| private readonly array | $textFormatters, | ||
| private readonly bool | $showExceptionDetails, | ||
| private readonly BasicAuthorizerInterface | $basicAuth, | ||
| private readonly Authority | $authority, | ||
| private readonly ObjectFactory | $objectFactory, | ||
| private readonly Validator | $restValidator, | ||
| private ErrorReporter | $errorReporter, | ||
| private readonly HookContainer | $hookContainer, | ||
| private readonly Session | $session, | ||
| private readonly UrlUtils | $urlUtils, | ||
| private readonly JsonLocalizer | $jsonLocalizer ) |
| ModuleManager | $moduleManager | |
| array[] | $extraRoutes | |
| ServiceOptions | $options | |
| BagOStuff | $cacheBag | A cache in which to store the matcher trees |
| array | $textFormatters | |
| bool | $showExceptionDetails | |
| BasicAuthorizerInterface | $basicAuth | |
| Authority | $authority | |
| ObjectFactory | $objectFactory | |
| Validator | $restValidator | |
| ErrorReporter | $errorReporter | |
| HookContainer | $hookContainer | |
| Session | $session | |
| UrlUtils | $urlUtils | |
| JsonLocalizer | $jsonLocalizer | Used to localize the spec of the modules it instantiates. |
Definition at line 111 of file Router.php.
References MediaWiki\MainConfigNames\CanonicalServer, MediaWiki\MainConfigNames\InternalServer, MediaWiki\MainConfigNames\RestPath, and MediaWiki\MainConfigNames\ScriptPath.
| MediaWiki\Rest\Router::execute | ( | RequestInterface | $request | ) |
Definition at line 569 of file Router.php.
| MediaWiki\Rest\Router::getModule | ( | string | $name | ) |
Returns an uninitialized module by name.
Definition at line 422 of file Router.php.
References if.
Referenced by getModuleForPath().
| MediaWiki\Rest\Router::getModuleBaseUrl | ( | string | $moduleId | ) |
Gets the absolute base URL for a given module ID.
For external modules, UrlUtils expands any relative URL. For local modules, the route URL is generated from the module ID.
| string | $moduleId | The module ID |
| UnexpectedValueException | If an external module has no base URL configured |
Definition at line 493 of file Router.php.
| MediaWiki\Rest\Router::getModuleForPath | ( | string | $fullPath | ) |
Returns an uninitialized module by full path.
Definition at line 373 of file Router.php.
References getModule(), and wfDeprecated().
| MediaWiki\Rest\Router::getModuleForRequest | ( | RequestInterface | $request, |
| ?string | $name ) |
Returns a module suitable for handling the given request.
| RequestInterface | $request | |
| string | null | $name | The module name, if known. Will be derived from $request if not given. |
Definition at line 390 of file Router.php.
| MediaWiki\Rest\Router::getModuleIds | ( | ) |
| MediaWiki\Rest\Router::getModuleManager | ( | ) |
| MediaWiki\Rest\Router::getModuleResponseFactoryByName | ( | string | $moduleName, |
| RequestInterface | $request ) |
Like getModuleResponseFactory(), but for the module with the given name: the ResponseFactory that module would use for this request, with the error format selected by the module's errorSchemaVersion or, if the request asks for it, the RESTBase-compatible format (see isRestbaseCompatEnabled()).
Definition at line 743 of file Router.php.
| MediaWiki\Rest\Router::getModuleSpecUrl | ( | string | $moduleId | ) |
Gets the absolute OpenAPI specification URL for a given module ID.
For external modules, UrlUtils expands the spec URL. For local modules, returns the default route URL defined by self::ROUTE_MODULE_SPEC.
| string | $moduleId | The module ID |
| UnexpectedValueException | If an external module has no spec URL configured |
Definition at line 523 of file Router.php.
| MediaWiki\Rest\Router::getPrivateRouteUrl | ( | string | $pathWithModulePrefix, |
| array | $pathParams = [], | ||
| array | $queryParams = [] ) |
Definition at line 474 of file Router.php.
References getRoutePath(), and return.
| MediaWiki\Rest\Router::getRoutePath | ( | string | $pathWithModulePrefix, |
| array | $pathParams = [], | ||
| array | $queryParams = [] ) |
Definition at line 456 of file Router.php.
References $path, substPathParams(), and wfAppendQuery().
Referenced by getPrivateRouteUrl(), and getRouteUrl().
| MediaWiki\Rest\Router::getRouteUrl | ( | string | $pathWithModulePrefix, |
| array | $pathParams = [], | ||
| array | $queryParams = [] ) |
Definition at line 466 of file Router.php.
References getRoutePath(), and return.
| MediaWiki\Rest\Router::isRestbaseCompatEnabled | ( | RequestInterface | $request | ) |
| MediaWiki\Rest\Router::prepareHandler | ( | Handler | $handler | ) |
Prepare the handler by injecting relevant service objects and state into $handler.
Definition at line 635 of file Router.php.
References MediaWiki\Rest\Handler\initServices(), and MediaWiki\Rest\Handler\initSession().
| MediaWiki\Rest\Router::setCors | ( | CorsUtils | $cors | ) |
Definition at line 646 of file Router.php.
| MediaWiki\Rest\Router::setStats | ( | StatsFactory | $stats | ) |
| StatsFactory | $stats |
Definition at line 659 of file Router.php.
|
static |
Substitute parameters into a template string, following the requirements for path parameters: Spaces are encoded as %20 (not +) and slashes are encoded as %2F, other characters with special meaning are encoded as they would be for query parameters.
| string | $route | A path with {placeholders} |
| array | $pathParams |
Definition at line 559 of file Router.php.
Referenced by getRoutePath().
| const MediaWiki\Rest\Router::CONSTRUCTOR_OPTIONS |
Definition at line 83 of file Router.php.
Referenced by MediaWiki\Rest\EntryPoint\createRouter().
| const MediaWiki\Rest\Router::DEFAULT_ERROR_SCHEMA = '1.0' |
Definition at line 39 of file Router.php.
| const MediaWiki\Rest\Router::ROUTE_MODULE_SPEC = '/specs/v0/module/{module}' |
Definition at line 35 of file Router.php.