Merge "language: Move some language-related classes to includes/language/"
[lhc/web/wiklou.git] / includes / Rest / EntryPoint.php
index d5924f0..795999a 100644 (file)
@@ -6,8 +6,16 @@ use ExtensionRegistry;
 use MediaWiki\MediaWikiServices;
 use RequestContext;
 use Title;
+use WebResponse;
 
 class EntryPoint {
+       /** @var RequestInterface */
+       private $request;
+       /** @var WebResponse */
+       private $webResponse;
+       /** @var Router */
+       private $router;
+
        public static function main() {
                // URL safety checks
                global $wgRequest;
@@ -21,8 +29,8 @@ class EntryPoint {
                RequestContext::getMain()->setTitle( $wgTitle );
 
                $services = MediaWikiServices::getInstance();
-
                $conf = $services->getMainConfig();
+
                $request = new RequestFromGlobals( [
                        'cookiePrefix' => $conf->get( 'CookiePrefix' )
                ] );
@@ -36,20 +44,35 @@ class EntryPoint {
                        new ResponseFactory
                );
 
-               $response = $router->execute( $request );
+               $entryPoint = new self(
+                       $request,
+                       $wgRequest->response(),
+                       $router );
+               $entryPoint->execute();
+       }
+
+       public function __construct( RequestInterface $request, WebResponse $webResponse,
+               Router $router
+       ) {
+               $this->request = $request;
+               $this->webResponse = $webResponse;
+               $this->router = $router;
+       }
+
+       public function execute() {
+               $response = $this->router->execute( $this->request );
 
-               $webResponse = $wgRequest->response();
-               $webResponse->header(
+               $this->webResponse->header(
                        'HTTP/' . $response->getProtocolVersion() . ' ' .
                        $response->getStatusCode() . ' ' .
                        $response->getReasonPhrase() );
 
                foreach ( $response->getRawHeaderLines() as $line ) {
-                       $webResponse->header( $line );
+                       $this->webResponse->header( $line );
                }
 
                foreach ( $response->getCookies() as $cookie ) {
-                       $webResponse->setCookie(
+                       $this->webResponse->setCookie(
                                $cookie['name'],
                                $cookie['value'],
                                $cookie['expiry'],