-
-
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.
- Loading branch information
1 parent
cfd568b
commit 4fdc5f4
Showing
15 changed files
with
285 additions
and
37 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
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,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" | ||
bootstrap="vendor/autoload.php" | ||
colors="true" | ||
> | ||
<testsuites> | ||
<testsuite name="Unit"> | ||
<directory>./tests</directory> | ||
</testsuite> | ||
</testsuites> | ||
<source> | ||
<include> | ||
<directory>./src</directory> | ||
</include> | ||
</source> | ||
</phpunit> |
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaravelLang\Config\Concerns; | ||
|
||
use BackedEnum; | ||
|
||
trait HasKey | ||
{ | ||
protected function resolveKey(int | string | BackedEnum $key): int | string | ||
{ | ||
if ($key instanceof BackedEnum) { | ||
return $key->value ?? $key->name; | ||
} | ||
|
||
return $key; | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaravelLang\Config\Concerns; | ||
|
||
use BackedEnum; | ||
|
||
trait HasValues | ||
{ | ||
use HasKey; | ||
|
||
public function get(int | string | BackedEnum $key): mixed | ||
{ | ||
if (!is_null($this->default)) { | ||
$default = $this->default . '.' . $this->resolveKey($key); | ||
} | ||
|
||
return $this->value($this->key . '.' . $this->resolveKey($key), $default ?? null); | ||
} | ||
|
||
protected function value(string $key, ?string $default = null): mixed | ||
{ | ||
return $default | ||
? config()->get($key, config()->get($default)) | ||
: config()->get($key); | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace LaravelLang\Config\Data; | ||
|
||
use LaravelLang\Config\Concerns\HasValues; | ||
|
||
class NonPushableData | ||
{ | ||
use HasValues; | ||
|
||
public function __construct( | ||
protected readonly string $key, | ||
protected readonly ?string $default = null | ||
) { | ||
} | ||
|
||
public function all(): array | ||
{ | ||
return config($this->key, config($this->default, [])); | ||
} | ||
} |
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
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
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,3 @@ | ||
<?php | ||
|
||
declare(strict_types=1); |
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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests; | ||
|
||
use Orchestra\Testbench\TestCase as BaseTestCase; | ||
|
||
abstract class TestCase extends BaseTestCase | ||
{ | ||
} |
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,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use LaravelLang\Config\Facades\Config; | ||
|
||
beforeAll(function () { | ||
putenv('LOCALIZATION_INLINE=true'); | ||
putenv('LOCALIZATION_ALIGN=true'); | ||
putenv('LOCALIZATION_SMART_ENABLED=true'); | ||
}); | ||
|
||
test('plugins', function () { | ||
config(['localization-private.plugins' => ['foo', 'bar']]); | ||
|
||
expect(Config::hidden()->plugins->all()) | ||
->toBeArray() | ||
->toBe(['foo', 'bar']) | ||
->toBe(config('localization-private.plugins')); | ||
|
||
Config::hidden()->plugins->push('baz'); | ||
|
||
expect(Config::hidden()->plugins->all()) | ||
->toBeArray() | ||
->toBe(['foo', 'bar', 'baz']) | ||
->toBe(config('localization-private.plugins')); | ||
}); | ||
|
||
test('packages', function () { | ||
config(['localization-private.packages' => ['foo', 'bar']]); | ||
|
||
expect(Config::hidden()->packages->all()) | ||
->toBeArray() | ||
->toBe(['foo', 'bar']) | ||
->toBe(config('localization-private.packages')); | ||
|
||
Config::hidden()->packages->push('baz'); | ||
|
||
expect(Config::hidden()->packages->all()) | ||
->toBeArray() | ||
->toBe(['foo', 'bar', 'baz']) | ||
->toBe(config('localization-private.packages')); | ||
}); | ||
|
||
test('map', function () { | ||
expect(Config::hidden()->map->all()) | ||
->toBeArray() | ||
->toBe(config('localization-private.map')); | ||
}); |
Oops, something went wrong.