Skip to content

Commit

Permalink
Merge pull request #3 from databox/feature/php-8
Browse files Browse the repository at this point in the history
Feature/php 8
  • Loading branch information
fuzin authored Feb 6, 2023
2 parents 46be2fd + 398fe76 commit 83048cd
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 77 deletions.
36 changes: 5 additions & 31 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,14 @@
}
],
"require": {
"php": ">=7.1.3",
"php": ">=8.2.0",
"pimple/pimple": "^3.0",
"symfony/event-dispatcher": "^3.0|^4.0|^5.0",
"symfony/http-foundation": "^3.0|^4.0|^5.0",
"symfony/http-kernel": "^3.0|^4.0|^5.0",
"symfony/routing": "^3.0|^4.0|^5.0"
"symfony/event-dispatcher": "6.1.*",
"symfony/http-foundation": "5.*",
"symfony/http-kernel": "5.*",
"symfony/routing": "5.*"
},
"require-dev": {
"symfony/asset": "^4.0|^5.0",
"symfony/expression-language": "^4.0|^5.0",
"symfony/security": "^4.0|^5.0",
"symfony/config": "^4.0|^5.0",
"symfony/form": "^4.0|^5.0",
"symfony/browser-kit": "^4.0|^5.0",
"symfony/css-selector": "^4.0|^5.0",
"symfony/debug": "^4.0|^5.0",
"symfony/dom-crawler": "^4.0|^5.0",
"symfony/finder": "^4.0|^5.0",
"symfony/intl": "^4.0|^5.0",
"symfony/monolog-bridge": "^4.0|^5.0",
"symfony/doctrine-bridge": "^4.0|^5.0",
"symfony/options-resolver": "^4.0|^5.0",
"symfony/phpunit-bridge": "^3.2",
"symfony/process": "^4.0|^5.0",
"symfony/serializer": "^4.0|^5.0",
"symfony/translation": "^4.0|^5.0",
"symfony/twig-bridge": "^4.0|^5.0",
"symfony/validator": "^4.0|^5.0",
"symfony/var-dumper": "^4.0|^5.0",
"twig/twig": "^2.0",
"doctrine/dbal": "^2.2",
"swiftmailer/swiftmailer": "^5",
"monolog/monolog": "^1.4.1",
"symfony/web-link": "^4.0|^5.0"
},
"replace": {
"silex/api": "self.version",
Expand Down
4 changes: 2 additions & 2 deletions src/Silex/AppArgumentValueResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public function __construct(Application $app)
/**
* {@inheritdoc}
*/
public function supports(Request $request, ArgumentMetadata $argument)
public function supports(Request $request, ArgumentMetadata $argument): bool
{
return null !== $argument->getType() && (Application::class === $argument->getType() || is_subclass_of($argument->getType(), Application::class));
}

/**
* {@inheritdoc}
*/
public function resolve(Request $request, ArgumentMetadata $argument)
public function resolve(Request $request, ArgumentMetadata $argument): iterable
{
yield $this->app;
}
Expand Down
15 changes: 8 additions & 7 deletions src/Silex/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
use Pimple\ServiceProviderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\Event\TerminateEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\TerminableInterface;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\PostResponseEvent;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -246,7 +246,8 @@ public function before($callback, $priority = 0)
{
$app = $this;

$this->on(KernelEvents::REQUEST, function (GetResponseEvent $event) use ($callback, $app) {
$this->on(KernelEvents::REQUEST, function (RequestEvent $event) use ($callback, $app) {

if (!$event->isMasterRequest()) {
return;
}
Expand All @@ -272,7 +273,7 @@ public function after($callback, $priority = 0)
{
$app = $this;

$this->on(KernelEvents::RESPONSE, function (FilterResponseEvent $event) use ($callback, $app) {
$this->on(KernelEvents::RESPONSE, function (ResponseEvent $event) use ($callback, $app) {
if (!$event->isMasterRequest()) {
return;
}
Expand All @@ -299,7 +300,7 @@ public function finish($callback, $priority = 0)
{
$app = $this;

$this->on(KernelEvents::TERMINATE, function (PostResponseEvent $event) use ($callback, $app) {
$this->on(KernelEvents::TERMINATE, function (TerminateEvent $event) use ($callback, $app) {
call_user_func($app['callback_resolver']->resolveCallback($callback), $event->getRequest(), $event->getResponse(), $app);
}, $priority);
}
Expand Down Expand Up @@ -485,7 +486,7 @@ public function run(Request $request = null)
* If you call this method directly instead of run(), you must call the
* terminate() method yourself if you want the finish filters to be run.
*/
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true): Response
{
if (!$this->booted) {
$this->boot();
Expand Down
9 changes: 3 additions & 6 deletions src/Silex/EventListener/ConverterListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Silex\EventListener;

use Silex\CallbackResolver;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\FilterControllerEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Expand Down Expand Up @@ -39,12 +40,8 @@ public function __construct(RouteCollection $routes, CallbackResolver $callbackR
$this->callbackResolver = $callbackResolver;
}

/**
* Handles converters.
*
* @param FilterControllerEvent $event The event to handle
*/
public function onKernelController(FilterControllerEvent $event)

public function onKernelController(ControllerEvent $event)
{
$request = $event->getRequest();
$route = $this->routes->get($request->attributes->get('_route'));
Expand Down
4 changes: 2 additions & 2 deletions src/Silex/EventListener/LogListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(LoggerInterface $logger, $exceptionLogFilter = null)
*/
public function onKernelRequest(GetResponseEvent $event)
{
if (!$event->isMasterRequest()) {
if (!$event->isMainRequest()) {
return;
}

Expand All @@ -68,7 +68,7 @@ public function onKernelRequest(GetResponseEvent $event)
*/
public function onKernelResponse(FilterResponseEvent $event)
{
if (!$event->isMasterRequest()) {
if (!$event->isMainRequest()) {
return;
}

Expand Down
17 changes: 5 additions & 12 deletions src/Silex/EventListener/MiddlewareListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Silex\EventListener;

use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
Expand All @@ -37,12 +39,8 @@ public function __construct(Application $app)
$this->app = $app;
}

/**
* Runs before filters.
*
* @param GetResponseEvent $event The event to handle
*/
public function onKernelRequest(GetResponseEvent $event)

public function onKernelRequest(RequestEvent $event)
{
$request = $event->getRequest();
$routeName = $request->attributes->get('_route');
Expand All @@ -62,12 +60,7 @@ public function onKernelRequest(GetResponseEvent $event)
}
}

/**
* Runs after filters.
*
* @param FilterResponseEvent $event The event to handle
*/
public function onKernelResponse(FilterResponseEvent $event)
public function onKernelResponse(ResponseEvent $event)
{
$request = $event->getRequest();
$routeName = $request->attributes->get('_route');
Expand Down
9 changes: 3 additions & 6 deletions src/Silex/EventListener/StringToResponseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Silex\EventListener;

use Symfony\Component\HttpKernel\Event\ViewEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
Expand All @@ -23,12 +24,8 @@
*/
class StringToResponseListener implements EventSubscriberInterface
{
/**
* Handles string responses.
*
* @param GetResponseForControllerResultEvent $event The event to handle
*/
public function onKernelView(GetResponseForControllerResultEvent $event)

public function onKernelView(ViewEvent $event)
{
$response = $event->getControllerResult();

Expand Down
19 changes: 11 additions & 8 deletions src/Silex/ExceptionListenerWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
namespace Silex;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
use Symfony\Component\HttpKernel\Event\ViewEvent;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;

/**
* Wraps exception listeners.
Expand All @@ -39,9 +40,10 @@ public function __construct(Application $app, $callback)
$this->callback = $callback;
}

public function __invoke(GetResponseForExceptionEvent $event)
public function __invoke(ExceptionEvent $event)
{
$exception = $event->getException();
$exception = $event->getThrowable();

$this->callback = $this->app['callback_resolver']->resolveCallback($this->callback);

if (!$this->shouldRun($exception)) {
Expand All @@ -55,7 +57,7 @@ public function __invoke(GetResponseForExceptionEvent $event)
$this->ensureResponse($response, $event);
}

protected function shouldRun(\Exception $exception)
protected function shouldRun(\Throwable $exception)
{
if (is_array($this->callback)) {
$callbackReflection = new \ReflectionMethod($this->callback[0], $this->callback[1]);
Expand All @@ -77,13 +79,14 @@ protected function shouldRun(\Exception $exception)
return true;
}

protected function ensureResponse($response, GetResponseForExceptionEvent $event)
protected function ensureResponse($response, ExceptionEvent $event)
{
if ($response instanceof Response) {
$event->setResponse($response);
} else {
$viewEvent = new GetResponseForControllerResultEvent($this->app['kernel'], $event->getRequest(), $event->getRequestType(), $response);
$this->app['dispatcher']->dispatch(KernelEvents::VIEW, $viewEvent);
$viewEvent = new ViewEvent($this->app['kernel'], $event->getRequest(), $event->getRequestType(), $response);

$this->app['dispatcher']->dispatch($viewEvent, KernelEvents::VIEW);

if ($viewEvent->hasResponse()) {
$event->setResponse($viewEvent->getResponse());
Expand Down
2 changes: 1 addition & 1 deletion src/Silex/ServiceControllerResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct(ControllerResolverInterface $controllerResolver, Cal
/**
* {@inheritdoc}
*/
public function getController(Request $request)
public function getController(Request $request): callable|false
{
$controller = $request->attributes->get('_controller', null);

Expand Down
6 changes: 4 additions & 2 deletions src/Silex/ViewListenerWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
namespace Silex;

use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;

/**
* Wraps view listeners.
Expand All @@ -36,9 +37,10 @@ public function __construct(Application $app, $callback)
$this->callback = $callback;
}

public function __invoke(GetResponseForControllerResultEvent $event)
public function __invoke(RequestEvent $event)
{
$controllerResult = $event->getControllerResult();

$callback = $this->app['callback_resolver']->resolveCallback($this->callback);

if (!$this->shouldRun($callback, $controllerResult)) {
Expand Down

0 comments on commit 83048cd

Please sign in to comment.