Skip to content

Commit

Permalink
Merge branch 'jfoliveira-feature/lumen_service_provider'
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiasgrimm committed Mar 8, 2016
2 parents 5d511de + c5f3703 commit 5c56603
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ Laravel Env Validator is available via Composer:
}
```

## Setup

### Laravel

#### Register Service Provider

```php
// config/app.php

Expand All @@ -35,11 +41,39 @@ Laravel Env Validator is available via Composer:
],
```

#### Publish configuration file

```
php artisan vendor:publish --provider="MathiasGrimm\LaravelEnvValidator\ServiceProvider" --tag="config"
```

## Example
### Lumen

Manually copy the configuration file
```
vendor/mathiasgrimm/laravel-env-validator/src/config/laravel-env-validator.php
```

to

```
config/laravel-env-validator.php
```

Register Service Provider in `bootstrap/app.php`:

```php
...
$app->register(MathiasGrimm\LaravelEnvValidator\LumenServiceProvider::class);
...
```

Load configuration file in `bootstrap/app.php`:
```php
$app->configure('laravel-env-validator');
```

## Example configuration file
```php
<?php
// config/laravel-env-validator.php
Expand Down
3 changes: 1 addition & 2 deletions src/EnvValidatorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ public static function buildFromValidator(Validator $validator)

public static function buildFromLaravelConfig()
{
$config = \Config::get('laravel-env-validator');

$config = config('laravel-env-validator');
// there is a bug that would not load APP_ENV into $_SERVER or $_ENV
// therefore I had to read based on what was defined in the config file
$env = [];
Expand Down
22 changes: 22 additions & 0 deletions src/LumenServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php namespace MathiasGrimm\LaravelEnvValidator;

use Illuminate\Support\ServiceProvider as Provider;

class LumenServiceProvider extends Provider
{
public function boot()
{
$validator = EnvValidatorFactory::buildFromLaravelConfig();
$validator->validate();
}

/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(__DIR__ . '/config/laravel-env-validator.php', 'laravel-env-validator');
}
}

0 comments on commit 5c56603

Please sign in to comment.