mirror of
https://github.com/flarum/core.git
synced 2025-08-04 23:47:32 +02:00
Frontend refactor (#1471)
Refactor Frontend + Asset code - Use Laravel's Filesystem component for asset IO, meaning theoretically assets should be storable on S3 etc. - More reliable checking for asset recompilation when debug mode is on, so you don't have to constantly delete the compiled assets to force a recompile. Should also fix issues with locale JS files being recompiled with the same name and cached. - Remove JavaScript minification, because it will be done by Webpack (exception is for the TextFormatter JS). - Add support for JS sourcemaps. - Separate frontend view and assets completely. This is an important distinction because frontend assets are compiled independent of a request, whereas putting together a view depends on a request. - Bind frontend view/asset factory instances to the container (in service providers) rather than subclassing. Asset and content populators can be added to these factories – these are simply objects that populate the asset compilers or the view with information. - Add RouteHandlerFactory functions that make it easy to hook up a frontend controller with a frontend instance ± some content. - Remove the need for "nojs" - Fix cache:clear command - Recompile assets when settings/enabled extensions change
This commit is contained in:
@@ -25,13 +25,13 @@ class ControllerRouteHandler
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
* @var string|callable
|
||||
*/
|
||||
protected $controller;
|
||||
|
||||
/**
|
||||
* @param Container $container
|
||||
* @param string $controller
|
||||
* @param string|callable $controller
|
||||
*/
|
||||
public function __construct(Container $container, $controller)
|
||||
{
|
||||
@@ -54,12 +54,16 @@ class ControllerRouteHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $class
|
||||
* @param string|callable $class
|
||||
* @return RequestHandlerInterface
|
||||
*/
|
||||
protected function resolveController($class)
|
||||
{
|
||||
$controller = $this->container->make($class);
|
||||
if (is_callable($class)) {
|
||||
$controller = $this->container->call($class);
|
||||
} else {
|
||||
$controller = $this->container->make($class);
|
||||
}
|
||||
|
||||
if (! ($controller instanceof RequestHandlerInterface)) {
|
||||
throw new InvalidArgumentException(
|
||||
|
@@ -46,6 +46,8 @@ class SetLocale implements Middleware
|
||||
$this->locales->setLocale($locale);
|
||||
}
|
||||
|
||||
$request = $request->withAttribute('locale', $this->locales->getLocale());
|
||||
|
||||
return $handler->handle($request);
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Flarum\Http;
|
||||
|
||||
use Flarum\Frontend\Controller as FrontendController;
|
||||
use Illuminate\Contracts\Container\Container;
|
||||
|
||||
class RouteHandlerFactory
|
||||
@@ -29,11 +30,47 @@ class RouteHandlerFactory
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $controller
|
||||
* @param string|callable $controller
|
||||
* @return ControllerRouteHandler
|
||||
*/
|
||||
public function toController($controller)
|
||||
{
|
||||
return new ControllerRouteHandler($this->container, $controller);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $frontend
|
||||
* @param string|null $content
|
||||
* @return ControllerRouteHandler
|
||||
*/
|
||||
public function toFrontend(string $frontend, string $content = null)
|
||||
{
|
||||
return $this->toController(function (Container $container) use ($frontend, $content) {
|
||||
$frontend = $container->make($frontend);
|
||||
|
||||
if ($content) {
|
||||
$frontend->add($container->make($content));
|
||||
}
|
||||
|
||||
return new FrontendController($frontend);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $content
|
||||
* @return ControllerRouteHandler
|
||||
*/
|
||||
public function toForum(string $content = null)
|
||||
{
|
||||
return $this->toFrontend('flarum.forum.frontend', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|null $content
|
||||
* @return ControllerRouteHandler
|
||||
*/
|
||||
public function toAdmin(string $content = null)
|
||||
{
|
||||
return $this->toFrontend('flarum.admin.frontend', $content);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user