Skip to content

Commit 5c56603

Browse files
committed
Merge branch 'jfoliveira-feature/lumen_service_provider'
2 parents 5d511de + c5f3703 commit 5c56603

File tree

3 files changed

+58
-3
lines changed

3 files changed

+58
-3
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ Laravel Env Validator is available via Composer:
2525
}
2626
```
2727

28+
## Setup
29+
30+
### Laravel
31+
32+
#### Register Service Provider
33+
2834
```php
2935
// config/app.php
3036

@@ -35,11 +41,39 @@ Laravel Env Validator is available via Composer:
3541
],
3642
```
3743

44+
#### Publish configuration file
45+
3846
```
3947
php artisan vendor:publish --provider="MathiasGrimm\LaravelEnvValidator\ServiceProvider" --tag="config"
4048
```
4149

42-
## Example
50+
### Lumen
51+
52+
Manually copy the configuration file
53+
```
54+
vendor/mathiasgrimm/laravel-env-validator/src/config/laravel-env-validator.php
55+
```
56+
57+
to
58+
59+
```
60+
config/laravel-env-validator.php
61+
```
62+
63+
Register Service Provider in `bootstrap/app.php`:
64+
65+
```php
66+
...
67+
$app->register(MathiasGrimm\LaravelEnvValidator\LumenServiceProvider::class);
68+
...
69+
```
70+
71+
Load configuration file in `bootstrap/app.php`:
72+
```php
73+
$app->configure('laravel-env-validator');
74+
```
75+
76+
## Example configuration file
4377
```php
4478
<?php
4579
// config/laravel-env-validator.php

src/EnvValidatorFactory.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ public static function buildFromValidator(Validator $validator)
1515

1616
public static function buildFromLaravelConfig()
1717
{
18-
$config = \Config::get('laravel-env-validator');
19-
18+
$config = config('laravel-env-validator');
2019
// there is a bug that would not load APP_ENV into $_SERVER or $_ENV
2120
// therefore I had to read based on what was defined in the config file
2221
$env = [];

src/LumenServiceProvider.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php namespace MathiasGrimm\LaravelEnvValidator;
2+
3+
use Illuminate\Support\ServiceProvider as Provider;
4+
5+
class LumenServiceProvider extends Provider
6+
{
7+
public function boot()
8+
{
9+
$validator = EnvValidatorFactory::buildFromLaravelConfig();
10+
$validator->validate();
11+
}
12+
13+
/**
14+
* Register any application services.
15+
*
16+
* @return void
17+
*/
18+
public function register()
19+
{
20+
$this->mergeConfigFrom(__DIR__ . '/config/laravel-env-validator.php', 'laravel-env-validator');
21+
}
22+
}

0 commit comments

Comments
 (0)