Skip to content

Commit a2a2b21

Browse files
Merge pull request #127 from andrew-broberg-five9/add-support-for-handler-to-contain-path
feat: Support path in STACKKIT_CLOUD_TASKS_HANDLER
2 parents ef17e01 + 188a7c0 commit a2a2b21

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

src/Config.php

+5-10
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,13 @@ public static function getHandler($handler): string
6363
));
6464
}
6565

66-
// Versions 1.x and 2.x required the full path (e.g. my-app.com/handle-task). In 3.x and beyond
67-
// it is no longer necessary to also include the path and simply setting the handler
68-
// URL is enough. If someone upgrades and forgets we will warn them here.
69-
if (!empty($parse['path'])) {
70-
throw new Exception(
71-
'Unable to push task to Cloud Tasks because the task handler URL (' . $handler . ') is not ' .
72-
'compatible. To fix this, please remove \'' . $parse['path'] . '\' from the URL, ' .
73-
'or copy from here: STACKKIT_CLOUD_TASKS_HANDLER=' . $parse['scheme'] . '://' . $parse['host']
74-
);
66+
$trimmedHandlerUrl = rtrim($handler, '/');
67+
68+
if (!str_ends_with($trimmedHandlerUrl, '/handle-task')) {
69+
return "$trimmedHandlerUrl/handle-task";
7570
}
7671

77-
return $handler . '/handle-task';
72+
return $trimmedHandlerUrl;
7873
} catch (UrlException $e) {
7974
throw new Exception(
8075
'Unable to push task to Cloud Tasks because the task handler URL (' . $handler . ') is ' .

tests/ConfigHandlerTest.php

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Tests;
4+
5+
use Stackkit\LaravelGoogleCloudTasksQueue\Config;
6+
7+
class ConfigHandlerTest extends \PHPUnit\Framework\TestCase
8+
{
9+
/**
10+
* @dataProvider handlerDataProvider
11+
*/
12+
public function test_it_allows_a_handler_url_to_contain_path(string $handler, string $expectedHandler): void
13+
{
14+
self::assertSame($expectedHandler, Config::getHandler($handler));
15+
}
16+
17+
public function handlerDataProvider(): array
18+
{
19+
return [
20+
['https://example.com', 'https://example.com/handle-task'],
21+
['https://example.com/my/path', 'https://example.com/my/path/handle-task'],
22+
['https://example.com/trailing/slashes//', 'https://example.com/trailing/slashes/handle-task'],
23+
['https://example.com/handle-task', 'https://example.com/handle-task'],
24+
['https://example.com/handle-task/', 'https://example.com/handle-task'],
25+
];
26+
}
27+
}

0 commit comments

Comments
 (0)