pragmarx/yaml
Composer 安装命令:
composer require pragmarx/yaml
包简介
Load your Laravel config files using yaml
README 文档
README
A Laravel YAML parser and config loader
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
License
This package is licensed under the MIT License - see the LICENSE file for details
Contributing
Pull requests and issues are welcome.
pragmarx/yaml 适用场景与选型建议
pragmarx/yaml 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.83M 次下载、GitHub Stars 达 115, 最近一次更新时间为 2017 年 11 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「yaml」 「config」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pragmarx/yaml 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pragmarx/yaml 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pragmarx/yaml 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Zend Framework module to quickly and easily set PHP settings.
SUML for PHP
SUML support for Symfony
Server environment detection based on config array-file
provides an facade for php-yaml, syck and symphony/yaml so switching in between is easier
Especificação do formato Cnab240 e Cnab400 traduzida para Yaml
统计信息
- 总下载量: 2.83M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 116
- 点击次数: 21
- 依赖项目数: 31
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-11-30
