27 private ?
Router $router =
null;
48 $conf = $services->getMainConfig();
54 ->addAuthorizer( $cors );
57 $restValidator =
new Validator( $objectFactory,
71 $moduleManager->getRouteFiles(),
72 ExtensionRegistry::getInstance()->getAttribute(
'RestRoutes' ),
93 static $mainRequest = null;
95 if ( $mainRequest ===
null ) {
108 $context = RequestContext::getMain();
112 MWExceptionRenderer::shouldShowExceptionDetails()
117 CorsUtils::CONSTRUCTOR_OPTIONS,
118 $this->getServiceContainer()->getMainConfig()
124 if ( !$this->router ) {
125 $this->router = $this->createRouter(
126 $this->getServiceContainer(),
140 private function getTextFormatters() {
141 $services = $this->getServiceContainer();
144 $langs = array_unique( [ $code,
'en' ] );
145 $textFormatters = [];
148 foreach ( $langs as $lang ) {
149 $textFormatters[] = $factory->getTextFormatter( $lang );
152 return $textFormatters;
161 parent::__construct( $context, $environment, $mediaWikiServices );
163 $this->request = $request;
171 $this->router = $router;
175 $this->startOutputBuffer();
179 $response = $this->cors->modifyResponse(
181 $this->router->execute( $this->request )
184 $webResponse = $this->getResponse();
186 $webResponse->header(
187 'HTTP/' . $response->getProtocolVersion() .
' ' . $response->getStatusCode() .
' ' .
188 $response->getReasonPhrase()
191 foreach ( $response->getRawHeaderLines() as $line ) {
192 $webResponse->header( $line );
195 foreach ( $response->getCookies() as $cookie ) {
196 $webResponse->setCookie(
205 $this->discardOutputBuffer();
207 $stream = $response->getBody();
210 $this->prepareForOutput();
213 $stream->copyToStream( fopen(
'php://output',
'w' ) );
216 $buffer = $stream->read( 65536 );
217 if ( $buffer ===
'' ) {
220 $this->print( $buffer );
Group all the pieces relevant to the context of a request into one instance.
Utility class wrapping PHP runtime state.
A class containing constants representing the names of configuration variables.
const CookiePrefix
Name constant for the CookiePrefix setting, for use with Config::get()
Base class for entry point handlers.
doSetup()
Perform any setup needed before execute() is called.
setRouter(Router $router)
Sets the router to use.
__construct(RequestInterface $request, RequestContext $context, EntryPointEnvironment $environment, MediaWikiServices $mediaWikiServices)
execute()
Subclasses implement the entry point's functionality by overriding this method.
static createRouter(MediaWikiServices $services, IContextSource $context, RequestInterface $request, ResponseFactory $responseFactory, CorsUtils $cors)
Interface for objects which can provide a MediaWiki context on request.