diff --git a/.upgradenotes/MDL-84351-2025040804272401.yml b/.upgradenotes/MDL-84351-2025040804272401.yml new file mode 100644 index 00000000000..efeccda0e0f --- /dev/null +++ b/.upgradenotes/MDL-84351-2025040804272401.yml @@ -0,0 +1,5 @@ +issueNumber: MDL-84351 +notes: + core: + - message: The public method `get_slashargument` has been added to the `url` class. + type: improved diff --git a/lib/classes/url.php b/lib/classes/url.php index 5af50cf9beb..f390760a240 100644 --- a/lib/classes/url.php +++ b/lib/classes/url.php @@ -936,6 +936,17 @@ All values that are not arrays should be a string.'); public function get_port() { return $this->port; } + + /** + * Returns the 'slashargument' portion of a URL. For example, if the URL is + * http://www.example.org.com/pluginfile.php/1/core_admin/logocompact/ then this will + * return '1/core_admin/logocompact/'. + * + * @return string Slash argument as string. + */ + public function get_slashargument(): string { + return $this->slashargument; + } } // Alias this class to the old name. diff --git a/lib/tests/url_test.php b/lib/tests/url_test.php index 5f6a9693784..4592a05fe9e 100644 --- a/lib/tests/url_test.php +++ b/lib/tests/url_test.php @@ -334,6 +334,19 @@ final class url_test extends \advanced_testcase { $this->assertMatchesRegularExpression($expected, $url->out(true)); } + /** + * Test the get_slashargument method. + */ + public function test_get_slashargument(): void { + $this->resetAfterTest(); + + $url = new url('/pluginfile.php/14/user/private/capybara.png'); + $this->assertEquals('/14/user/private/capybara.png', $url->get_slashargument()); + + $url = new url('/image/capybara.png'); + $this->assertEmpty($url->get_slashargument()); + } + /** * Data provider for make_pluginfile_url tests. *