Skip to content

Commit 2402c0d

Browse files
authored
Merge pull request #91 from phenixphp/feature/add-config-global-helper
Add config global helper
2 parents 4921cef + be7487a commit 2402c0d

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

.gitattributes

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
* text=auto eol=lf
2+
3+
*.css diff=css
4+
*.html diff=html
5+
*.md diff=markdown
6+
*.php diff=php
7+
8+
/.github export-ignore
9+
/tests export-ignore
10+
CHANGELOG.md export-ignore
11+
phpstan.neon export-ignore
12+
phpstan-baseline.neon export-ignore
13+
phpunit.xml.dist export-ignore
14+
rector.php export-ignore
15+
sonar-project.properties export-ignore

src/functions.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare(strict_types=1);
44

55
use Phenix\App;
6+
use Phenix\Facades\Config;
67
use Phenix\Facades\Log;
78
use Phenix\Facades\Translator;
89
use Phenix\Http\Response;
@@ -40,6 +41,13 @@ function env(string $key, Closure|null $default = null): array|string|float|int|
4041
}
4142
}
4243

44+
if (! function_exists('config')) {
45+
function config(string $key, mixed $default = null): mixed
46+
{
47+
return Config::get($key, $default);
48+
}
49+
}
50+
4351
if (! function_exists('value')) {
4452
function value($value, ...$args)
4553
{

tests/Unit/Runtime/ConfigTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@
1818

1919
expect($config->get('app.name'))->toBe('PHPhenix');
2020
});
21+
22+
it('retrieve configurations from global config helper function', function (): void {
23+
config('app.name', 'DefaultApp');
24+
25+
expect(config('app.name'))->toBe('Phenix');
26+
});

0 commit comments

Comments
 (0)