diff --git a/src/Config.php b/src/Config.php index 9ffd34b..422ce44 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..523f6a4 --- /dev/null +++ b/tests/ConfigHandlerTest.php @@ -0,0 +1,27 @@ +