From e322135d9c8d0947e55bb3f73f98673fefa637a9 Mon Sep 17 00:00:00 2001 From: fadrian06 Date: Mon, 1 Apr 2024 18:45:37 -0400 Subject: [PATCH] Add symfony/polyfill-80 --- composer.json | 2 ++ flight/core/Dispatcher.php | 31 ++++++++++++++----------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index 2be3e4b..e30b937 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,8 @@ "require": { "php": "^7.4|^8.0|^8.1|^8.2|^8.3", "ext-json": "*" + "ext-json": "*", + "symfony/polyfill-php80": "^1.29" }, "autoload": { "files": [ diff --git a/flight/core/Dispatcher.php b/flight/core/Dispatcher.php index 6a167a8..dd202be 100644 --- a/flight/core/Dispatcher.php +++ b/flight/core/Dispatcher.php @@ -251,7 +251,10 @@ class Dispatcher */ public function execute($callback, array &$params = []) { - if (is_string($callback) === true && (strpos($callback, '->') !== false || strpos($callback, '::') !== false)) { + if ( + is_string($callback) + && (str_contains($callback, '->') || str_contains($callback, '::')) + ) { $callback = $this->parseStringClassAndMethod($callback); } @@ -327,27 +330,21 @@ class Dispatcher } [$class, $method] = $func; - $resolvedClass = null; - // Only execute the container handler if it's not a Flight class - if ( - $this->containerHandler !== null && - ( - ( - is_object($class) === true && - strpos(get_class($class), 'flight\\') === false - ) || - is_string($class) === true - ) - ) { - $containerHandler = $this->containerHandler; - $resolvedClass = $this->resolveContainerClass($containerHandler, $class, $params); - if ($resolvedClass !== null) { + $mustUseTheContainer = $this->containerHandler && ( + (is_object($class) && !str_starts_with(get_class($class), 'flight\\')) + || is_string($class) + ); + + if ($mustUseTheContainer) { + $resolvedClass = $this->resolveContainerClass($class, $params); + + if ($resolvedClass) { $class = $resolvedClass; } } - $this->verifyValidClassCallable($class, $method, $resolvedClass); + $this->verifyValidClassCallable($class, $method, $resolvedClass ?? null); // Class is a string, and method exists, create the object by hand and inject only the Engine if (is_string($class) === true) {