theofidry/laravel-yaml

This package is abandoned and no longer maintained. No replacement package was suggested.

Laravel ServiceProvider for using YAML configuration files

v1.0.0-beta.2 2016-03-14 12:28 UTC

This package is auto-updated.

Last update: 2022-02-01 12:56:11 UTC


README

Package version Build Status SensioLabsInsight Dependency Status Scrutinizer Code Quality Code Coverage License

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

  1. Disclaimer: why using this library?
  2. Install
  3. Everything about parameters
  4. YAML vs PHP
  5. Refering to another value
  6. Refering to an environment value
  7. Refering to constants
  8. Overriding values
  9. Environment dependent parameters
  10. Service declaration
  11. Simple services
  12. Factories
  13. Decorating services
  14. Custom file organisation
  15. Import other files
  16. 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.

See more.

Credits

This bundle is developed by Théo FIDRY.