From 4f9a1b0cac056631c18fef92773e9f02f2960cf8 Mon Sep 17 00:00:00 2001 From: Bojan Date: Wed, 18 Jan 2023 11:41:48 +0100 Subject: [PATCH 01/20] symfony/http-foundation to v6 --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index c5c88cab6..631b19bd6 100644 --- a/composer.json +++ b/composer.json @@ -18,8 +18,8 @@ "php": ">=7.1.3", "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/http-foundation": "^3.0|^4.0|^5.0|^6.0", + "symfony/http-kernel": "^3.0|^4.0|^5.0|^6.0", "symfony/routing": "^3.0|^4.0|^5.0" }, "require-dev": { From 438635ab39bceaae7807ee0479f1a18cbbfcbf23 Mon Sep 17 00:00:00 2001 From: Bojan Date: Wed, 18 Jan 2023 12:24:45 +0100 Subject: [PATCH 02/20] event-dispatcher v6 allowed --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 631b19bd6..2907662ee 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "require": { "php": ">=7.1.3", "pimple/pimple": "^3.0", - "symfony/event-dispatcher": "^3.0|^4.0|^5.0", + "symfony/event-dispatcher": "^3.0|^4.0|^5.0|^6.0", "symfony/http-foundation": "^3.0|^4.0|^5.0|^6.0", "symfony/http-kernel": "^3.0|^4.0|^5.0|^6.0", "symfony/routing": "^3.0|^4.0|^5.0" From c84379a008fabf351392b7cba2ededbe0653a352 Mon Sep 17 00:00:00 2001 From: Bojan Date: Wed, 18 Jan 2023 13:16:08 +0100 Subject: [PATCH 03/20] public function handle(Request $request, int $type = self::MAIN_REQUEST, bool $catch = true): Response --- src/Silex/Application.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Silex/Application.php b/src/Silex/Application.php index b1125d0df..608f8476f 100644 --- a/src/Silex/Application.php +++ b/src/Silex/Application.php @@ -485,7 +485,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(); From 20cb9966fc4c885181f25b5f1d1da1dee03b6129 Mon Sep 17 00:00:00 2001 From: Bojan Date: Wed, 18 Jan 2023 13:23:01 +0100 Subject: [PATCH 04/20] Warning: include(/www/zep-api/Config/Config.localenv.php): Failed to open stream: No such file or directory --- src/Silex/AppArgumentValueResolver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Silex/AppArgumentValueResolver.php b/src/Silex/AppArgumentValueResolver.php index e96b26219..ce671be84 100644 --- a/src/Silex/AppArgumentValueResolver.php +++ b/src/Silex/AppArgumentValueResolver.php @@ -32,7 +32,7 @@ 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)); } @@ -40,7 +40,7 @@ public function supports(Request $request, ArgumentMetadata $argument) /** * {@inheritdoc} */ - public function resolve(Request $request, ArgumentMetadata $argument) + public function resolve(Request $request, ArgumentMetadata $argument): iterable { yield $this->app; } From 5dbf492360920f020a9bea6195c3e8d13fb26213 Mon Sep 17 00:00:00 2001 From: Bojan Date: Wed, 18 Jan 2023 13:26:49 +0100 Subject: [PATCH 05/20] Symfony\Component\HttpKernel\Event\GetResponseEvent, Symfony\Component\HttpKernel\Event\RequestEvent given --- src/Silex/Application.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Silex/Application.php b/src/Silex/Application.php index 608f8476f..fcff47bfb 100644 --- a/src/Silex/Application.php +++ b/src/Silex/Application.php @@ -15,6 +15,7 @@ use Pimple\ServiceProviderInterface; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\HttpFoundation\BinaryFileResponse; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\HttpKernelInterface; use Symfony\Component\HttpKernel\TerminableInterface; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; @@ -246,7 +247,7 @@ 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; } From 34386f8b93260bdd973a3190a2554c406d096e15 Mon Sep 17 00:00:00 2001 From: Bojan Date: Wed, 18 Jan 2023 13:28:17 +0100 Subject: [PATCH 06/20] seems isMaster was removed --- src/Silex/Application.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Silex/Application.php b/src/Silex/Application.php index fcff47bfb..b81997501 100644 --- a/src/Silex/Application.php +++ b/src/Silex/Application.php @@ -248,9 +248,9 @@ public function before($callback, $priority = 0) $app = $this; $this->on(KernelEvents::REQUEST, function (RequestEvent $event) use ($callback, $app) { - if (!$event->isMasterRequest()) { - return; - } +// if (!$event->isMasterRequest()) { +// return; +// } $ret = call_user_func($app['callback_resolver']->resolveCallback($callback), $event->getRequest(), $app); From 412b1cababec356f91b4ead7d4460d724643422d Mon Sep 17 00:00:00 2001 From: Bojan Date: Wed, 18 Jan 2023 13:30:38 +0100 Subject: [PATCH 07/20] TypeError: Silex\EventListener\MiddlewareListener::onKernelRequest(): Argument #1 ($event) must be of type Symfony\Component\HttpKernel\Event\GetResponseEvent, Symfony\Component\HttpKernel\Event\RequestEvent given --- src/Silex/EventListener/MiddlewareListener.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Silex/EventListener/MiddlewareListener.php b/src/Silex/EventListener/MiddlewareListener.php index 412bb7b61..2a152d1cb 100644 --- a/src/Silex/EventListener/MiddlewareListener.php +++ b/src/Silex/EventListener/MiddlewareListener.php @@ -11,6 +11,7 @@ namespace Silex\EventListener; +use Symfony\Component\HttpKernel\Event\RequestEvent; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseEvent; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; @@ -37,12 +38,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'); From 5f93f4b7c032819d525f335df468080b3e05284c Mon Sep 17 00:00:00 2001 From: Bojan Date: Wed, 18 Jan 2023 13:33:24 +0100 Subject: [PATCH 08/20] Symfony\Component\HttpKernel\Event\FilterControllerEvent, Symfony\Component\HttpKernel\Event\ControllerEvent given --- src/Silex/EventListener/ConverterListener.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Silex/EventListener/ConverterListener.php b/src/Silex/EventListener/ConverterListener.php index dfb2d5c19..2b4d01d02 100644 --- a/src/Silex/EventListener/ConverterListener.php +++ b/src/Silex/EventListener/ConverterListener.php @@ -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; @@ -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')); From 794b31d5865c1fe4b54ae109ce5a2522e926377b Mon Sep 17 00:00:00 2001 From: Bojan Date: Wed, 18 Jan 2023 13:35:34 +0100 Subject: [PATCH 09/20] Uncaught TypeError: Silex\EventListener\MiddlewareListener::onKernelResponse(): Argument #1 ($event) must be of type Symfony\Component\HttpKernel\Event\FilterResponseEvent, Symfony\Component\HttpKernel\Event\ResponseEvent given --- src/Silex/EventListener/MiddlewareListener.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/Silex/EventListener/MiddlewareListener.php b/src/Silex/EventListener/MiddlewareListener.php index 2a152d1cb..2cc303100 100644 --- a/src/Silex/EventListener/MiddlewareListener.php +++ b/src/Silex/EventListener/MiddlewareListener.php @@ -12,6 +12,7 @@ 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; @@ -59,12 +60,7 @@ public function onKernelRequest(RequestEvent $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'); From 51741c2e039c15985e641d1ae61485e4a563acc3 Mon Sep 17 00:00:00 2001 From: Bojan Date: Wed, 18 Jan 2023 13:37:08 +0100 Subject: [PATCH 10/20] Uncaught TypeError: Silex\Application::Silex\{closure}(): Argument #1 ($event) must be of type Symfony\Component\HttpKernel\Event\FilterResponseEvent, Symfony\Component\HttpKernel\Event\ResponseEvent given, called in /www/zep-api/vendor/symfony/event-dispatcher/EventDispatcher.php --- src/Silex/Application.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Silex/Application.php b/src/Silex/Application.php index b81997501..d38e09903 100644 --- a/src/Silex/Application.php +++ b/src/Silex/Application.php @@ -16,6 +16,7 @@ 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\HttpKernelInterface; use Symfony\Component\HttpKernel\TerminableInterface; use Symfony\Component\HttpKernel\Event\FilterResponseEvent; @@ -273,7 +274,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; } From 154956f1b734e5e151b625417fef3f403a2232a8 Mon Sep 17 00:00:00 2001 From: Bojan Date: Wed, 18 Jan 2023 13:39:14 +0100 Subject: [PATCH 11/20] isMasterRequest seems to be removed --- src/Silex/Application.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Silex/Application.php b/src/Silex/Application.php index d38e09903..b3211f5e2 100644 --- a/src/Silex/Application.php +++ b/src/Silex/Application.php @@ -275,9 +275,9 @@ public function after($callback, $priority = 0) $app = $this; $this->on(KernelEvents::RESPONSE, function (ResponseEvent $event) use ($callback, $app) { - if (!$event->isMasterRequest()) { - return; - } +// if (!$event->isMasterRequest()) { +// return; +// } $response = call_user_func($app['callback_resolver']->resolveCallback($callback), $event->getRequest(), $event->getResponse(), $app); if ($response instanceof Response) { From 1d826fe8f411c842774cad8a064c9385f755546a Mon Sep 17 00:00:00 2001 From: Bojan Date: Wed, 18 Jan 2023 13:43:05 +0100 Subject: [PATCH 12/20] Uncaught TypeError: Silex\EventListener\StringToResponseListener::onKernelView(): Argument #1 ($event) must be of type Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent, Symfony\Component\HttpKernel\Event\ViewEvent given --- src/Silex/EventListener/StringToResponseListener.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Silex/EventListener/StringToResponseListener.php b/src/Silex/EventListener/StringToResponseListener.php index 5b93b2164..1714a0bbc 100644 --- a/src/Silex/EventListener/StringToResponseListener.php +++ b/src/Silex/EventListener/StringToResponseListener.php @@ -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; @@ -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(); From 6ebf2850aecfc3f1e08436725e58c25ffe39923d Mon Sep 17 00:00:00 2001 From: Bojan Date: Wed, 18 Jan 2023 14:07:55 +0100 Subject: [PATCH 13/20] This should be implemented, but is not! --- src/Silex/ExceptionListenerWrapper.php | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Silex/ExceptionListenerWrapper.php b/src/Silex/ExceptionListenerWrapper.php index d83170ebf..eb699cf74 100644 --- a/src/Silex/ExceptionListenerWrapper.php +++ b/src/Silex/ExceptionListenerWrapper.php @@ -12,6 +12,7 @@ namespace Silex; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Event\ExceptionEvent; use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface; use Symfony\Component\HttpKernel\KernelEvents; use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; @@ -39,7 +40,7 @@ public function __construct(Application $app, $callback) $this->callback = $callback; } - public function __invoke(GetResponseForExceptionEvent $event) + public function __invoke(ExceptionEvent $event) { $exception = $event->getException(); $this->callback = $this->app['callback_resolver']->resolveCallback($this->callback); @@ -77,17 +78,23 @@ 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); - if ($viewEvent->hasResponse()) { - $event->setResponse($viewEvent->getResponse()); - } + error_log('This should be implemented, but is not!'); + + // $viewEvent = new GetResponseForControllerResultEvent($this->app['kernel'], $event->getRequest(), $event->getRequestType(), $response); + // $this->app['dispatcher']->dispatch(KernelEvents::VIEW, $viewEvent); + + // it was updated to + // $this->app['dispatcher']->dispatch($viewEvent, KernelEvents::VIEW); + +// if ($viewEvent->hasResponse()) { +// $event->setResponse($viewEvent->getResponse()); +// } } } } From 2350d936d83466baf030d68adb111ea6289ce952 Mon Sep 17 00:00:00 2001 From: Bojan Date: Wed, 18 Jan 2023 14:25:41 +0100 Subject: [PATCH 14/20] Some fixes for Silex. --- src/Silex/Application.php | 5 +--- src/Silex/ExceptionListenerWrapper.php | 24 ++++++++---------- src/Silex/ServiceControllerResolver.php | 2 +- src/Silex/ViewListenerWrapper.php | 33 ++++++++++++++----------- 4 files changed, 30 insertions(+), 34 deletions(-) diff --git a/src/Silex/Application.php b/src/Silex/Application.php index b3211f5e2..d193885dd 100644 --- a/src/Silex/Application.php +++ b/src/Silex/Application.php @@ -19,9 +19,6 @@ use Symfony\Component\HttpKernel\Event\ResponseEvent; 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; @@ -301,7 +298,7 @@ public function finish($callback, $priority = 0) { $app = $this; - $this->on(KernelEvents::TERMINATE, function (PostResponseEvent $event) use ($callback, $app) { + $this->on(KernelEvents::TERMINATE, function (ResponseEvent $event) use ($callback, $app) { call_user_func($app['callback_resolver']->resolveCallback($callback), $event->getRequest(), $event->getResponse(), $app); }, $priority); } diff --git a/src/Silex/ExceptionListenerWrapper.php b/src/Silex/ExceptionListenerWrapper.php index eb699cf74..690caad35 100644 --- a/src/Silex/ExceptionListenerWrapper.php +++ b/src/Silex/ExceptionListenerWrapper.php @@ -12,11 +12,10 @@ namespace Silex; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Event\ResponseEvent; use Symfony\Component\HttpKernel\Event\ExceptionEvent; 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. @@ -42,7 +41,8 @@ public function __construct(Application $app, $callback) public function __invoke(ExceptionEvent $event) { - $exception = $event->getException(); + $exception = $event->getThrowable(); + $this->callback = $this->app['callback_resolver']->resolveCallback($this->callback); if (!$this->shouldRun($exception)) { @@ -56,7 +56,7 @@ public function __invoke(ExceptionEvent $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]); @@ -83,18 +83,14 @@ protected function ensureResponse($response, ExceptionEvent $event) if ($response instanceof Response) { $event->setResponse($response); } else { + $viewEvent = new ResponseEvent($this->app['kernel'], $event->getRequest(), $event->getRequestType(), $response); - error_log('This should be implemented, but is not!'); - - // $viewEvent = new GetResponseForControllerResultEvent($this->app['kernel'], $event->getRequest(), $event->getRequestType(), $response); - // $this->app['dispatcher']->dispatch(KernelEvents::VIEW, $viewEvent); + // $this->app['dispatcher']->dispatch(KernelEvents::VIEW, $viewEvent); + $this->app['dispatcher']->dispatch($viewEvent, KernelEvents::VIEW); - // it was updated to - // $this->app['dispatcher']->dispatch($viewEvent, KernelEvents::VIEW); - -// if ($viewEvent->hasResponse()) { -// $event->setResponse($viewEvent->getResponse()); -// } + if ($viewEvent->hasResponse()) { + $event->setResponse($viewEvent->getResponse()); + } } } } diff --git a/src/Silex/ServiceControllerResolver.php b/src/Silex/ServiceControllerResolver.php index 7de8e492e..bd5371daf 100644 --- a/src/Silex/ServiceControllerResolver.php +++ b/src/Silex/ServiceControllerResolver.php @@ -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); diff --git a/src/Silex/ViewListenerWrapper.php b/src/Silex/ViewListenerWrapper.php index a67ec938e..0984873e0 100644 --- a/src/Silex/ViewListenerWrapper.php +++ b/src/Silex/ViewListenerWrapper.php @@ -12,7 +12,7 @@ namespace Silex; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent; +use Symfony\Component\HttpKernel\Event\ControllerEvent; /** * Wraps view listeners. @@ -36,22 +36,25 @@ public function __construct(Application $app, $callback) $this->callback = $callback; } - public function __invoke(GetResponseForControllerResultEvent $event) + public function __invoke(ControllerEvent $event) { - $controllerResult = $event->getControllerResult(); - $callback = $this->app['callback_resolver']->resolveCallback($this->callback); - if (!$this->shouldRun($callback, $controllerResult)) { - return; - } - - $response = call_user_func($callback, $controllerResult, $event->getRequest()); - - if ($response instanceof Response) { - $event->setResponse($response); - } elseif (null !== $response) { - $event->setControllerResult($response); - } + error_log('Should be implemented but it is not.'); +// $controllerResult = $event->getControllerResult(); +// +// $callback = $this->app['callback_resolver']->resolveCallback($this->callback); +// +// if (!$this->shouldRun($callback, $controllerResult)) { +// return; +// } +// +// $response = call_user_func($callback, $controllerResult, $event->getRequest()); +// +// if ($response instanceof Response) { +// $event->setResponse($response); +// } elseif (null !== $response) { +// $event->setControllerResult($response); +// } } private function shouldRun($callback, $controllerResult) From 4695da712fdfbc7f7a25d1564567d0b9fe44bc61 Mon Sep 17 00:00:00 2001 From: Bojan Kovacec Date: Wed, 1 Feb 2023 13:48:41 +0100 Subject: [PATCH 15/20] It is ViewEvent --- src/Silex/ExceptionListenerWrapper.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Silex/ExceptionListenerWrapper.php b/src/Silex/ExceptionListenerWrapper.php index 690caad35..3f8c2afba 100644 --- a/src/Silex/ExceptionListenerWrapper.php +++ b/src/Silex/ExceptionListenerWrapper.php @@ -14,6 +14,7 @@ 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; @@ -83,10 +84,9 @@ protected function ensureResponse($response, ExceptionEvent $event) if ($response instanceof Response) { $event->setResponse($response); } else { - $viewEvent = new ResponseEvent($this->app['kernel'], $event->getRequest(), $event->getRequestType(), $response); + $viewEvent = new ViewEvent($this->app['kernel'], $event->getRequest(), $event->getRequestType(), $response); - // $this->app['dispatcher']->dispatch(KernelEvents::VIEW, $viewEvent); - $this->app['dispatcher']->dispatch($viewEvent, KernelEvents::VIEW); + $this->app['dispatcher']->dispatch($viewEvent, KernelEvents::VIEW); if ($viewEvent->hasResponse()) { $event->setResponse($viewEvent->getResponse()); From 717f86f6fe97895bd8d976df5c7460e0ea4b1ce4 Mon Sep 17 00:00:00 2001 From: Bojan Kovacec Date: Wed, 1 Feb 2023 13:55:02 +0100 Subject: [PATCH 16/20] Should be used. --- src/Silex/Application.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Silex/Application.php b/src/Silex/Application.php index d193885dd..959ef4ead 100644 --- a/src/Silex/Application.php +++ b/src/Silex/Application.php @@ -246,9 +246,9 @@ public function before($callback, $priority = 0) $app = $this; $this->on(KernelEvents::REQUEST, function (RequestEvent $event) use ($callback, $app) { -// if (!$event->isMasterRequest()) { -// return; -// } + if (!$event->isMasterRequest()) { + return; + } $ret = call_user_func($app['callback_resolver']->resolveCallback($callback), $event->getRequest(), $app); From fc7eeccf4e8b2db15dfac60df61ae5545b435e60 Mon Sep 17 00:00:00 2001 From: Bojan Kovacec Date: Wed, 1 Feb 2023 13:56:21 +0100 Subject: [PATCH 17/20] Should be used. --- src/Silex/Application.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Silex/Application.php b/src/Silex/Application.php index 959ef4ead..df48c2397 100644 --- a/src/Silex/Application.php +++ b/src/Silex/Application.php @@ -272,9 +272,9 @@ public function after($callback, $priority = 0) $app = $this; $this->on(KernelEvents::RESPONSE, function (ResponseEvent $event) use ($callback, $app) { -// if (!$event->isMasterRequest()) { -// return; -// } + if (!$event->isMasterRequest()) { + return; + } $response = call_user_func($app['callback_resolver']->resolveCallback($callback), $event->getRequest(), $event->getResponse(), $app); if ($response instanceof Response) { From 47c1abe067db94712b6f28c78495f5e8f0e8d09b Mon Sep 17 00:00:00 2001 From: Bojan Kovacec Date: Wed, 1 Feb 2023 13:58:18 +0100 Subject: [PATCH 18/20] TerminateEvent --- src/Silex/Application.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Silex/Application.php b/src/Silex/Application.php index df48c2397..8b89ec578 100644 --- a/src/Silex/Application.php +++ b/src/Silex/Application.php @@ -17,6 +17,7 @@ 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\Exception\HttpException; @@ -298,7 +299,7 @@ public function finish($callback, $priority = 0) { $app = $this; - $this->on(KernelEvents::TERMINATE, function (ResponseEvent $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); } From 5d1c3d7d3fcbef13032831a702baa54bfbbbfcb7 Mon Sep 17 00:00:00 2001 From: Bojan Kovacec Date: Wed, 1 Feb 2023 14:11:17 +0100 Subject: [PATCH 19/20] RequestEvent --- src/Silex/ViewListenerWrapper.php | 33 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/Silex/ViewListenerWrapper.php b/src/Silex/ViewListenerWrapper.php index 0984873e0..5afad61bd 100644 --- a/src/Silex/ViewListenerWrapper.php +++ b/src/Silex/ViewListenerWrapper.php @@ -13,6 +13,7 @@ use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Event\ControllerEvent; +use Symfony\Component\HttpKernel\Event\RequestEvent; /** * Wraps view listeners. @@ -36,25 +37,23 @@ public function __construct(Application $app, $callback) $this->callback = $callback; } - public function __invoke(ControllerEvent $event) + public function __invoke(RequestEvent $event) { + $controllerResult = $event->getControllerResult(); - error_log('Should be implemented but it is not.'); -// $controllerResult = $event->getControllerResult(); -// -// $callback = $this->app['callback_resolver']->resolveCallback($this->callback); -// -// if (!$this->shouldRun($callback, $controllerResult)) { -// return; -// } -// -// $response = call_user_func($callback, $controllerResult, $event->getRequest()); -// -// if ($response instanceof Response) { -// $event->setResponse($response); -// } elseif (null !== $response) { -// $event->setControllerResult($response); -// } + $callback = $this->app['callback_resolver']->resolveCallback($this->callback); + + if (!$this->shouldRun($callback, $controllerResult)) { + return; + } + + $response = call_user_func($callback, $controllerResult, $event->getRequest()); + + if ($response instanceof Response) { + $event->setResponse($response); + } elseif (null !== $response) { + $event->setControllerResult($response); + } } private function shouldRun($callback, $controllerResult) From 398fe7676a4f79911950b15a5aaafd0dc775e6e4 Mon Sep 17 00:00:00 2001 From: Bojan Kovacec Date: Thu, 2 Feb 2023 14:49:02 +0100 Subject: [PATCH 20/20] More fixed version. --- composer.json | 36 ++++--------------------- src/Silex/Application.php | 1 + src/Silex/EventListener/LogListener.php | 4 +-- 3 files changed, 8 insertions(+), 33 deletions(-) diff --git a/composer.json b/composer.json index 2907662ee..fbb0160c2 100644 --- a/composer.json +++ b/composer.json @@ -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|^6.0", - "symfony/http-foundation": "^3.0|^4.0|^5.0|^6.0", - "symfony/http-kernel": "^3.0|^4.0|^5.0|^6.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", diff --git a/src/Silex/Application.php b/src/Silex/Application.php index 8b89ec578..8b130858f 100644 --- a/src/Silex/Application.php +++ b/src/Silex/Application.php @@ -247,6 +247,7 @@ public function before($callback, $priority = 0) $app = $this; $this->on(KernelEvents::REQUEST, function (RequestEvent $event) use ($callback, $app) { + if (!$event->isMasterRequest()) { return; } diff --git a/src/Silex/EventListener/LogListener.php b/src/Silex/EventListener/LogListener.php index 39c1b1120..fe7352ed7 100644 --- a/src/Silex/EventListener/LogListener.php +++ b/src/Silex/EventListener/LogListener.php @@ -54,7 +54,7 @@ public function __construct(LoggerInterface $logger, $exceptionLogFilter = null) */ public function onKernelRequest(GetResponseEvent $event) { - if (!$event->isMasterRequest()) { + if (!$event->isMainRequest()) { return; } @@ -68,7 +68,7 @@ public function onKernelRequest(GetResponseEvent $event) */ public function onKernelResponse(FilterResponseEvent $event) { - if (!$event->isMasterRequest()) { + if (!$event->isMainRequest()) { return; }