From 84cbcecc49310e5d71b0e4c956a50c47b1810a42 Mon Sep 17 00:00:00 2001 From: TheKito <11139894+TheKito@users.noreply.github.com> Date: Sun, 1 Mar 2020 02:17:07 -0300 Subject: [PATCH 01/11] Create Functions.php --- src/Functions.php | 77 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/Functions.php diff --git a/src/Functions.php b/src/Functions.php new file mode 100644 index 0000000..76a5eb2 --- /dev/null +++ b/src/Functions.php @@ -0,0 +1,77 @@ + RouteParser\Std::class, + 'dataGenerator' => DataGenerator\GroupCountBased::class, + 'dispatcher' => Dispatcher\GroupCountBased::class, + 'routeCollector' => RouteCollector::class, + ]; + + $routeCollector = new $options['routeCollector']( + new $options['routeParser'](), new $options['dataGenerator']() + ); + assert($routeCollector instanceof RouteCollector); + $routeDefinitionCallback($routeCollector); + + return new $options['dispatcher']($routeCollector->getData()); + } + + /** + * @param array $options + */ + public static function cachedDispatcher(callable $routeDefinitionCallback, array $options = []): Dispatcher + { + $options += [ + 'routeParser' => RouteParser\Std::class, + 'dataGenerator' => DataGenerator\GroupCountBased::class, + 'dispatcher' => Dispatcher\GroupCountBased::class, + 'routeCollector' => RouteCollector::class, + 'cacheDisabled' => false, + ]; + + if (! isset($options['cacheFile'])) { + throw new LogicException('Must specify "cacheFile" option'); + } + + if (! $options['cacheDisabled'] && file_exists($options['cacheFile'])) { + $dispatchData = require $options['cacheFile']; + if (! is_array($dispatchData)) { + throw new RuntimeException('Invalid cache file "' . $options['cacheFile'] . '"'); + } + + return new $options['dispatcher']($dispatchData); + } + + $routeCollector = new $options['routeCollector']( + new $options['routeParser'](), new $options['dataGenerator']() + ); + assert($routeCollector instanceof RouteCollector); + $routeDefinitionCallback($routeCollector); + + $dispatchData = $routeCollector->getData(); + if (! $options['cacheDisabled']) { + file_put_contents( + $options['cacheFile'], + ' Date: Sun, 1 Mar 2020 02:19:50 -0300 Subject: [PATCH 02/11] Update functions.php --- src/functions.php | 52 ++--------------------------------------------- 1 file changed, 2 insertions(+), 50 deletions(-) diff --git a/src/functions.php b/src/functions.php index 9641f57..6478c38 100644 --- a/src/functions.php +++ b/src/functions.php @@ -18,20 +18,7 @@ */ function simpleDispatcher(callable $routeDefinitionCallback, array $options = []): Dispatcher { - $options += [ - 'routeParser' => RouteParser\Std::class, - 'dataGenerator' => DataGenerator\GroupCountBased::class, - 'dispatcher' => Dispatcher\GroupCountBased::class, - 'routeCollector' => RouteCollector::class, - ]; - - $routeCollector = new $options['routeCollector']( - new $options['routeParser'](), new $options['dataGenerator']() - ); - assert($routeCollector instanceof RouteCollector); - $routeDefinitionCallback($routeCollector); - - return new $options['dispatcher']($routeCollector->getData()); + return Functions::simpleDispatcher($routeDefinitionCallback, $options): } /** @@ -39,41 +26,6 @@ function simpleDispatcher(callable $routeDefinitionCallback, array $options = [] */ function cachedDispatcher(callable $routeDefinitionCallback, array $options = []): Dispatcher { - $options += [ - 'routeParser' => RouteParser\Std::class, - 'dataGenerator' => DataGenerator\GroupCountBased::class, - 'dispatcher' => Dispatcher\GroupCountBased::class, - 'routeCollector' => RouteCollector::class, - 'cacheDisabled' => false, - ]; - - if (! isset($options['cacheFile'])) { - throw new LogicException('Must specify "cacheFile" option'); - } - - if (! $options['cacheDisabled'] && file_exists($options['cacheFile'])) { - $dispatchData = require $options['cacheFile']; - if (! is_array($dispatchData)) { - throw new RuntimeException('Invalid cache file "' . $options['cacheFile'] . '"'); - } - - return new $options['dispatcher']($dispatchData); - } - - $routeCollector = new $options['routeCollector']( - new $options['routeParser'](), new $options['dataGenerator']() - ); - assert($routeCollector instanceof RouteCollector); - $routeDefinitionCallback($routeCollector); - - $dispatchData = $routeCollector->getData(); - if (! $options['cacheDisabled']) { - file_put_contents( - $options['cacheFile'], - ' Date: Sun, 1 Mar 2020 12:23:50 -0300 Subject: [PATCH 03/11] Update functions.php semicolon mistakes --- src/functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/functions.php b/src/functions.php index 6478c38..13ff1f6 100644 --- a/src/functions.php +++ b/src/functions.php @@ -18,7 +18,7 @@ */ function simpleDispatcher(callable $routeDefinitionCallback, array $options = []): Dispatcher { - return Functions::simpleDispatcher($routeDefinitionCallback, $options): + return Functions::simpleDispatcher($routeDefinitionCallback, $options); } /** From 0a1b06305a6565cff134b2d1ae3d86fa2c78ac51 Mon Sep 17 00:00:00 2001 From: TheKito <11139894+TheKito@users.noreply.github.com> Date: Sun, 1 Mar 2020 12:39:04 -0300 Subject: [PATCH 04/11] remove unused use functions --- src/functions.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/functions.php b/src/functions.php index 13ff1f6..d9ac529 100644 --- a/src/functions.php +++ b/src/functions.php @@ -3,14 +3,7 @@ namespace FastRoute; -use LogicException; -use RuntimeException; -use function assert; -use function file_exists; -use function file_put_contents; use function function_exists; -use function is_array; -use function var_export; if (! function_exists('FastRoute\simpleDispatcher')) { /** From 4ea99bdd9ad2b9840915625cb7973c9eb36e6c10 Mon Sep 17 00:00:00 2001 From: TheKito <11139894+TheKito@users.noreply.github.com> Date: Sun, 1 Mar 2020 12:41:38 -0300 Subject: [PATCH 05/11] add @params to simpleDispatcher --- src/Functions.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Functions.php b/src/Functions.php index 76a5eb2..dace7ad 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -8,12 +8,15 @@ use function assert; use function file_exists; use function file_put_contents; -use function function_exists; use function is_array; use function var_export; class Functions { + + /** + * @param array $options + */ public static function simpleDispatcher(callable $routeDefinitionCallback, array $options = []): Dispatcher { $options += [ From 045406b00a96ee2c5680e8f0f7c6e449cfbcaa74 Mon Sep 17 00:00:00 2001 From: TheKito <11139894+TheKito@users.noreply.github.com> Date: Sun, 1 Mar 2020 12:54:00 -0300 Subject: [PATCH 06/11] remove empty lines --- src/Functions.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Functions.php b/src/Functions.php index dace7ad..6bc1f32 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -13,7 +13,6 @@ class Functions { - /** * @param array $options */ @@ -34,7 +33,6 @@ public static function simpleDispatcher(callable $routeDefinitionCallback, array return new $options['dispatcher']($routeCollector->getData()); } - /** * @param array $options */ From 2944bc7917fc1260e07bcef395eaad3fd047798a Mon Sep 17 00:00:00 2001 From: TheKito <11139894+TheKito@users.noreply.github.com> Date: Sun, 1 Mar 2020 13:00:15 -0300 Subject: [PATCH 07/11] add blank line --- src/Functions.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Functions.php b/src/Functions.php index 6bc1f32..2681d52 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -33,6 +33,7 @@ public static function simpleDispatcher(callable $routeDefinitionCallback, array return new $options['dispatcher']($routeCollector->getData()); } + /** * @param array $options */ From c96b2d5a79d31a51a183a6d19005bd792fe4e496 Mon Sep 17 00:00:00 2001 From: TheKito <11139894+TheKito@users.noreply.github.com> Date: Sun, 1 Mar 2020 13:05:25 -0300 Subject: [PATCH 08/11] remove whitespace line 36 --- src/Functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Functions.php b/src/Functions.php index 2681d52..ba9cdba 100644 --- a/src/Functions.php +++ b/src/Functions.php @@ -33,7 +33,7 @@ public static function simpleDispatcher(callable $routeDefinitionCallback, array return new $options['dispatcher']($routeCollector->getData()); } - + /** * @param array $options */ From dc406c85f2679e4822af1bf3825785d0e0e588cd Mon Sep 17 00:00:00 2001 From: TheKito <11139894+TheKito@users.noreply.github.com> Date: Thu, 26 Mar 2020 16:46:48 -0300 Subject: [PATCH 09/11] Rename Functions.php to Utils.php --- src/{Functions.php => Utils.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/{Functions.php => Utils.php} (100%) diff --git a/src/Functions.php b/src/Utils.php similarity index 100% rename from src/Functions.php rename to src/Utils.php From 8a7acd49f80c33961e98cd616dc76505fd62f505 Mon Sep 17 00:00:00 2001 From: TheKito <11139894+TheKito@users.noreply.github.com> Date: Thu, 26 Mar 2020 16:47:58 -0300 Subject: [PATCH 10/11] renane function and class from Functions to Utils rename function and class from Functions to Utils to prevent overlap in non case sensitive file systems --- src/Utils.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Utils.php b/src/Utils.php index ba9cdba..fe23066 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -11,7 +11,7 @@ use function is_array; use function var_export; -class Functions +class Utils { /** * @param array $options From fe94fbceb100e00ffb9efa56341b82cbb4e704e0 Mon Sep 17 00:00:00 2001 From: TheKito <11139894+TheKito@users.noreply.github.com> Date: Thu, 26 Mar 2020 16:48:38 -0300 Subject: [PATCH 11/11] rename function and class from Functions to Utils rename function and class from Functions to Utils to prevent overlap in non case sensitive file systems --- src/functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/functions.php b/src/functions.php index d9ac529..64f5f90 100644 --- a/src/functions.php +++ b/src/functions.php @@ -11,7 +11,7 @@ */ function simpleDispatcher(callable $routeDefinitionCallback, array $options = []): Dispatcher { - return Functions::simpleDispatcher($routeDefinitionCallback, $options); + return Utils::simpleDispatcher($routeDefinitionCallback, $options); } /** @@ -19,6 +19,6 @@ function simpleDispatcher(callable $routeDefinitionCallback, array $options = [] */ function cachedDispatcher(callable $routeDefinitionCallback, array $options = []): Dispatcher { - return Functions::cachedDispatcher($routeDefinitionCallback, $options); + return Utils::cachedDispatcher($routeDefinitionCallback, $options); } }