1
0
mirror of https://github.com/flarum/core.git synced 2025-08-07 08:56:38 +02:00

Allow easier extensibility of page document

This allows extensions to:

- mutate the json api document sent with php documents
- override/interact with the Document

Right now extensions need to replace the complete Frontend class
in order to interact with the document. Let's abstract into ioc
so that advanced devs can interact with it.
This commit is contained in:
Daniel Klabbers
2021-06-28 11:36:03 +02:00
parent e92c267cde
commit 838d9c5106
2 changed files with 15 additions and 1 deletions

View File

@@ -49,7 +49,9 @@ class Frontend
{
$forumDocument = $this->getForumDocument($request);
$document = new Document($this->view, $forumDocument, $request);
$responseDocument = resolve('flarum.frontend.document');
$document = $responseDocument($forumDocument, $request);
$this->populate($document, $request);

View File

@@ -16,6 +16,8 @@ use Flarum\Http\UrlGenerator;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\View\Factory as ViewFactory;
use Illuminate\View\Factory;
use Psr\Http\Message\ServerRequestInterface as Request;
class FrontendServiceProvider extends AbstractServiceProvider
{
@@ -57,6 +59,16 @@ class FrontendServiceProvider extends AbstractServiceProvider
return $frontend;
};
});
$this->container->singleton('flarum.frontend.document', function (Container $container) {
return function (array $apiDocument, Request $request) use ($container){
return new Document(
$container->make(Factory::class),
$apiDocument,
$request
);
};
});
}
/**