Skip to content

Commit

Permalink
Merge pull request #356 from Laravel-Lang/16.x
Browse files Browse the repository at this point in the history
Configuration management is transferred to an external repository
  • Loading branch information
andrey-helldar authored Jun 2, 2024
2 parents 9787404 + 09bcf3b commit 7812e7a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 189 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 0 additions & 21 deletions config/private.php

This file was deleted.

98 changes: 0 additions & 98 deletions config/public.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/Concerns/About.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();
Expand Down
57 changes: 11 additions & 46 deletions src/Helpers/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
17 changes: 0 additions & 17 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,13 +30,11 @@ class ServiceProvider extends BaseServiceProvider

public function boot(): void
{
$this->bootPublishes();
$this->bootCommands();
}

public function register(): void
{
$this->registerConfig();
$this->registerAbout();
}

Expand All @@ -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());
}
}
10 changes: 5 additions & 5 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -66,6 +68,7 @@ protected function getPackageProviders($app): array
LocalesServiceProvider::class,
PublisherServiceProvider::class,
PluginServiceProvider::class,
ConfigServiceProvider::class,
];
}

Expand All @@ -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);
Expand Down

0 comments on commit 7812e7a

Please sign in to comment.