From 92e34b743432a47f3be6d460b0c48f044ed96882 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Fri, 30 Sep 2016 14:09:33 +1300 Subject: [PATCH] API controller::join_links supports array values --- Control/Controller.php | 11 +++++++---- docs/en/04_Changelogs/4.0.0.md | 1 + tests/control/ControllerTest.php | 5 +++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Control/Controller.php b/Control/Controller.php index e4f641d58..375718efc 100644 --- a/Control/Controller.php +++ b/Control/Controller.php @@ -695,12 +695,15 @@ class Controller extends RequestHandler implements TemplateGlobalProvider { * * Caution: All parameters are expected to be URI-encoded already. * - * @param string - * + * @param string|array $arg,.. One or more link segments, or list of link segments as an array * @return string */ - public static function join_links() { - $args = func_get_args(); + public static function join_links($arg = null) { + if (func_num_args() === 1 && is_array($arg)) { + $args = $arg; + } else { + $args = func_get_args(); + } $result = ""; $queryargs = array(); $fragmentIdentifier = null; diff --git a/docs/en/04_Changelogs/4.0.0.md b/docs/en/04_Changelogs/4.0.0.md index 09ca650ba..f71d6ee2d 100644 --- a/docs/en/04_Changelogs/4.0.0.md +++ b/docs/en/04_Changelogs/4.0.0.md @@ -792,6 +792,7 @@ specific functions. Run `composer require --dev 'phpunit/phpunit:~4.8'` on existing projects to pull in the new dependency. * Admin URL can now be configured via custom Director routing rule * `Controller::init` visibility changed to protected. Use `Controller::doInit()` instead. +* `Controller::join_links` supports an array of link sections. * `Object::useCustomClass` has been removed. You should use the config API with Injector instead. * `Object::invokeWithExtensions` now has the same method signature as `Object::extend` and behaves the same way. * `ServiceConfigurationLocator` is now an interface not a class. diff --git a/tests/control/ControllerTest.php b/tests/control/ControllerTest.php index 8faedd0d3..a79001b57 100644 --- a/tests/control/ControllerTest.php +++ b/tests/control/ControllerTest.php @@ -283,6 +283,11 @@ class ControllerTest extends FunctionalTest { /* Does type-safe checks for zero value */ $this->assertEquals("my-page/0", Controller::join_links("my-page", 0)); + + // Test array args + $this->assertEquals("admin/crm/MyForm?a=1&b=2&c=3", + Controller::join_links(["?a=1", "admin/crm", "?b=2", "MyForm?c=3"]) + ); } public function testLink() {