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.
return null;
}
+ /**
+ * Indicates whether this route requires read rights.
+ *
+ * The handler should override this if it does not need to read from the
+ * wiki. This is uncommon, but may be useful for login and other account
+ * management APIs.
+ *
+ * @return bool
+ */
+ public function needsReadAccess() {
+ return true;
+ }
+
+ /**
+ * Indicates whether this route requires write access.
+ *
+ * The handler should override this if the route does not need to write to
+ * the database.
+ *
+ * This should return true for routes that may require synchronous database writes.
+ * Modules that do not need such writes should also not rely on master database access,
+ * since only read queries are needed and each master DB is a single point of failure.
+ *
+ * @return bool
+ */
+ public function needsWriteAccess() {
+ return true;
+ }
+
/**
* Execute the handler. This is called after parameter validation. The
* return value can either be a Response or any type accepted by