Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bb6b6b2

Browse files
committed
ADD baseUrl() and siteUrl() shorthands
1 parent 8efde82 commit bb6b6b2

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

‎composer.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
}
1717
],
1818
"autoload": {
19+
"files": [ "src/functions.php" ],
1920
"psr-4": {
2021
"Francerz\\Http\\Utils\\": "src/utils",
2122
"Francerz\\Http\\Utils\\Headers\\": "src/headers",

‎src/functions.php‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Francerz\Http\Utils;
4+
5+
use Francerz\Http\Utils\UriHelper;
6+
7+
if (!function_exists('siteUrl')) {
8+
function siteUrl(?string $path = null, array $sapiVars = [])
9+
{
10+
return UriHelper::getSiteUrl($path, $sapiVars);
11+
}
12+
}
13+
14+
if (!function_exists('baseUrl')) {
15+
function baseUrl(?string $path = null, array $sapiVars = [])
16+
{
17+
return UriHelper::getBaseUrl($path, $sapiVars);
18+
}
19+
}

‎test/UriHelperTest.php‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
use Francerz\Http\Utils\UriHelper;
44
use PHPUnit\Framework\TestCase;
55

6+
use function Francerz\Http\Utils\baseUrl;
7+
use function Francerz\Http\Utils\siteUrl;
8+
69
class UriHelperTest extends TestCase
710
{
811
private static function callPrivateStatic($obj, string $method, ...$args)
@@ -55,7 +58,7 @@ public function testGetBaseUrl()
5558
{
5659
$this->assertEquals(
5760
'http://localhost/assets/css/style.css',
58-
UriHelper::getBaseUrl('/assets/css/style.css', [
61+
baseUrl('/assets/css/style.css', [
5962
'HTTP_HOST' => 'localhost',
6063
'SCRIPT_NAME' => '/index.php'
6164
])
@@ -100,7 +103,7 @@ public function testGetSiteUrl()
100103
{
101104
$this->assertEquals(
102105
'https://localhost:3000/public/index.php/some/path',
103-
UriHelper::getSiteUrl('/some/path', [
106+
siteUrl('/some/path', [
104107
'HTTPS' => 'on',
105108
'SERVER_NAME' => 'localhost',
106109
'SERVER_PORT' => 3000,

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /