• Stars
    star
    110
  • Rank 316,770 (Top 7 %)
  • Language
    PHP
  • License
    MIT License
  • Created about 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Laravel YAML parser and config loader

YAML

A Laravel YAML parser and config loader

Latest Stable Version License Code Quality Build

Coverage StyleCI SensioLabsInsight

Rationale

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

Which one is cleaner?

Key features

Load one file to Laravel config

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

Or a whole directory, recursively, so all those files would be loaded with a single command

Yaml::loadToConfig(config_path('myapp'), 'my-app-conf');

To load a directory with all your config files:

.
└── myapp
    β”œβ”€β”€ multiple
    β”‚   β”œβ”€β”€ alter.yml
    β”‚   β”œβ”€β”€ app.yml
    β”‚   └── second-level
    β”‚       └── third-level
    β”‚           β”œβ”€β”€ alter.yml
    β”‚           └── app.yml
    β”œβ”€β”€ single
        └── single-app.yml

Then you would just have to use it like you usually do in Laravel

config('my-app-conf.multiple.second-level.third-level.alter.person.name')

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

repository: "{{ env('APP_NAME') }}"
path: "{{ storage_path('app') }}"

Config values can reference config keys, you just have to quote it this way:

{{'format.version'}}

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

build:
  mode: git-local  #### other modes: git-remote or number

Parser and dumper methods

In case you need to deal with YAML directly, you can use these public methods:

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.

Install

Via Composer

$ composer require pragmarx/yaml

Using

Publish your package as you would usually do:

$this->publishes([
    __DIR__.'/../config/version.yml' => $this->getConfigFile(),
]);

Load the configuration in your boot() method:

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

Or use the Facade:

Yaml::loadToConfig(config_path('myapp.yml'), 'my-package');

And it's merged to your Laravel config:

config('my-package.name');

Utilize PECL YAML

To utilize the PECL YAML, you should install the PECL YAML extension and register the binding in the register() method of your service provider:

$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:

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

Minimum requirements

  • Laravel 5.5
  • PHP 7.0

Author

Antonio Carlos Ribeiro

License

This package is licensed under the MIT License - see the LICENSE file for details

Contributing

Pull requests and issues are welcome.

More Repositories

1

tracker

Laravel Stats Tracker
PHP
2,824
star
2

health

Laravel Health Panel
PHP
1,879
star
3

countries

Laravel countries and currencies
PHP
1,741
star
4

google2fa

A One Time Password Authentication package, compatible with Google Authenticator.
PHP
1,684
star
5

firewall

Firewall package for Laravel applications
PHP
1,362
star
6

google2fa-laravel

A One Time Password Authentication package, compatible with Google Authenticator for Laravel
PHP
825
star
7

tddd

A Laravel Continuous Integration Package
Vue
727
star
8

version

Laravel App versioning
PHP
565
star
9

laravelcs

Laravel PHP_CodeSniffer
PHP
236
star
10

deeployer

Deploy your Laravel applications via Github or Bitbucket Hooks
PHP
146
star
11

countries-laravel

Countries for Laravel
PHP
141
star
12

zipcode

Zip code searcher
PHP
97
star
13

steroids

Laravel 4 Blade on Steroids
PHP
95
star
14

coollection

Laravel Collection Objectified
PHP
87
star
15

google2fa-qrcode

QRCode for Google2FA
PHP
84
star
16

recovery

Create recovery/backup codes for 2FA
PHP
72
star
17

random

Generate random strings or numeric values
PHP
70
star
18

glottos

A PHP 5.3+ Translation/Localization System
PHP
69
star
19

sqli

A Laravel Artisan SQL Interactive Interface
PHP
60
star
20

support

Support Classes
PHP
58
star
21

ia-arr

Laravel Illuminate Agnostic Arr
PHP
49
star
22

ia-str

Laravel Illuminate Agnostic Str
PHP
46
star
23

ia-collection

Laravel Illuminate Agnostic Collection
PHP
43
star
24

artisan-anywhere

Execute Artisan from anywhere in your Laravel project tree
43
star
25

dev-box

Development Box Provisioning in Ansible
Shell
41
star
26

artisan-tool

Nova Artisan Tool
PHP
35
star
27

glottosAdmin

Glottos Admin Panel and Starter
JavaScript
27
star
28

laravel-installer

Laravel Framework Installer Script for Unlix-Like Systems
Shell
26
star
29

google2fa-starter

Google2FA Starter App
PHP
26
star
30

tddd-starter

Laravel TDDD Starter App
PHP
23
star
31

nova-boolean-datetime-field

A Laravel Nova Boolean DateTime field
PHP
20
star
32

skel

A PHP Package Creator & Skeleton
Shell
12
star
33

health-docker

App Health Panel for Docker Environments
PHP
8
star
34

google2fa-php

A One Time Password Authentication PHP class, compatible with Google Authenticator
PHP
6
star
35

lumen-image-processor

Lumen Image Processor
PHP
5
star
36

http-basic-auth

HTTP Basic Auth middleware for Laravel
Shell
3
star
37

trivia

Trivia database
PHP
3
star
38

vanhack-agentbot

Vanhack Agent Bot
PHP
3
star
39

pragmarx.com

Source of pragmarx.com
PHP
3
star
40

zsh

zsh
Shell
3
star
41

backup-server

backup-server
PHP
3
star
42

googleforms

Post to Google Form Spreadsheets
PHP
2
star
43

sdk

sdk
PHP
1
star
44

fluxbb-style

The FluxBB style for the Laravel forums.
1
star
45

core-libraries

core libraries
PHP
1
star
46

veveystore

Vevey Store
HTML
1
star
47

a17ex

Area 17 Exercice
PHP
1
star
48

church.api

Church API
PHP
1
star