From dc54faad120cff5bd44892a16de3aa00ab6c99bd Mon Sep 17 00:00:00 2001 From: Andrew Broberg Date: Wed, 24 Jan 2024 14:48:52 +1100 Subject: [PATCH 1/2] feat: Support path in STACKKIT_CLOUD_TASKS_HANDLER --- src/Config.php | 15 +++++---------- tests/ConfigHandlerTest.php | 27 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 tests/ConfigHandlerTest.php diff --git a/src/Config.php b/src/Config.php index 9ffd34b..588de73 100644 --- a/src/Config.php +++ b/src/Config.php @@ -63,18 +63,13 @@ public static function getHandler($handler): string )); } - // Versions 1.x and 2.x required the full path (e.g. my-app.com/handle-task). In 3.x and beyond - // it is no longer necessary to also include the path and simply setting the handler - // URL is enough. If someone upgrades and forgets we will warn them here. - if (!empty($parse['path'])) { - throw new Exception( - 'Unable to push task to Cloud Tasks because the task handler URL (' . $handler . ') is not ' . - 'compatible. To fix this, please remove \'' . $parse['path'] . '\' from the URL, ' . - 'or copy from here: STACKKIT_CLOUD_TASKS_HANDLER=' . $parse['scheme'] . '://' . $parse['host'] - ); + $trimmedHandlerUrl = rtrim($handler, '/'); + + if (!str_ends_with($trimmedHandlerUrl, '/handle-task')) { + return $trimmedHandlerUrl . '/handle-task'; } - return $handler . '/handle-task'; + return $trimmedHandlerUrl; } catch (UrlException $e) { throw new Exception( 'Unable to push task to Cloud Tasks because the task handler URL (' . $handler . ') is ' . diff --git a/tests/ConfigHandlerTest.php b/tests/ConfigHandlerTest.php new file mode 100644 index 0000000..c15cd6a --- /dev/null +++ b/tests/ConfigHandlerTest.php @@ -0,0 +1,27 @@ + Date: Wed, 24 Jan 2024 15:05:35 +1100 Subject: [PATCH 2/2] feat: Support path in STACKKIT_CLOUD_TASKS_HANDLER --- src/Config.php | 2 +- tests/ConfigHandlerTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Config.php b/src/Config.php index 588de73..422ce44 100644 --- a/src/Config.php +++ b/src/Config.php @@ -66,7 +66,7 @@ public static function getHandler($handler): string $trimmedHandlerUrl = rtrim($handler, '/'); if (!str_ends_with($trimmedHandlerUrl, '/handle-task')) { - return $trimmedHandlerUrl . '/handle-task'; + return "$trimmedHandlerUrl/handle-task"; } return $trimmedHandlerUrl; diff --git a/tests/ConfigHandlerTest.php b/tests/ConfigHandlerTest.php index c15cd6a..523f6a4 100644 --- a/tests/ConfigHandlerTest.php +++ b/tests/ConfigHandlerTest.php @@ -4,7 +4,7 @@ use Stackkit\LaravelGoogleCloudTasksQueue\Config; -class ConfigHandlerTest extends TestCase +class ConfigHandlerTest extends \PHPUnit\Framework\TestCase { /** * @dataProvider handlerDataProvider @@ -24,4 +24,4 @@ public function handlerDataProvider(): array ['https://example.com/handle-task/', 'https://example.com/handle-task'], ]; } -} \ No newline at end of file +}