theofidry / Laravelyaml
Labels
Projects that are alternatives of or similar to Laravelyaml
Laravel Yaml ServiceProvider
A simple Laravel library to declare your parmeters and services in Yaml like in Symfony:
# resources/providers/services.yml
services:
dummy_service:
class: App\Services\DummyService
alias: dummy
arguments:
- %app.url%
- %app.env%
instead of:
# app/Providers/AppServiceProvider.php
//...
public function register()
{
$this->app->singleton(
'dummy_service',
function ($app) {
$url = env('APP_URL');
$env = env('APP_ENV');
return new \App\Services\DummyService($url, $env);
}
);
}
Documentation
- Disclaimer: why using this library?
- Install
- Everything about parameters
- YAML vs PHP
- Refering to another value
- Refering to an environment value
- Refering to constants
- Overriding values
- Environment dependent parameters
- Service declaration
- Simple services
- Factories
- Decorating services
- Custom file organisation
- Import other files
- Use your own provider
Install
You can use Composer to install the bundle to your project:
composer require theofidry/laravel-yaml
Then, add the provider Fidry\LaravelYaml\Provider\DefaultExtensionProvider
to your application providers:
<?php
// config/app.php
'providers' => [
// ...
\Fidry\LaravelYaml\Provider\DefaultExtensionProvider::class,
];
Usage
See how to declare and use parameters and services!
By convention, you should have the following structure:
resources/
providers/
parameters.yml
parameters_testing.yml
services.yml
The parameters.yml
should contain all of your application parameters values:
# resources/providers/parameters.yml
parameters:
my_parameter: parameter_value
Depending of your environment, a second parameters file will be loaded. For
example, if your application environment (by default defined by the environment
variable APP_ENV
in your .env
file) is 'testing'
or 'production'
, the
library will try to load the parameters_testing.yml
or parameters_production.yml
file.
Then services.yml
should contain all your service definitions.
Credits
This bundle is developed by Théo FIDRY.