Merge branch 'master' into 1236-database-changes

This commit is contained in:
Daniël Klabbers 2018-06-03 21:51:01 +02:00
commit 26b02adc9d
No known key found for this signature in database
GPG Key ID: 823B3D5DDF3FBAB6
40 changed files with 221 additions and 198 deletions

View File

@ -1,19 +1,34 @@
language: php
sudo: false
env:
- DB_USERNAME=travis
services:
- mysql
global:
- DB=mariadb
addons:
mariadb: '10.2'
php:
- 7.0
- 7.1
- 7.2
matrix:
fast_finish: true
include:
- php: 7.1
addons: # to prevent mariadb
services: mysql
env:
- DB=mysql
- php: 7.2
addons: # to prevent mariadb
services: mysql
env:
- DB=mysql
before_install:
- mysql -e 'CREATE DATABASE flarum;'
before_script:
- composer self-update
- composer install
@ -27,5 +42,3 @@ notifications:
after_success:
- bash <(curl -s https://codecov.io/bash)
sudo: false

View File

@ -20,10 +20,10 @@
"docs": "http://flarum.org/docs"
},
"require": {
"php": ">=7.0",
"php": ">=7.1",
"components/font-awesome": "^5.0.6",
"dflydev/fig-cookies": "^1.0.2",
"doctrine/dbal": "^2.5",
"components/font-awesome": "^5.0.6",
"franzl/whoops-middleware": "^0.4.0",
"illuminate/bus": "5.5.*",
"illuminate/cache": "5.5.*",
@ -47,16 +47,17 @@
"nikic/fast-route": "^0.6",
"oyejorge/less.php": "~1.5",
"psr/http-message": "^1.0",
"psr/http-server-handler": "^1.0",
"psr/http-server-middleware": "^1.0",
"s9e/text-formatter": "^0.8.1",
"symfony/config": "^3.3",
"symfony/console": "^3.3",
"symfony/http-foundation": "^3.3",
"symfony/translation": "^3.3",
"symfony/yaml": "^3.3",
"s9e/text-formatter": "^0.8.1",
"tobscure/json-api": "^0.3.0",
"zendframework/zend-diactoros": "^1.6",
"zendframework/zend-stratigility": "^2.2",
"http-interop/http-middleware": "^0.4.0"
"zendframework/zend-diactoros": "^1.7",
"zendframework/zend-stratigility": "^3.0"
},
"require-dev": {
"mockery/mockery": "^0.9.4",
@ -75,6 +76,9 @@
"Flarum\\Tests\\": "tests/"
}
},
"config": {
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "0.1.x-dev"

View File

@ -19,4 +19,9 @@
<exclude>./tests/Install</exclude>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
</phpunit>

View File

@ -12,18 +12,19 @@
namespace Flarum\Admin\Middleware;
use Flarum\User\AssertPermissionTrait;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as Handler;
class RequireAdministrateAbility implements MiddlewareInterface
class RequireAdministrateAbility implements Middleware
{
use AssertPermissionTrait;
public function process(Request $request, DelegateInterface $delegate)
public function process(Request $request, Handler $handler): Response
{
$this->assertAdmin($request->getAttribute('actor'));
return $delegate->process($request);
return $handler->handle($request);
}
}

View File

@ -13,10 +13,10 @@ namespace Flarum\Api;
use Exception;
use Flarum\Foundation\Application;
use Flarum\Http\Controller\ControllerInterface;
use Flarum\User\User;
use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\ServerRequestFactory;
class Client
@ -43,7 +43,7 @@ class Client
/**
* Execute the given API action class, pass the input and return its response.
*
* @param string|ControllerInterface $controller
* @param string|RequestHandlerInterface $controller
* @param User|null $actor
* @param array $queryParams
* @param array $body
@ -60,9 +60,9 @@ class Client
$controller = $this->app->make($controller);
}
if (! ($controller instanceof ControllerInterface)) {
if (! ($controller instanceof RequestHandlerInterface)) {
throw new InvalidArgumentException(
'Endpoint must be an instance of '.ControllerInterface::class
'Endpoint must be an instance of '.RequestHandlerInterface::class
);
}

View File

@ -11,6 +11,7 @@
namespace Flarum\Api\Controller;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
abstract class AbstractCreateController extends AbstractShowController
@ -18,7 +19,7 @@ abstract class AbstractCreateController extends AbstractShowController
/**
* {@inheritdoc}
*/
public function handle(ServerRequestInterface $request)
public function handle(ServerRequestInterface $request): ResponseInterface
{
return parent::handle($request)->withStatus(201);
}

View File

@ -11,16 +11,17 @@
namespace Flarum\Api\Controller;
use Flarum\Http\Controller\ControllerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\EmptyResponse;
abstract class AbstractDeleteController implements ControllerInterface
abstract class AbstractDeleteController implements RequestHandlerInterface
{
/**
* {@inheritdoc}
*/
public function handle(ServerRequestInterface $request)
public function handle(ServerRequestInterface $request): ResponseInterface
{
$this->delete($request);

View File

@ -14,15 +14,16 @@ namespace Flarum\Api\Controller;
use Flarum\Api\Event\WillGetData;
use Flarum\Api\Event\WillSerializeData;
use Flarum\Api\JsonApiResponse;
use Flarum\Http\Controller\ControllerInterface;
use Illuminate\Contracts\Container\Container;
use Illuminate\Contracts\Events\Dispatcher;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Tobscure\JsonApi\Document;
use Tobscure\JsonApi\Parameters;
use Tobscure\JsonApi\SerializerInterface;
abstract class AbstractSerializeController implements ControllerInterface
abstract class AbstractSerializeController implements RequestHandlerInterface
{
/**
* The name of the serializer class to output results with.
@ -86,7 +87,7 @@ abstract class AbstractSerializeController implements ControllerInterface
/**
* {@inheritdoc}
*/
public function handle(ServerRequestInterface $request)
public function handle(ServerRequestInterface $request): ResponseInterface
{
$document = new Document;

View File

@ -11,14 +11,15 @@
namespace Flarum\Api\Controller;
use Flarum\Http\Controller\ControllerInterface;
use Flarum\User\Command\RequestPasswordReset;
use Flarum\User\UserRepository;
use Illuminate\Contracts\Bus\Dispatcher;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\EmptyResponse;
class ForgotPasswordController implements ControllerInterface
class ForgotPasswordController implements RequestHandlerInterface
{
/**
* @var \Flarum\User\UserRepository
@ -43,7 +44,7 @@ class ForgotPasswordController implements ControllerInterface
/**
* {@inheritdoc}
*/
public function handle(ServerRequestInterface $request)
public function handle(ServerRequestInterface $request): ResponseInterface
{
$email = array_get($request->getParsedBody(), 'email');

View File

@ -11,7 +11,6 @@
namespace Flarum\Api\Controller;
use Flarum\Http\Controller\ControllerInterface;
use Flarum\Http\UrlGenerator;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\AssertPermissionTrait;
@ -19,11 +18,13 @@ use Flarum\User\EmailToken;
use Flarum\User\Exception\PermissionDeniedException;
use Illuminate\Contracts\Mail\Mailer;
use Illuminate\Mail\Message;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Zend\Diactoros\Response\EmptyResponse;
class SendConfirmationEmailController implements ControllerInterface
class SendConfirmationEmailController implements RequestHandlerInterface
{
use AssertPermissionTrait;
@ -64,7 +65,7 @@ class SendConfirmationEmailController implements ControllerInterface
/**
* {@inheritdoc}
*/
public function handle(ServerRequestInterface $request)
public function handle(ServerRequestInterface $request): ResponseInterface
{
$id = array_get($request->getQueryParams(), 'id');
$actor = $request->getAttribute('actor');

View File

@ -12,19 +12,20 @@
namespace Flarum\Api\Controller;
use Flarum\Group\Permission;
use Flarum\Http\Controller\ControllerInterface;
use Flarum\User\AssertPermissionTrait;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\EmptyResponse;
class SetPermissionController implements ControllerInterface
class SetPermissionController implements RequestHandlerInterface
{
use AssertPermissionTrait;
/**
* {@inheritdoc}
*/
public function handle(ServerRequestInterface $request)
public function handle(ServerRequestInterface $request): ResponseInterface
{
$this->assertAdmin($request->getAttribute('actor'));

View File

@ -11,16 +11,17 @@
namespace Flarum\Api\Controller;
use Flarum\Http\Controller\ControllerInterface;
use Flarum\Settings\Event\Saved;
use Flarum\Settings\Event\Serializing;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\AssertPermissionTrait;
use Illuminate\Contracts\Events\Dispatcher;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\EmptyResponse;
class SetSettingsController implements ControllerInterface
class SetSettingsController implements RequestHandlerInterface
{
use AssertPermissionTrait;
@ -46,7 +47,7 @@ class SetSettingsController implements ControllerInterface
/**
* {@inheritdoc}
*/
public function handle(ServerRequestInterface $request)
public function handle(ServerRequestInterface $request): ResponseInterface
{
$this->assertAdmin($request->getAttribute('actor'));

View File

@ -12,15 +12,16 @@
namespace Flarum\Api\Controller;
use Flarum\Http\AccessToken;
use Flarum\Http\Controller\ControllerInterface;
use Flarum\User\Exception\PermissionDeniedException;
use Flarum\User\UserRepository;
use Illuminate\Contracts\Bus\Dispatcher as BusDispatcher;
use Illuminate\Contracts\Events\Dispatcher as EventDispatcher;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\JsonResponse;
class TokenController implements ControllerInterface
class TokenController implements RequestHandlerInterface
{
/**
* @var \Flarum\User\UserRepository
@ -52,7 +53,7 @@ class TokenController implements ControllerInterface
/**
* {@inheritdoc}
*/
public function handle(ServerRequestInterface $request)
public function handle(ServerRequestInterface $request): ResponseInterface
{
$body = $request->getParsedBody();

View File

@ -12,12 +12,13 @@
namespace Flarum\Api\Controller;
use Flarum\Extension\ExtensionManager;
use Flarum\Http\Controller\ControllerInterface;
use Flarum\User\AssertPermissionTrait;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\EmptyResponse;
class UpdateExtensionController implements ControllerInterface
class UpdateExtensionController implements RequestHandlerInterface
{
use AssertPermissionTrait;
@ -37,7 +38,7 @@ class UpdateExtensionController implements ControllerInterface
/**
* {@inheritdoc}
*/
public function handle(ServerRequestInterface $request)
public function handle(ServerRequestInterface $request): ResponseInterface
{
$this->assertAdmin($request->getAttribute('actor'));

View File

@ -11,15 +11,16 @@
namespace Flarum\Api\Middleware;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as Handler;
class FakeHttpMethods implements MiddlewareInterface
class FakeHttpMethods implements Middleware
{
const HEADER_NAME = 'x-http-method-override';
public function process(Request $request, DelegateInterface $delegate)
public function process(Request $request, Handler $handler): Response
{
if ($request->getMethod() === 'POST' && $request->hasHeader(self::HEADER_NAME)) {
$fakeMethod = $request->getHeaderLine(self::HEADER_NAME);
@ -27,6 +28,6 @@ class FakeHttpMethods implements MiddlewareInterface
$request = $request->withMethod(strtoupper($fakeMethod));
}
return $delegate->process($request);
return $handler->handle($request);
}
}

View File

@ -13,12 +13,12 @@ namespace Flarum\Api\Middleware;
use Exception;
use Flarum\Api\ErrorHandler;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as Handler;
class HandleErrors implements MiddlewareInterface
class HandleErrors implements Middleware
{
/**
* @var ErrorHandler
@ -35,15 +35,11 @@ class HandleErrors implements MiddlewareInterface
/**
* Catch all errors that happen during further middleware execution.
*
* @param Request $request
* @param DelegateInterface $delegate
* @return Response
*/
public function process(Request $request, DelegateInterface $delegate)
public function process(Request $request, Handler $handler): Response
{
try {
return $delegate->process($request);
return $handler->handle($request);
} catch (Exception $e) {
return $this->errorHandler->handle($e);
}

View File

@ -12,12 +12,13 @@
namespace Flarum\Forum\Controller;
use Flarum\Forum\AuthenticationResponseFactory;
use Flarum\Http\Controller\ControllerInterface;
use League\OAuth2\Client\Provider\ResourceOwnerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\RedirectResponse;
abstract class AbstractOAuth2Controller implements ControllerInterface
abstract class AbstractOAuth2Controller implements RequestHandlerInterface
{
/**
* @var AuthenticationResponseFactory
@ -46,9 +47,9 @@ abstract class AbstractOAuth2Controller implements ControllerInterface
/**
* @param Request $request
* @return \Psr\Http\Message\ResponseInterface|RedirectResponse
* @return ResponseInterface
*/
public function handle(Request $request)
public function handle(Request $request): ResponseInterface
{
$redirectUri = (string) $request->getAttribute('originalUri', $request->getUri())->withQuery('');

View File

@ -12,16 +12,17 @@
namespace Flarum\Forum\Controller;
use Flarum\Foundation\Application;
use Flarum\Http\Controller\ControllerInterface;
use Flarum\Http\SessionAuthenticator;
use Flarum\User\Command\ConfirmEmail;
use Flarum\User\Exception\InvalidConfirmationTokenException;
use Illuminate\Contracts\Bus\Dispatcher;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\HtmlResponse;
use Zend\Diactoros\Response\RedirectResponse;
class ConfirmEmailController implements ControllerInterface
class ConfirmEmailController implements RequestHandlerInterface
{
/**
* @var Dispatcher
@ -52,9 +53,9 @@ class ConfirmEmailController implements ControllerInterface
/**
* @param Request $request
* @return \Psr\Http\Message\ResponseInterface
* @return ResponseInterface
*/
public function handle(Request $request)
public function handle(Request $request): ResponseInterface
{
try {
$token = array_get($request->getQueryParams(), 'token');

View File

@ -14,14 +14,15 @@ namespace Flarum\Forum\Controller;
use Flarum\Api\Client;
use Flarum\Api\Controller\TokenController;
use Flarum\Http\AccessToken;
use Flarum\Http\Controller\ControllerInterface;
use Flarum\Http\Rememberer;
use Flarum\Http\SessionAuthenticator;
use Flarum\User\Event\LoggedIn;
use Flarum\User\UserRepository;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface;
class LogInController implements ControllerInterface
class LogInController implements RequestHandlerInterface
{
/**
* @var \Flarum\User\UserRepository
@ -60,7 +61,7 @@ class LogInController implements ControllerInterface
/**
* {@inheritdoc}
*/
public function handle(Request $request)
public function handle(Request $request): ResponseInterface
{
$actor = $request->getAttribute('actor');
$body = $request->getParsedBody();

View File

@ -12,7 +12,6 @@
namespace Flarum\Forum\Controller;
use Flarum\Foundation\Application;
use Flarum\Http\Controller\ControllerInterface;
use Flarum\Http\Exception\TokenMismatchException;
use Flarum\Http\Rememberer;
use Flarum\Http\SessionAuthenticator;
@ -21,11 +20,13 @@ use Flarum\User\AssertPermissionTrait;
use Flarum\User\Event\LoggedOut;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\View\Factory;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\HtmlResponse;
use Zend\Diactoros\Response\RedirectResponse;
class LogOutController implements ControllerInterface
class LogOutController implements RequestHandlerInterface
{
use AssertPermissionTrait;
@ -85,10 +86,10 @@ class LogOutController implements ControllerInterface
/**
* @param Request $request
* @return \Psr\Http\Message\ResponseInterface
* @return ResponseInterface
* @throws TokenMismatchException
*/
public function handle(Request $request)
public function handle(Request $request): ResponseInterface
{
$session = $request->getAttribute('session');
$actor = $request->getAttribute('actor');

View File

@ -13,12 +13,13 @@ namespace Flarum\Forum\Controller;
use Flarum\Api\Client;
use Flarum\Api\Controller\CreateUserController;
use Flarum\Http\Controller\ControllerInterface;
use Flarum\Http\Rememberer;
use Flarum\Http\SessionAuthenticator;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface;
class RegisterController implements ControllerInterface
class RegisterController implements RequestHandlerInterface
{
/**
* @var Client
@ -50,7 +51,7 @@ class RegisterController implements ControllerInterface
/**
* {@inheritdoc}
*/
public function handle(Request $request)
public function handle(Request $request): ResponseInterface
{
$controller = CreateUserController::class;
$actor = $request->getAttribute('actor');

View File

@ -12,7 +12,6 @@
namespace Flarum\Forum\Controller;
use Flarum\Foundation\DispatchEventsTrait;
use Flarum\Http\Controller\ControllerInterface;
use Flarum\Http\SessionAuthenticator;
use Flarum\Http\UrlGenerator;
use Flarum\User\PasswordToken;
@ -20,10 +19,12 @@ use Flarum\User\UserValidator;
use Illuminate\Contracts\Events\Dispatcher;
use Illuminate\Contracts\Validation\Factory;
use Illuminate\Validation\ValidationException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\RedirectResponse;
class SavePasswordController implements ControllerInterface
class SavePasswordController implements RequestHandlerInterface
{
use DispatchEventsTrait;
@ -64,9 +65,9 @@ class SavePasswordController implements ControllerInterface
/**
* @param Request $request
* @return RedirectResponse
* @return ResponseInterface
*/
public function handle(Request $request)
public function handle(Request $request): ResponseInterface
{
$input = $request->getParsedBody();

View File

@ -12,16 +12,18 @@
namespace Flarum\Http\Controller;
use Illuminate\Contracts\Support\Renderable;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface;
use Zend\Diactoros\Response\HtmlResponse;
abstract class AbstractHtmlController implements ControllerInterface
abstract class AbstractHtmlController implements RequestHandlerInterface
{
/**
* @param Request $request
* @return HtmlResponse
*/
public function handle(Request $request)
public function handle(Request $request): ResponseInterface
{
$view = $this->render($request);

View File

@ -1,23 +0,0 @@
<?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\Controller;
use Psr\Http\Message\ServerRequestInterface;
interface ControllerInterface
{
/**
* @param ServerRequestInterface $request
* @return \Psr\Http\Message\ResponseInterface
*/
public function handle(ServerRequestInterface $request);
}

View File

@ -11,11 +11,11 @@
namespace Flarum\Http;
use Flarum\Http\Controller\ControllerInterface;
use Illuminate\Contracts\Container\Container;
use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
class ControllerRouteHandler
{
@ -55,15 +55,15 @@ class ControllerRouteHandler
/**
* @param string $class
* @return ControllerInterface
* @return RequestHandlerInterface
*/
protected function resolveController($class)
{
$controller = $this->container->make($class);
if (! ($controller instanceof ControllerInterface)) {
if (! ($controller instanceof RequestHandlerInterface)) {
throw new InvalidArgumentException(
'Controller must be an instance of '.ControllerInterface::class
'Controller must be an instance of '.RequestHandlerInterface::class
);
}

View File

@ -14,15 +14,16 @@ namespace Flarum\Http\Middleware;
use Flarum\Api\ApiKey;
use Flarum\Http\AccessToken;
use Flarum\User\User;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as Handler;
class AuthenticateWithHeader implements MiddlewareInterface
class AuthenticateWithHeader implements Middleware
{
const TOKEN_PREFIX = 'Token ';
public function process(Request $request, DelegateInterface $delegate)
public function process(Request $request, Handler $handler): Response
{
$headerLine = $request->getHeaderLine('authorization');
@ -50,7 +51,7 @@ class AuthenticateWithHeader implements MiddlewareInterface
}
}
return $delegate->process($request);
return $handler->handle($request);
}
private function getUser($string)

View File

@ -14,13 +14,14 @@ namespace Flarum\Http\Middleware;
use Flarum\User\Guest;
use Flarum\User\User;
use Illuminate\Contracts\Session\Session;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as Handler;
class AuthenticateWithSession implements MiddlewareInterface
class AuthenticateWithSession implements Middleware
{
public function process(Request $request, DelegateInterface $delegate)
public function process(Request $request, Handler $handler): Response
{
$session = $request->getAttribute('session');
@ -30,7 +31,7 @@ class AuthenticateWithSession implements MiddlewareInterface
$request = $request->withAttribute('actor', $actor);
return $delegate->process($request);
return $handler->handle($request);
}
private function getActor(Session $session)

View File

@ -17,12 +17,13 @@ use Flarum\User\AuthToken;
use Flarum\User\EmailToken;
use Flarum\User\PasswordToken;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as Handler;
use SessionHandlerInterface;
class CollectGarbage implements MiddlewareInterface
class CollectGarbage implements Middleware
{
/**
* @var SessionHandlerInterface
@ -40,11 +41,11 @@ class CollectGarbage implements MiddlewareInterface
$this->sessionConfig = $config->get('session');
}
public function process(Request $request, DelegateInterface $delegate)
public function process(Request $request, Handler $handler): Response
{
$this->collectGarbageSometimes();
return $delegate->process($request);
return $handler->handle($request);
}
private function collectGarbageSometimes()

View File

@ -15,12 +15,12 @@ use FastRoute\Dispatcher;
use Flarum\Http\Exception\MethodNotAllowedException;
use Flarum\Http\Exception\RouteNotFoundException;
use Flarum\Http\RouteCollection;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as Handler;
class DispatchRoute implements MiddlewareInterface
class DispatchRoute implements Middleware
{
/**
* @var RouteCollection
@ -45,13 +45,10 @@ class DispatchRoute implements MiddlewareInterface
/**
* Dispatch the given request to our route collection.
*
* @param Request $request
* @param DelegateInterface $delegate
* @return Response
* @throws MethodNotAllowedException
* @throws RouteNotFoundException
*/
public function process(Request $request, DelegateInterface $delegate)
public function process(Request $request, Handler $handler): Response
{
$method = $request->getMethod();
$uri = $request->getUri()->getPath() ?: '/';

View File

@ -15,15 +15,15 @@ use Exception;
use Flarum\Settings\SettingsRepositoryInterface;
use Franzl\Middleware\Whoops\WhoopsRunner;
use Illuminate\Contracts\View\Factory as ViewFactory;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as Handler;
use Psr\Log\LoggerInterface;
use Symfony\Component\Translation\TranslatorInterface;
use Zend\Diactoros\Response\HtmlResponse;
class HandleErrors implements MiddlewareInterface
class HandleErrors implements Middleware
{
/**
* @var ViewFactory
@ -68,15 +68,11 @@ class HandleErrors implements MiddlewareInterface
/**
* Catch all errors that happen during further middleware execution.
*
* @param Request $request
* @param DelegateInterface $delegate
* @return Response
*/
public function process(Request $request, DelegateInterface $delegate)
public function process(Request $request, Handler $handler): Response
{
try {
return $delegate->process($request);
return $handler->handle($request);
} catch (Exception $e) {
if ($this->debug) {
return WhoopsRunner::handle($e, $request);

View File

@ -11,13 +11,14 @@
namespace Flarum\Http\Middleware;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as Handler;
class ParseJsonBody implements MiddlewareInterface
class ParseJsonBody implements Middleware
{
public function process(Request $request, DelegateInterface $delegate)
public function process(Request $request, Handler $handler): Response
{
if (str_contains($request->getHeaderLine('content-type'), 'json')) {
$input = json_decode($request->getBody(), true);
@ -25,6 +26,6 @@ class ParseJsonBody implements MiddlewareInterface
$request = $request->withParsedBody($input ?: []);
}
return $delegate->process($request);
return $handler->handle($request);
}
}

View File

@ -13,11 +13,12 @@ namespace Flarum\Http\Middleware;
use Flarum\Http\AccessToken;
use Flarum\Http\CookieFactory;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as Handler;
class RememberFromCookie implements MiddlewareInterface
class RememberFromCookie implements Middleware
{
/**
* @var CookieFactory
@ -32,7 +33,7 @@ class RememberFromCookie implements MiddlewareInterface
$this->cookie = $cookie;
}
public function process(Request $request, DelegateInterface $delegate)
public function process(Request $request, Handler $handler): Response
{
$id = array_get($request->getCookieParams(), $this->cookie->getName('remember'));
@ -48,6 +49,6 @@ class RememberFromCookie implements MiddlewareInterface
}
}
return $delegate->process($request);
return $handler->handle($request);
}
}

View File

@ -12,11 +12,12 @@
namespace Flarum\Http\Middleware;
use Flarum\Locale\LocaleManager;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as Handler;
class SetLocale implements MiddlewareInterface
class SetLocale implements Middleware
{
/**
* @var LocaleManager
@ -31,7 +32,7 @@ class SetLocale implements MiddlewareInterface
$this->locales = $locales;
}
public function process(Request $request, DelegateInterface $delegate)
public function process(Request $request, Handler $handler): Response
{
$actor = $request->getAttribute('actor');
@ -45,6 +46,6 @@ class SetLocale implements MiddlewareInterface
$this->locales->setLocale($locale);
}
return $delegate->process($request);
return $handler->handle($request);
}
}

View File

@ -13,16 +13,17 @@ namespace Flarum\Http\Middleware;
use Illuminate\Contracts\View\Factory as ViewFactory;
use Illuminate\Support\ViewErrorBag;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as Handler;
/**
* Inspired by Illuminate\View\Middleware\ShareErrorsFromSession.
*
* @author Taylor Otwell
*/
class ShareErrorsFromSession implements MiddlewareInterface
class ShareErrorsFromSession implements Middleware
{
/**
* @var ViewFactory
@ -37,7 +38,7 @@ class ShareErrorsFromSession implements MiddlewareInterface
$this->view = $view;
}
public function process(Request $request, DelegateInterface $delegate)
public function process(Request $request, Handler $handler): Response
{
$session = $request->getAttribute('session');
@ -54,6 +55,6 @@ class ShareErrorsFromSession implements MiddlewareInterface
$session->remove('errors');
return $delegate->process($request);
return $handler->handle($request);
}
}

View File

@ -16,13 +16,13 @@ use Flarum\Http\CookieFactory;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Illuminate\Contracts\Session\Session;
use Illuminate\Session\Store;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as Handler;
use SessionHandlerInterface;
class StartSession implements MiddlewareInterface
class StartSession implements Middleware
{
/**
* @var SessionHandlerInterface
@ -51,7 +51,7 @@ class StartSession implements MiddlewareInterface
$this->config = $config->get('session');
}
public function process(Request $request, DelegateInterface $delegate)
public function process(Request $request, Handler $handler): Response
{
$request = $request->withAttribute(
'session',
@ -59,7 +59,7 @@ class StartSession implements MiddlewareInterface
);
$session->start();
$response = $delegate->process($request);
$response = $handler->handle($request);
$session->save();
$response = $this->withCsrfTokenHeader($response, $session);

View File

@ -18,16 +18,17 @@ use Flarum\Http\Middleware\HandleErrors;
use Flarum\Http\Middleware\StartSession;
use Flarum\Install\InstallServiceProvider;
use Flarum\Update\UpdateServiceProvider;
use Interop\Http\ServerMiddleware\MiddlewareInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface as Handler;
use Zend\Diactoros\Response\HtmlResponse;
use Zend\Diactoros\Server as DiactorosServer;
use Zend\Stratigility\MiddlewarePipe;
use Zend\Stratigility\NoopFinalHandler;
use function Zend\Stratigility\middleware;
use function Zend\Stratigility\path;
class Server
class Server implements Middleware, Handler
{
/**
* @param Site $site
@ -46,33 +47,38 @@ class Server
public function listen()
{
DiactorosServer::createServer(
$this,
[$this, 'handle'],
$_SERVER,
$_GET,
$_POST,
$_COOKIE,
$_FILES
)->listen(new NoopFinalHandler());
)->listen();
}
/**
* Use as PSR-7 middleware.
*
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable $out
* @return ResponseInterface
* Use as PSR-15 middleware.
*/
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $out)
public function process(Request $request, Handler $handler): Response
{
$middleware = $this->getMiddleware($request->getUri()->getPath());
return $middleware($request, $response, $out);
return $middleware->process($request, $handler);
}
/**
* Use as PSR-15 request handler.
*/
public function handle(Request $request): Response
{
$middleware = $this->getMiddleware($request->getUri()->getPath());
return $middleware->handle($request);
}
/**
* @param string $requestPath
* @return MiddlewareInterface
* @return MiddlewarePipe
*/
protected function getMiddleware($requestPath)
{
@ -126,9 +132,9 @@ class Server
protected function getMaintenanceMiddleware(MiddlewarePipe $pipe)
{
$pipe->pipe(function () {
$pipe->pipe(middleware(function () {
return new HtmlResponse(file_get_contents($this->getErrorDir().'/503.html', 503));
});
}));
// TODO: FOR API render JSON-API error document for HTTP 503

View File

@ -12,17 +12,18 @@
namespace Flarum\Install\Controller;
use Exception;
use Flarum\Http\Controller\ControllerInterface;
use Flarum\Http\SessionAuthenticator;
use Flarum\Install\Console\DefaultsDataProvider;
use Flarum\Install\Console\InstallCommand;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\StreamOutput;
use Zend\Diactoros\Response;
use Zend\Diactoros\Response\HtmlResponse;
class InstallController implements ControllerInterface
class InstallController implements RequestHandlerInterface
{
protected $command;
@ -44,9 +45,9 @@ class InstallController implements ControllerInterface
/**
* @param Request $request
* @return \Psr\Http\Message\ResponseInterface
* @return ResponseInterface
*/
public function handle(Request $request)
public function handle(Request $request): ResponseInterface
{
$input = $request->getParsedBody();

View File

@ -14,14 +14,15 @@ namespace Flarum\Update\Controller;
use Exception;
use Flarum\Database\Console\MigrateCommand;
use Flarum\Foundation\Application;
use Flarum\Http\Controller\ControllerInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\StreamOutput;
use Zend\Diactoros\Response;
use Zend\Diactoros\Response\HtmlResponse;
class UpdateController implements ControllerInterface
class UpdateController implements RequestHandlerInterface
{
protected $command;
@ -42,9 +43,9 @@ class UpdateController implements ControllerInterface
/**
* @param Request $request
* @return \Psr\Http\Message\ResponseInterface
* @return ResponseInterface
*/
public function handle(Request $request)
public function handle(Request $request): ResponseInterface
{
$input = $request->getParsedBody();

View File

@ -11,16 +11,16 @@
namespace Flarum\Tests\Api\Controller;
use Flarum\Http\Controller\ControllerInterface;
use Flarum\Tests\Test\TestCase;
use Flarum\User\User;
use Illuminate\Support\Arr;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Server\RequestHandlerInterface;
abstract class ApiControllerTestCase extends TestCase
{
/**
* @var ControllerInterface
* @var RequestHandlerInterface
*/
protected $controller;

View File

@ -75,9 +75,10 @@ trait CreatesForum
$data->setSetting('mail_driver', 'log');
$database = $data->getDatabaseConfiguration();
$database['database'] = env('DB_DATABASE', 'flarum');
$database['username'] = env('DB_USERNAME', 'root');
$database['password'] = env('DB_PASSWORD', '');
$database['host'] = env('DB_HOST', $database['host']);
$database['database'] = env('DB_DATABASE', $database['database']);
$database['username'] = env('DB_USERNAME', $database['username']);
$database['password'] = env('DB_PASSWORD', $database['password']);
$data->setDatabaseConfiguration($database);
$this->configuration = $data;