2017 © Pedro Pelรกez
 

library yaml

Load your Laravel config files using yaml

image

pragmarx/yaml

Load your Laravel config files using yaml

  • Saturday, February 10, 2018
  • by AntonioCarlosRibeiro
  • Repository
  • 3 Watchers
  • 27 Stars
  • 22,773 Installations
  • PHP
  • 4 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 8 Versions
  • 49 % Grown

The README.md

YAML

A Laravel YAML parser and config loader

, (*1)

Latest Stable Version License Code Quality Build , (*2)

Coverage StyleCI SensioLabsInsight , (*3)

Rationale

Config files getting bigger, harder to maintain and look at, every day. Why not just use YAML to load them?, (*4)

Which one is cleaner?

, (*5)

Key features

Load one file to Laravel config

``` php Yaml::loadToConfig(config_path('myapp.yml'), 'my-app-conf');, (*6)


## Or a whole directory, recursively, so all those files would be loaded with a single command ``` php Yaml::loadToConfig(config_path('myapp'), 'my-app-conf');

To load a directory with all your config files:, (*7)

``` text . โ””โ”€โ”€ myapp โ”œโ”€โ”€ multiple โ”‚ โ”œโ”€โ”€ alter.yml โ”‚ โ”œโ”€โ”€ app.yml โ”‚ โ””โ”€โ”€ second-level โ”‚ โ””โ”€โ”€ third-level โ”‚ โ”œโ”€โ”€ alter.yml โ”‚ โ””โ”€โ”€ app.yml โ”œโ”€โ”€ single โ””โ”€โ”€ single-app.yml, (*8)


Then you would just have to use it like you usually do in Laravel ``` php config('my-app-conf.multiple.second-level.third-level.alter.person.name')

Execute functions, like in the usual Laravel PHP array config.

``` php repository: "{{ env('APP_NAME') }}" path: "{{ storage_path('app') }}", (*9)


### Config values can reference config keys, you just have to quote it this way: ``` yaml {{'format.version'}}

You can add comments to your YAML files, something JSON wouldn't let you do

``` yaml build: mode: git-local #### other modes: git-remote or number, (*10)


## Parser and dumper methods In case you need to deal with YAML directly, you can use these public methods: ``` php Yaml::parse($input, $flags) // Parses YAML into a PHP value. Yaml::parseFile($filename, $flags) // Parses a YAML file into a PHP value. Yaml::dump($input, $inline, $indent, $flags) // Dumps a PHP value to a YAML string.

Which are simple bridges to Symfony's YAML., (*11)

Install

Via Composer, (*12)

``` bash $ composer require pragmarx/yaml, (*13)


## Using Publish your package as you would usually do: ``` php $this->publishes([ __DIR__.'/../config/version.yml' => $this->getConfigFile(), ]);

Load the configuration in your boot() method:, (*14)

``` php $this->app ->make('pragmarx.yaml') ->loadToConfig($this->getConfigFile(), 'my-package');, (*15)


Or use the Facade: ``` php Yaml::loadToConfig(config_path('myapp.yml'), 'my-package');

And it's merged to your Laravel config:, (*16)

``` php config('my-package.name');, (*17)


## Utilize PECL YAML To utilize the PECL YAML, you should [install the PECL YAML extension](https://www.php.net/manual/en/yaml.installation.php) and register the binding in the `register()` method of your service provider: ```php $this->app->bind(\PragmaRX\Yaml\Package\Support\Parser::class, \PragmaRX\Yaml\Package\Support\PeclParser::class);

Example

This is a YAML file from another package using this package:, (*18)

yaml current: major: 1 minor: 0 patch: 0 format: "{$major}.{$minor}.{$patch}" cache: enabled: true key: pragmarx-version build: mode: git-local # git-remote or number number: 701031 git-local: "git rev-parse --verify HEAD" git-remote: "git ls-remote {$repository} refs/heads/master" repository: "{{ env('APP_GIT_REPOSITORY') }}" length: 6 format: version: "{$major}.{$minor}.{$patch} (build {$build})" full: "version {{'format.version'}}" compact: "v{$major}.{$minor}.{$patch}-{$build}" ## add as many formats as you need, (*19)

Minimum requirements

  • Laravel 5.5
  • PHP 7.0

Author

Antonio Carlos Ribeiro, (*20)

License

This package is licensed under the MIT License - see the LICENSE file for details, (*21)

Contributing

Pull requests and issues are welcome., (*22)

The Versions

10/02 2018

dev-master

9999999-dev

Load your Laravel config files using yaml

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel config yaml

10/02 2018

v0.1.6

0.1.6.0

Load your Laravel config files using yaml

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel config yaml

19/12 2017

v0.1.5

0.1.5.0

Load your Laravel config files using yaml

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel config yaml

05/12 2017

v0.1.4

0.1.4.0

Load your Laravel config files using yaml

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel config yaml

02/12 2017

v0.1.3

0.1.3.0

Load your Laravel config files using yaml

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel config yaml

01/12 2017

v0.1.2

0.1.2.0

Load your Laravel config files using yaml

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel config yaml

30/11 2017

v0.1.1

0.1.1.0

Load your Laravel config files using yaml

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel config yaml

30/11 2017

v0.1.0

0.1.0.0

Load your Laravel config files using yaml

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel config yaml