namespace MediaWiki\Rest;
abstract class Handler {
+ /** @var Router */
+ private $router;
+
/** @var RequestInterface */
private $request;
/**
* Initialise with dependencies from the Router. This is called after construction.
+ * @internal
*/
- public function init( RequestInterface $request, array $config,
+ public function init( Router $router, RequestInterface $request, array $config,
ResponseFactory $responseFactory
) {
+ $this->router = $router;
$this->request = $request;
$this->config = $config;
$this->responseFactory = $responseFactory;
}
+ /**
+ * Get the Router. The return type declaration causes it to raise
+ * a fatal error if init() has not yet been called.
+ */
+ protected function getRouter(): Router {
+ return $this->router;
+ }
+
/**
* Get the current request. The return type declaration causes it to raise
* a fatal error if init() has not yet been called.
$spec = $match['userData'];
$objectFactorySpec = array_intersect_key( $spec,
[ 'factory' => true, 'class' => true, 'args' => true ] );
+ /** @var $handler Handler (annotation for PHPStorm) */
$handler = ObjectFactory::getObjectFromSpec( $objectFactorySpec );
- $handler->init( $request, $spec, $this->responseFactory );
+ $handler->init( $this, $request, $spec, $this->responseFactory );
try {
return $this->executeHandler( $handler );