Skip to content

Commit a07099f

Browse files
committed
Use optional defaults in constructor
1 parent 26ba1d4 commit a07099f

File tree

2 files changed

+5
-21
lines changed

2 files changed

+5
-21
lines changed

src/Localizer.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use CodeZero\Localizer\Detectors\Detector;
66
use Illuminate\Support\Facades\App;
7+
use Illuminate\Support\Facades\Config;
78

89
class Localizer
910
{
@@ -35,11 +36,11 @@ class Localizer
3536
* @param \Illuminate\Support\Collection|array $detectors
3637
* @param \Illuminate\Support\Collection|array $stores
3738
*/
38-
public function __construct($locales, $detectors, $stores = [])
39+
public function __construct($locales = null, $detectors = null, $stores = null)
3940
{
40-
$this->locales = $locales;
41-
$this->detectors = $detectors;
42-
$this->stores = $stores;
41+
$this->locales = $locales ?: Config::get('localizer.supported-locales');
42+
$this->detectors = $detectors ?: Config::get('localizer.detectors');
43+
$this->stores = $stores ?: Config::get('localizer.stores');
4344
}
4445

4546
/**

src/LocalizerServiceProvider.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public function boot()
3131
public function register()
3232
{
3333
$this->mergeConfig();
34-
$this->registerLocalizer();
3534
}
3635

3736
/**
@@ -56,20 +55,4 @@ protected function mergeConfig()
5655
{
5756
$this->mergeConfigFrom(__DIR__."/../config/{$this->name}.php", $this->name);
5857
}
59-
60-
/**
61-
* Register Localizer.
62-
*
63-
* @return void
64-
*/
65-
protected function registerLocalizer()
66-
{
67-
$this->app->bind(Localizer::class, function ($app) {
68-
$locales = $app['config']->get("{$this->name}.supported-locales");
69-
$detectors = $app['config']->get("{$this->name}.detectors");
70-
$stores = $app['config']->get("{$this->name}.stores");
71-
72-
return new Localizer($locales, $detectors, $stores);
73-
});
74-
}
7558
}

0 commit comments

Comments
 (0)