Skip to content

Commit

Permalink
The configurator interface has been prepared
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-helldar committed Jun 1, 2024
1 parent 9e6816f commit 07267de
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 3 deletions.
6 changes: 3 additions & 3 deletions config/public.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
* By default, `false`.
*/

'inline' => (bool) env('LOCALIZATION_INLINE', false),
'inline' => (bool)env('LOCALIZATION_INLINE', false),

/*
* Do arrays need to be aligned by keys before processing arrays?
*
* By default, true
*/

'align' => (bool) env('LOCALIZATION_ALIGN', true),
'align' => (bool)env('LOCALIZATION_ALIGN', true),

/*
* This option determines the mechanism for converting translation
Expand All @@ -41,7 +41,7 @@
*/

'smart_punctuation' => [
'enable' => (bool) env('LOCALIZATION_SMART_ENABLED', false),
'enable' => (bool)env('LOCALIZATION_SMART_ENABLED', false),

'common' => [
'double_quote_opener' => '',
Expand Down
15 changes: 15 additions & 0 deletions src/Data/HiddenData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace LaravelLang\Config\Data;

class HiddenData
{
public function __construct(
public PushableData $plugins,
public PushableData $packages,
public readonly array $map,
) {
}
}
32 changes: 32 additions & 0 deletions src/Data/PushableData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace LaravelLang\Config\Data;

class PushableData
{
public function __construct(
public array $items
) {
}

public function get(): array
{
return $this->items;
}

public function push(mixed $value): static
{
$this->items[] = $value;

return $this;
}

public function set(int | string $key, mixed $value): static
{
$this->items[$key] = $value;

return $this;
}
}
16 changes: 16 additions & 0 deletions src/Data/SharedData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace LaravelLang\Config\Data;

class SharedData
{
public function __construct(
public bool $inline,
public bool $align,
public array $aliases,
public SmartPunctuationData $smartPunctuation,
) {
}
}
15 changes: 15 additions & 0 deletions src/Data/SmartPunctuationData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace LaravelLang\Config\Data;

class SmartPunctuationData
{
public function __construct(
public bool $enabled,
public array $common,
public array $locales,
) {
}
}
55 changes: 55 additions & 0 deletions src/Facades/Config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace LaravelLang\Config\Facades;

use Illuminate\Config\Repository;
use LaravelLang\Config\Data\HiddenData;
use LaravelLang\Config\Data\PushableData;
use LaravelLang\Config\Data\SharedData;
use LaravelLang\Config\Data\SmartPunctuationData;
use LaravelLang\Config\Enums\Name;

class Config
{
public static function shared(): SharedData
{
return new SharedData(
inline: static::value(Name::Shared, 'inline'),
align: static::value(Name::Shared, 'align'),
aliases: static::value(Name::Shared, 'aliases'),
smartPunctuation: static::smartPunctuation()
);
}

public static function hidden(): HiddenData
{
return new HiddenData(
plugins: static::value(Name::Hidden, 'plugins', PushableData::class),
packages: static::value(Name::Hidden, 'packages', PushableData::class),
map: static::value(Name::Hidden, 'map'),
);
}

protected static function smartPunctuation(): SmartPunctuationData
{
return new SmartPunctuationData(
enabled: static::value(Name::Shared, 'enable'),
common: static::value(Name::Shared, 'common'),
locales: static::value(Name::Shared, 'locales'),
);
}

protected static function value(Name $name, string $key, ?string $object = null): mixed
{
$value = static::repository($name->value . '.' . $key);

return is_null($object) ? $value : new $object($value);
}

protected static function repository(string $key): mixed
{
return app(Repository::class)->get($key);
}
}

0 comments on commit 07267de

Please sign in to comment.