1
0
mirror of https://github.com/flarum/core.git synced 2025-10-14 08:24:28 +02:00

Refactor the web app bootstrapping code

- All custom JS variables are now preloaded into the `app.data` object, rather than directly on the `app` object. This means that admin settings are available in `app.data.settings` rather than `app.settings`, etc.
- Cleaner route handler generation
- Renamed ConfigureClientView to ConfigureWebApp, though the former still exists and is deprecated
- Partial fix for #881 (strips ?nojs=1 from URL if possible, so that refreshing will attempt to load JS version again)
This commit is contained in:
Toby Zerner
2016-05-26 19:04:24 +09:30
parent 2525e3e7ad
commit 9bfb797fdc
49 changed files with 1575 additions and 1254 deletions

View File

@@ -0,0 +1,71 @@
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Http\Handler;
use Flarum\Http\Controller\ControllerInterface;
use Illuminate\Contracts\Container\Container;
use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
class ControllerRouteHandler
{
/**
* @var Container
*/
protected $container;
/**
* @var string
*/
protected $controller;
/**
* @param Container $container
* @param string $controller
*/
public function __construct(Container $container, $controller)
{
$this->container = $container;
$this->controller = $controller;
}
/**
* @param ServerRequestInterface $request
* @param array $routeParams
* @return ResponseInterface
*/
public function __invoke(ServerRequestInterface $request, array $routeParams)
{
$controller = $this->resolveController($this->controller);
$request = $request->withQueryParams(array_merge($request->getQueryParams(), $routeParams));
return $controller->handle($request);
}
/**
* @param string $class
* @return ControllerInterface
*/
protected function resolveController($class)
{
$controller = $this->container->make($class);
if (! ($controller instanceof ControllerInterface)) {
throw new InvalidArgumentException(
'Controller must be an instance of '.ControllerInterface::class
);
}
return $controller;
}
}

View File

@@ -0,0 +1,38 @@
<?php
/*
* This file is part of Flarum.
*
* (c) Toby Zerner <toby.zerner@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Flarum\Http\Handler;
use Illuminate\Contracts\Container\Container;
class RouteHandlerFactory
{
/**
* @var Container
*/
protected $container;
/**
* @param Container $container
*/
public function __construct(Container $container)
{
$this->container = $container;
}
/**
* @param string $controller
* @return ControllerRouteHandler
*/
public function toController($controller)
{
return new ControllerRouteHandler($this->container, $controller);
}
}