-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The configurator interface has been prepared
- Loading branch information
1 parent
9e6816f
commit 07267de
Showing
6 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |