Skip to content
This repository has been archived by the owner on Sep 28, 2019. It is now read-only.
/ config-yaml Public archive

This package is abandoned and no longer maintained. Use pragmarx/yaml package instead.

License

Notifications You must be signed in to change notification settings

jameswmcnab/config-yaml

Repository files navigation

Abandoned

This package is abandoned and no longer maintained. The author suggests using the pragmarx/yaml package instead.

YAML Config Loader for Laravel

Build Status

This provides simple YAML config loading to Laravel. It takes a lot of inspiration from the illuminate/config package and uses the Symfony YAML parser.

This is not a replacement for the built-in PHP config file system in Laravel but is intended as an extra 'layer' of configuration. This allows you to have one or more Ruby-like config.yaml files containing user-configurable config for your application.

By default the package assumes your YAML files are in the base_path() directory, but you can customise this by publishing the package config file (config-yaml.php) to your application and changing the yaml_path key.

Installation

Installation is via Composer:

$ composer require jameswmcnab/config-yaml

Publish package config (optional)

If you want to customise the package config, publish the package config then edit the newly created config/config-yaml.php file:

$ php artisan vendor:publish --provider=ConfigYamlServiceProvider

Usage

Example YAML file:

# Example YAML config.yaml file
app:
  name: "Great App"
  version: 1.0.2

log:
  dir: /var/log/vendor/app
  level: debug

database:
  adapter: mysql
  database: app_live
  username: user
  password: password

Using the facade

Note: Remember to register the facade in your app.php config.

ConfigYaml::get('config.database.adapter'); // mysql

Using dependency injection

If you don't want to use the facade just directly inject Jameswmcnab\ConfigYaml\RepositoryInterface wherever dependency injection is supported and use it directly:

<?php

namespace App\Foo;

use Jameswmcnab\ConfigYaml\RepositoryInterface;

class FooBar
{
    /**
     * @var RepositoryInterface
     */
    private $yamlConfig;

    /**
     * FooBar constructor.
     *
     * @param RepositoryInterface $yamlConfig
     */
    public function __construct(RepositoryInterface $yamlConfig)
    {
        $this->yamlConfig = $yamlConfig;
    }

    /**
     * @return array|string
     */
    private function getDatabaseAdapter()
    {
        return $this->yamlConfig->get('config.database.adapter');  // mysql
    }
}

Running Tests

To run the package tests:

$ vendor/bin/phpspec run
$ vendor/bin/phpunit

About

This package is abandoned and no longer maintained. Use pragmarx/yaml package instead.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages