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

chore: adapt test infra

This commit is contained in:
Sami Mazouz
2023-08-11 15:04:30 +01:00
parent cca5725fe4
commit 3b3efc7cbb
7 changed files with 61 additions and 57 deletions

View File

@@ -9,12 +9,12 @@
namespace Flarum\Foundation;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Foundation\Application as ApplicationContract;
use Symfony\Component\Console\Command\Command;
interface AppInterface
{
public function getContainer(): Container;
public function getContainer(): ApplicationContract;
public function getMiddlewareStack(): array;

View File

@@ -12,6 +12,7 @@ namespace Flarum\Foundation;
use Flarum\Foundation\Concerns\InteractsWithLaravel;
use Flarum\Http\RoutingServiceProvider;
use Illuminate\Container\Container as IlluminateContainer;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Foundation\Application as LaravelApplication;
use Illuminate\Events\EventServiceProvider;
use Illuminate\Support\Arr;
@@ -70,7 +71,7 @@ class Application extends IlluminateContainer implements LaravelApplication
IlluminateContainer::setInstance($this);
$this->instance('app', $this);
$this->instance('container', $this);
$this->instance(Container::class, $this);
$this->instance('flarum', $this);
$this->instance('flarum.paths', $this->paths);
}

View File

@@ -9,34 +9,29 @@
namespace Flarum\Foundation;
use Flarum\Http\Middleware as HttpMiddleware;
use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Console\Command;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Foundation\Application as ApplicationContract;
use Laminas\Stratigility\Middleware\OriginalMessages;
use Laminas\Stratigility\MiddlewarePipe;
use Middlewares\BasePath;
use Middlewares\BasePathRouter;
use Middlewares\RequestHandler;
use Psr\Http\Server\RequestHandlerInterface;
class InstalledApp implements AppInterface
{
public function __construct(
protected Container $container,
protected ApplicationContract $app,
protected Config $config
) {
}
public function getContainer(): Container
public function getContainer(): ApplicationContract
{
return $this->container;
return $this->app;
}
public function getMiddlewareStack(): array
{
// if ($this->config->inMaintenanceMode()) {
// return $this->container->make('flarum.maintenance.handler');
// return $this->app->make('flarum.maintenance.handler');
// }
return match ($this->needsUpdate()) {
@@ -47,7 +42,7 @@ class InstalledApp implements AppInterface
protected function needsUpdate(): bool
{
$settings = $this->container->make(SettingsRepositoryInterface::class);
$settings = $this->app->make(SettingsRepositoryInterface::class);
$version = $settings->get('version');
return $version !== Application::VERSION;
@@ -76,13 +71,13 @@ class InstalledApp implements AppInterface
public function getConsoleCommands(): array
{
return array_map(function ($command) {
$command = $this->container->make($command);
$command = $this->app->make($command);
if ($command instanceof Command) {
$command->setLaravel($this->container);
$command->setLaravel($this->app);
}
return $command;
}, $this->container->make('flarum.console.commands'));
}, $this->app->make('flarum.console.commands'));
}
}

View File

@@ -40,6 +40,7 @@ use Illuminate\Config\Repository as ConfigRepository;
use Illuminate\Contracts\Cache\Repository;
use Illuminate\Contracts\Cache\Store;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Foundation\Application as ApplicationContract;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Hashing\HashServiceProvider;
use Illuminate\Validation\ValidationServiceProvider;
@@ -87,7 +88,7 @@ class InstalledSite implements SiteInterface
return $this;
}
protected function bootLaravel(): Container
protected function bootLaravel(): ApplicationContract
{
$app = new Application($this->paths);

View File

@@ -13,30 +13,36 @@ use Flarum\Foundation\AppInterface;
use Flarum\Foundation\ErrorHandling\LogReporter;
use Flarum\Foundation\SiteInterface;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\Request;
use Illuminate\Routing\Pipeline;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Response;
use Throwable;
class Server
{
public function __construct(
private readonly SiteInterface $site
private readonly ?SiteInterface $site = null
) {
}
public function listen(): void
{
$request = Request::capture();
$siteApp = $this->safelyBoot();
$container = $siteApp->getContainer();
$app = $siteApp->getContainer();
$globalMiddleware = $siteApp->getMiddlewareStack();
(new Pipeline($container))
$this->send(Request::capture(), $app, $globalMiddleware);
}
public function send(Request $request, Application $app, array $globalMiddleware): Response
{
return (new Pipeline($app))
->send($request)
->through($globalMiddleware)
->then(function (Request $request) use ($container) {
return $container->make(Router::class)->dispatch($request);
->then(function (Request $request) use ($app) {
return $app->make(Router::class)->dispatch($request);
});
}