Skip to content

Commit 7812e7a

Browse files
Merge pull request #356 from Laravel-Lang/16.x
Configuration management is transferred to an external repository
2 parents 9787404 + 09bcf3b commit 7812e7a

File tree

7 files changed

+19
-189
lines changed

7 files changed

+19
-189
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"illuminate/collections": "^10.0 || ^11.0",
5252
"illuminate/console": "^10.0 || ^11.0",
5353
"illuminate/support": "^10.0 || ^11.0",
54+
"laravel-lang/config": "^1.0",
5455
"laravel-lang/locales": "^2.3",
5556
"league/commonmark": "^2.4.1",
5657
"league/config": "^1.2"

config/private.php

Lines changed: 0 additions & 21 deletions
This file was deleted.

config/public.php

Lines changed: 0 additions & 98 deletions
This file was deleted.

src/Concerns/About.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Composer\InstalledVersions;
2121
use DragonCode\Support\Facades\Helpers\Arr;
2222
use Illuminate\Foundation\Console\AboutCommand;
23-
use LaravelLang\Locales\Enums\Config;
23+
use LaravelLang\Config\Facades\Config;
2424

2525
trait About
2626
{
@@ -40,7 +40,7 @@ protected function pushInformation(callable $data): void
4040

4141
protected function getPackages(): array
4242
{
43-
return Arr::of(config(Config::PrivateKey() . '.packages'))
43+
return Arr::of(Config::hidden()->packages->all())
4444
->renameKeys(static fn (mixed $key, array $values) => $values['class'])
4545
->map(fn (array $values) => $this->getPackageVersion($values['name']))
4646
->toArray();

src/Helpers/Config.php

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717

1818
namespace LaravelLang\Publisher\Helpers;
1919

20-
use DragonCode\Contracts\Support\Stringable;
20+
use LaravelLang\Config\Facades\Config as BaseConfig;
2121
use LaravelLang\LocaleList\Locale;
2222
use LaravelLang\Locales\Concerns\Aliases;
23-
use LaravelLang\Locales\Enums\Config as ConfigEnum;
2423
use LaravelLang\Publisher\Constants\Types;
24+
use Stringable;
2525

2626
class Config
2727
{
@@ -33,21 +33,17 @@ public function __construct(
3333

3434
public function getPlugins(): array
3535
{
36-
return $this->getPrivate('plugins', []);
36+
return BaseConfig::hidden()->plugins->all();
3737
}
3838

3939
public function setPlugins(string $path, array $plugins): void
4040
{
41-
$items = array_merge($this->getPlugins(), [
42-
$path => $plugins,
43-
]);
44-
45-
$this->setPrivate('plugins', $items);
41+
BaseConfig::hidden()->plugins->set($path, $plugins);
4642
}
4743

4844
public function getPackages(): array
4945
{
50-
return $this->getPrivate('packages', []);
46+
return BaseConfig::hidden()->packages->all();
5147
}
5248

5349
public function getPackageNameByPath(string $path, Types $type = Types::TypeName): string
@@ -59,14 +55,10 @@ public function getPackageNameByPath(string $path, Types $type = Types::TypeName
5955

6056
public function setPackage(string $base_path, string $plugin_class, string $package_name): void
6157
{
62-
$items = $this->getPackages();
63-
64-
$items[$base_path] = [
58+
BaseConfig::hidden()->packages->set($base_path, [
6559
'class' => $plugin_class,
6660
'name' => $package_name,
67-
];
68-
69-
$this->setPrivate('packages', $items);
61+
]);
7062
}
7163

7264
public function langPath(Locale|string|null ...$paths): string
@@ -81,49 +73,22 @@ public function langPath(Locale|string|null ...$paths): string
8173

8274
public function hasInline(): bool
8375
{
84-
return $this->getPublic('inline', false);
76+
return BaseConfig::shared()->inline;
8577
}
8678

8779
public function hasAlign(): bool
8880
{
89-
return $this->getPublic('align', true);
81+
return BaseConfig::shared()->align;
9082
}
9183

9284
public function hasSmartPunctuation(): bool
9385
{
94-
return $this->getPublic('smart_punctuation.enable', false);
86+
return BaseConfig::shared()->punctuation->enabled;
9587
}
9688

9789
public function smartPunctuationConfig(string $locale): array
9890
{
99-
$default = $this->getPublic('smart_punctuation.common', []);
100-
101-
return $this->getPublic('smart_punctuation.locales.' . $locale, $default);
102-
}
103-
104-
public function setPrivate(string $key, mixed $value): void
105-
{
106-
$this->set(ConfigEnum::PrivateKey(), $key, $value);
107-
}
108-
109-
protected function getPrivate(string $key, mixed $default = null): mixed
110-
{
111-
return $this->get(ConfigEnum::PrivateKey(), $key, $default);
112-
}
113-
114-
protected function getPublic(string $key, mixed $default = null): mixed
115-
{
116-
return $this->get(ConfigEnum::PublicKey(), $key, $default);
117-
}
118-
119-
protected function get(string $visibility, string $key, mixed $default = null): mixed
120-
{
121-
return config()->get($visibility . '.' . $key, $default);
122-
}
123-
124-
protected function set(string $visibility, string $key, mixed $value): void
125-
{
126-
config()->set($visibility . '.' . $key, $value);
91+
return BaseConfig::shared()->punctuation->locales->get($locale);
12792
}
12893

12994
protected function path(string $base, string|Stringable|null $suffix = null): string

src/ServiceProvider.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
namespace LaravelLang\Publisher;
1919

2020
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
21-
use LaravelLang\Locales\Enums\Config;
2221
use LaravelLang\Publisher\Concerns\About;
2322
use LaravelLang\Publisher\Console\Add;
2423
use LaravelLang\Publisher\Console\Remove;
@@ -31,13 +30,11 @@ class ServiceProvider extends BaseServiceProvider
3130

3231
public function boot(): void
3332
{
34-
$this->bootPublishes();
3533
$this->bootCommands();
3634
}
3735

3836
public function register(): void
3937
{
40-
$this->registerConfig();
4138
$this->registerAbout();
4239
}
4340

@@ -50,18 +47,4 @@ protected function bootCommands(): void
5047
Update::class,
5148
]);
5249
}
53-
54-
protected function bootPublishes(): void
55-
{
56-
$this->publishes(
57-
[__DIR__ . '/../config/public.php' => $this->app->configPath(Config::PublicKey() . '.php')],
58-
['config', Config::PublicKey()]
59-
);
60-
}
61-
62-
protected function registerConfig(): void
63-
{
64-
$this->mergeConfigFrom(__DIR__ . '/../config/public.php', Config::PublicKey());
65-
$this->mergeConfigFrom(__DIR__ . '/../config/private.php', Config::PrivateKey());
66-
}
6750
}

tests/TestCase.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
use DragonCode\Support\Facades\Filesystem\Directory;
2121
use Illuminate\Support\Facades\App;
2222
use Illuminate\Translation\TranslationServiceProvider;
23+
use LaravelLang\Config\Enums\Name;
24+
use LaravelLang\Config\ServiceProvider as ConfigServiceProvider;
2325
use LaravelLang\JsonFallback\TranslationServiceProvider as FixedTranslationServiceProvider;
2426
use LaravelLang\LocaleList\Locale;
2527
use LaravelLang\Locales\Facades\Locales;
@@ -66,6 +68,7 @@ protected function getPackageProviders($app): array
6668
LocalesServiceProvider::class,
6769
PublisherServiceProvider::class,
6870
PluginServiceProvider::class,
71+
ConfigServiceProvider::class,
6972
];
7073
}
7174

@@ -81,11 +84,8 @@ protected function getEnvironmentSetUp($app): void
8184
/** @var \Illuminate\Config\Repository $config */
8285
$config = $app['config'];
8386

84-
$config->set(\LaravelLang\Locales\Enums\Config::PublicKey() . '.inline', $this->inline);
85-
$config->set(
86-
\LaravelLang\Locales\Enums\Config::PublicKey() . '.smart_punctuation.enable',
87-
$this->smartPunctuation
88-
);
87+
$config->set(Name::Shared() . '.inline', $this->inline);
88+
$config->set(Name::Shared() . '.smart_punctuation.enable', $this->smartPunctuation);
8989

9090
$config->set('app.locale', $this->locale->value);
9191
$config->set('app.fallback_locale', $this->fallbackLocale->value);

0 commit comments

Comments
 (0)