MediaWiki master
RedirectHandler.php
Go to the documentation of this file.
1<?php
2
3namespace MediaWiki\Rest\Handler;
4
5use MediaWiki\Config\ConfigException;
6use MediaWiki\Rest\Handler;
7use MediaWiki\Rest\Response;
8use MediaWiki\Rest\RouteDefinitionException;
9
30class RedirectHandler extends Handler {
31
36 public function execute() {
37 $path = $this->getConfig()['redirect']['path'] ?? '';
38 if ( $path === '' ) {
39 throw new RouteDefinitionException( 'No registered redirect for this path' );
40 }
41 $code = $this->getConfig()['redirect']['code'] ?? 308;
42 $pathParams = $this->getRequest()->getPathParams();
43 $queryParams = $this->getRequest()->getQueryParams();
44 $locationPath = $this->getRouter()->getRoutePath( $path, $pathParams, $queryParams );
45 $response = $this->getResponseFactory()->createRedirect( $locationPath, $code );
46 return $response;
47 }
48}
A generic redirect handler for the REST API.
getRequest()
Get the current request.
Definition Handler.php:371
getConfig()
Get the configuration array for the current route.
Definition Handler.php:397
getRouter()
Get the Router of the Module that this handler belongs to.
Definition Handler.php:291
getResponseFactory()
Get the ResponseFactory which can be used to generate Response objects.
Definition Handler.php:422
Copyright (C) 2011-2020 Wikimedia Foundation and others.