Skip to content

Commit 0b418db

Browse files
committed
Use facades/classes instead of global functions
1 parent 12ab23c commit 0b418db

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/Macros/UriTranslationMacro.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace CodeZero\LocalizedRoutes\Macros;
44

5+
use Illuminate\Support\Collection;
6+
use Illuminate\Support\Str;
57
use Lang;
68

79
class UriTranslationMacro
@@ -15,7 +17,7 @@ public static function register()
1517
{
1618
Lang::macro('uri', function ($uri, $locale = null) {
1719
// Split the URI into a Collection of segments.
18-
$segments = collect(explode('/', trim($uri, '/')));
20+
$segments = new Collection(explode('/', trim($uri, '/')));
1921

2022
// Attempt to translate each segment. If there is no translation
2123
// for a specific segment, then its original value will be used.
@@ -24,7 +26,7 @@ public static function register()
2426

2527
// If the segment is not a placeholder and the segment
2628
// has a translation, then update the segment.
27-
if ( ! starts_with($segment, '{') && Lang::has($translationKey, $locale)) {
29+
if ( ! Str::startsWith($segment, '{') && Lang::has($translationKey, $locale)) {
2830
$segment = Lang::get($translationKey, [], $locale);
2931
}
3032

src/UrlGenerator.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace CodeZero\LocalizedRoutes;
44

5+
use App;
6+
use Config;
57
use Illuminate\Http\Request;
68
use Illuminate\Routing\RouteCollection;
79
use Illuminate\Routing\UrlGenerator as BaseUrlGenerator;
@@ -45,22 +47,22 @@ public function route($name, $parameters = [], $absolute = true, $locale = null)
4547
// Cache the current locale so we can change it
4648
// to automatically resolve any translatable
4749
// route parameters such as slugs.
48-
$currentLocale = app()->getLocale();
50+
$currentLocale = App::getLocale();
4951

5052
// Use the specified or current locale
5153
// as a prefix for the route name.
5254
$locale = $locale ?: $currentLocale;
5355

5456
// Update the current locale if needed.
5557
if ($locale !== $currentLocale) {
56-
app()->setLocale($locale);
58+
App::setLocale($locale);
5759
}
5860

5961
$url = parent::route("{$locale}.{$name}", $parameters, $absolute);
6062

6163
// Restore the current locale if needed.
6264
if ($locale !== $currentLocale) {
63-
app()->setLocale($currentLocale);
65+
App::setLocale($currentLocale);
6466
}
6567

6668
return $url;
@@ -83,7 +85,7 @@ protected function stripLocaleFromRouteName($name)
8385
return $name;
8486
}
8587

86-
$locales = config('app.locales', []);
88+
$locales = Config::get('app.locales', []);
8789

8890
// If the first part of the route name is a valid
8991
// locale, then remove it from the array.

0 commit comments

Comments
 (0)