Skip to content

Commit

Permalink
Make toRelative check the config internally
Browse files Browse the repository at this point in the history
  • Loading branch information
daftspunk committed Dec 3, 2023
1 parent dfcc9b2 commit 9572a6b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/Html/UrlServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php namespace October\Rain\Html;

use Str;
use Config;
use Illuminate\Support\ServiceProvider;

/**
Expand Down Expand Up @@ -59,10 +60,14 @@ public function registerRelativeHelper()
$provider = $this->app['url'];

$provider->macro('toRelative', function($url) use ($provider) {
$fullUrl = $provider->to($url);
return parse_url($fullUrl, PHP_URL_PATH)
. (($query = parse_url($fullUrl, PHP_URL_QUERY)) ? '?' . $query : '')
. (($fragment = parse_url($fullUrl, PHP_URL_FRAGMENT)) ? '#' . $fragment : '');
if (Config::get('system.relative_links', false)) {
$fullUrl = $provider->to($url);
return parse_url($fullUrl, PHP_URL_PATH)
. (($query = parse_url($fullUrl, PHP_URL_QUERY)) ? '?' . $query : '')
. (($fragment = parse_url($fullUrl, PHP_URL_FRAGMENT)) ? '#' . $fragment : '');
}

return $provider->to($url);
});
}

Expand Down

0 comments on commit 9572a6b

Please sign in to comment.