Code Monkey home page Code Monkey logo

laravelyaml's Introduction

Laravel Yaml ServiceProvider

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.

laravelyaml's People

Contributors

theofidry avatar

Stargazers

Ribamar FS avatar Chun-Sheng, Li avatar Oleksii Ilienko avatar Nipe avatar  avatar Stefan Bauer avatar Ivan Popov avatar Sam Brown avatar  avatar

Watchers

James Cloos avatar Oleksii Ilienko avatar  avatar  avatar

laravelyaml's Issues

Not Compatible with Laravel 5.5

Nice library, but i had trying to implement in laravel 5.5, and not compatible.
I Will try to fixit, and can i make a PR?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.