jameswmcnab / config-yaml
A simple YAML config file loader for Laravel, taking inspiration from illuminate/config.
Installs: 4 298
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 3
Open Issues: 1
Requires
- php: >=7.0
- illuminate/contracts: 5.5.*|5.6.*
- illuminate/filesystem: 5.5.*|5.6.*
- illuminate/support: 5.5.*|5.6.*
- symfony/yaml: ^3.0|^4.0
Requires (Dev)
- orchestra/testbench: 3.5.*|3.6.*
- phpspec/phpspec: ^3.0|^4.0
Suggests
- illuminate/cache: Allows caching of your YAML config values via the CachingRepository.
This package is auto-updated.
Last update: 2019-09-28 13:26:38 UTC
README
This package is abandoned and no longer maintained. The author suggests using the pragmarx/yaml package instead.
YAML Config Loader for Laravel
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