•  


GitHub - antonioribeiro/yaml: A Laravel YAML parser and config loader
Skip to content

antonioribeiro/yaml

Repository files navigation

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.

- "漢字路" 한글한자자동변환 서비스는 교육부 고전문헌국역지원사업의 지원으로 구축되었습니다.
- "漢字路" 한글한자자동변환 서비스는 전통문화연구회 "울산대학교한국어처리연구실 옥철영(IT융합전공)교수팀"에서 개발한 한글한자자동변환기를 바탕하여 지속적으로 공동 연구 개발하고 있는 서비스입니다.
- 현재 고유명사(인명, 지명등)을 비롯한 여러 변환오류가 있으며 이를 해결하고자 많은 연구 개발을 진행하고자 하고 있습니다. 이를 인지하시고 다른 곳에서 인용시 한자 변환 결과를 한번 더 검토하시고 사용해 주시기 바랍니다.
- 변환오류 및 건의,문의사항은 juntong@juntong.or.kr로 메일로 보내주시면 감사하겠습니다. .
Copyright ⓒ 2020 By '전통문화연구회(傳統文化硏究會)' All Rights reserved.
 한국   대만   중국   일본