File tree Expand file tree Collapse file tree 2 files changed +32
-10
lines changed Expand file tree Collapse file tree 2 files changed +32
-10
lines changed Original file line number Diff line number Diff 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 ' .
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments