Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
RedirectHandler
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 execute
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
2
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
10/**
11 * A generic redirect handler for the REST API
12 * @package MediaWiki\Rest\Handler
13 */
14class RedirectHandler extends Handler {
15
16    /**
17     * @return Response
18     * @throws ConfigException
19     */
20    public function execute() {
21        $path = $this->getConfig()['redirect']['path'] ?? '';
22        if ( $path === '' ) {
23            throw new RouteDefinitionException( 'No registered redirect for this path' );
24        }
25        $code = $this->getConfig()['redirect']['code'] ?? 308;
26        $pathParams = $this->getRequest()->getPathParams();
27        $queryParams = $this->getRequest()->getQueryParams();
28        $locationPath = $this->getRouter()->getRoutePath( $path, $pathParams, $queryParams );
29        $response = $this->getResponseFactory()->createRedirect( $locationPath, $code );
30        return $response;
31    }
32}