theofidry / laravel-yaml
Laravel ServiceProvider for using YAML configuration files
Installs: 5 595
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 2
Forks: 3
Open Issues: 1
Requires
- php: >=5.5.9
- laravel/framework: ^5.1
- symfony/config: ^2.7|^3.0
- symfony/expression-language: ^2.7|^3.0
- symfony/yaml: ^2.7|^3.0
Requires (Dev)
- mikey179/vfsstream: ^1.6
- phpunit/phpunit: ^5.2
This package is auto-updated.
Last update: 2022-02-01 12:56:11 UTC
README
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.