diff --git a/composer.json b/composer.json index c12b0a0f..c468981a 100644 --- a/composer.json +++ b/composer.json @@ -51,6 +51,7 @@ "illuminate/collections": "^10.0 || ^11.0", "illuminate/console": "^10.0 || ^11.0", "illuminate/support": "^10.0 || ^11.0", + "laravel-lang/config": "^1.0", "laravel-lang/locales": "^2.3", "league/commonmark": "^2.4.1", "league/config": "^1.2" diff --git a/config/private.php b/config/private.php deleted file mode 100644 index bcf31f0e..00000000 --- a/config/private.php +++ /dev/null @@ -1,21 +0,0 @@ - - * @copyright 2024 Laravel Lang Team - * @license MIT - * - * @see https://laravel-lang.com - */ - -declare(strict_types=1); - -return [ - 'plugins' => [], - 'packages' => [], -]; diff --git a/config/public.php b/config/public.php deleted file mode 100644 index 7504dc03..00000000 --- a/config/public.php +++ /dev/null @@ -1,98 +0,0 @@ - - * @copyright 2024 Laravel Lang Team - * @license MIT - * - * @see https://laravel-lang.com - */ - -declare(strict_types=1); - -use LaravelLang\LocaleList\Locale; - -return [ - /* - * Determines what type of files to use when updating language files. - * - * `true` means inline files will be used. - * `false` means that default files will be used. - * - * For example, the difference between them can be seen here: - * - * The :attribute must be accepted. // default - * This field must be accepted. // inline - * - * By default, `false`. - */ - - 'inline' => (bool) env('LANG_PUBLISHER_INLINE', false), - - /* - * Do arrays need to be aligned by keys before processing arrays? - * - * By default, true - */ - - 'align' => (bool) env('LANG_PUBLISHER_ALIGN', true), - - /* - * This option determines the mechanism for converting translation - * keys into a typographic version. - * - * For example: - * for `false`: - * "It's super-configurable... you can even use additional extensions to expand its capabilities -- just like this one!" - * for `true`: - * “It’s super-configurable… you can even use additional extensions to expand its capabilities – just like this one!” - * - * By default, false - */ - - 'smart_punctuation' => [ - 'enable' => false, - - 'common' => [ - 'double_quote_opener' => '“', - 'double_quote_closer' => '”', - 'single_quote_opener' => '‘', - 'single_quote_closer' => '’', - ], - - 'locales' => [ - Locale::French->value => [ - 'double_quote_opener' => '« ', - 'double_quote_closer' => ' »', - 'single_quote_opener' => '‘', - 'single_quote_closer' => '’', - ], - - Locale::Russian->value => [ - 'double_quote_opener' => '«', - 'double_quote_closer' => '»', - 'single_quote_opener' => '‘', - 'single_quote_closer' => '’', - ], - - Locale::Ukrainian->value => [ - 'double_quote_opener' => '«', - 'double_quote_closer' => '»', - 'single_quote_opener' => '‘', - 'single_quote_closer' => '’', - ], - - Locale::Belarusian->value => [ - 'double_quote_opener' => '«', - 'double_quote_closer' => '»', - 'single_quote_opener' => '‘', - 'single_quote_closer' => '’', - ], - ], - ], -]; diff --git a/src/Concerns/About.php b/src/Concerns/About.php index 7a4ecac7..071a641a 100644 --- a/src/Concerns/About.php +++ b/src/Concerns/About.php @@ -20,7 +20,7 @@ use Composer\InstalledVersions; use DragonCode\Support\Facades\Helpers\Arr; use Illuminate\Foundation\Console\AboutCommand; -use LaravelLang\Locales\Enums\Config; +use LaravelLang\Config\Facades\Config; trait About { @@ -40,7 +40,7 @@ protected function pushInformation(callable $data): void protected function getPackages(): array { - return Arr::of(config(Config::PrivateKey() . '.packages')) + return Arr::of(Config::hidden()->packages->all()) ->renameKeys(static fn (mixed $key, array $values) => $values['class']) ->map(fn (array $values) => $this->getPackageVersion($values['name'])) ->toArray(); diff --git a/src/Helpers/Config.php b/src/Helpers/Config.php index 25b5d0b3..e5e1654c 100644 --- a/src/Helpers/Config.php +++ b/src/Helpers/Config.php @@ -17,11 +17,11 @@ namespace LaravelLang\Publisher\Helpers; -use DragonCode\Contracts\Support\Stringable; +use LaravelLang\Config\Facades\Config as BaseConfig; use LaravelLang\LocaleList\Locale; use LaravelLang\Locales\Concerns\Aliases; -use LaravelLang\Locales\Enums\Config as ConfigEnum; use LaravelLang\Publisher\Constants\Types; +use Stringable; class Config { @@ -33,21 +33,17 @@ public function __construct( public function getPlugins(): array { - return $this->getPrivate('plugins', []); + return BaseConfig::hidden()->plugins->all(); } public function setPlugins(string $path, array $plugins): void { - $items = array_merge($this->getPlugins(), [ - $path => $plugins, - ]); - - $this->setPrivate('plugins', $items); + BaseConfig::hidden()->plugins->set($path, $plugins); } public function getPackages(): array { - return $this->getPrivate('packages', []); + return BaseConfig::hidden()->packages->all(); } public function getPackageNameByPath(string $path, Types $type = Types::TypeName): string @@ -59,14 +55,10 @@ public function getPackageNameByPath(string $path, Types $type = Types::TypeName public function setPackage(string $base_path, string $plugin_class, string $package_name): void { - $items = $this->getPackages(); - - $items[$base_path] = [ + BaseConfig::hidden()->packages->set($base_path, [ 'class' => $plugin_class, 'name' => $package_name, - ]; - - $this->setPrivate('packages', $items); + ]); } public function langPath(Locale|string|null ...$paths): string @@ -81,49 +73,22 @@ public function langPath(Locale|string|null ...$paths): string public function hasInline(): bool { - return $this->getPublic('inline', false); + return BaseConfig::shared()->inline; } public function hasAlign(): bool { - return $this->getPublic('align', true); + return BaseConfig::shared()->align; } public function hasSmartPunctuation(): bool { - return $this->getPublic('smart_punctuation.enable', false); + return BaseConfig::shared()->punctuation->enabled; } public function smartPunctuationConfig(string $locale): array { - $default = $this->getPublic('smart_punctuation.common', []); - - return $this->getPublic('smart_punctuation.locales.' . $locale, $default); - } - - public function setPrivate(string $key, mixed $value): void - { - $this->set(ConfigEnum::PrivateKey(), $key, $value); - } - - protected function getPrivate(string $key, mixed $default = null): mixed - { - return $this->get(ConfigEnum::PrivateKey(), $key, $default); - } - - protected function getPublic(string $key, mixed $default = null): mixed - { - return $this->get(ConfigEnum::PublicKey(), $key, $default); - } - - protected function get(string $visibility, string $key, mixed $default = null): mixed - { - return config()->get($visibility . '.' . $key, $default); - } - - protected function set(string $visibility, string $key, mixed $value): void - { - config()->set($visibility . '.' . $key, $value); + return BaseConfig::shared()->punctuation->locales->get($locale); } protected function path(string $base, string|Stringable|null $suffix = null): string diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 35112113..8fcaec22 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -18,7 +18,6 @@ namespace LaravelLang\Publisher; use Illuminate\Support\ServiceProvider as BaseServiceProvider; -use LaravelLang\Locales\Enums\Config; use LaravelLang\Publisher\Concerns\About; use LaravelLang\Publisher\Console\Add; use LaravelLang\Publisher\Console\Remove; @@ -31,13 +30,11 @@ class ServiceProvider extends BaseServiceProvider public function boot(): void { - $this->bootPublishes(); $this->bootCommands(); } public function register(): void { - $this->registerConfig(); $this->registerAbout(); } @@ -50,18 +47,4 @@ protected function bootCommands(): void Update::class, ]); } - - protected function bootPublishes(): void - { - $this->publishes( - [__DIR__ . '/../config/public.php' => $this->app->configPath(Config::PublicKey() . '.php')], - ['config', Config::PublicKey()] - ); - } - - protected function registerConfig(): void - { - $this->mergeConfigFrom(__DIR__ . '/../config/public.php', Config::PublicKey()); - $this->mergeConfigFrom(__DIR__ . '/../config/private.php', Config::PrivateKey()); - } } diff --git a/tests/TestCase.php b/tests/TestCase.php index beb9d3a2..b25ade76 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -20,6 +20,8 @@ use DragonCode\Support\Facades\Filesystem\Directory; use Illuminate\Support\Facades\App; use Illuminate\Translation\TranslationServiceProvider; +use LaravelLang\Config\Enums\Name; +use LaravelLang\Config\ServiceProvider as ConfigServiceProvider; use LaravelLang\JsonFallback\TranslationServiceProvider as FixedTranslationServiceProvider; use LaravelLang\LocaleList\Locale; use LaravelLang\Locales\Facades\Locales; @@ -66,6 +68,7 @@ protected function getPackageProviders($app): array LocalesServiceProvider::class, PublisherServiceProvider::class, PluginServiceProvider::class, + ConfigServiceProvider::class, ]; } @@ -81,11 +84,8 @@ protected function getEnvironmentSetUp($app): void /** @var \Illuminate\Config\Repository $config */ $config = $app['config']; - $config->set(\LaravelLang\Locales\Enums\Config::PublicKey() . '.inline', $this->inline); - $config->set( - \LaravelLang\Locales\Enums\Config::PublicKey() . '.smart_punctuation.enable', - $this->smartPunctuation - ); + $config->set(Name::Shared() . '.inline', $this->inline); + $config->set(Name::Shared() . '.smart_punctuation.enable', $this->smartPunctuation); $config->set('app.locale', $this->locale->value); $config->set('app.fallback_locale', $this->fallbackLocale->value);