guemidiborhane/yaml-config

此包的最新版本(1.1)没有提供许可证信息。

CakePHP 3 的 Yaml 配置支持

安装: 313

依赖项: 2

建议者: 0

安全: 0

星标: 11

关注者: 4

分支: 4

开放问题: 0

类型:cakephp-plugin

1.1 2015-07-30 22:33 UTC

This package is auto-updated.

Last update: 2024-09-19 22:54:57 UTC


README

使用 Symfony Yaml 组件实现大部分 YAML 1.2 规范,以便将配置文件解析到 CakePHP 3

需求

3.0 分支有以下需求

  • CakePHP 3.0.0 或更高版本。

安装

  • 从 CakePHP 项目的根目录(位于 composer.json 文件所在位置)使用 composer 安装插件
php composer.phar require chobo1210/yaml "dev-master"

或者将以下行添加到你的 composer.json

"require": {
  "chobo1210/Yaml": "dev-master"
}

然后运行 php composer.phar update

然后将以下行添加到你的 config/bootstrap.php

use Yaml\Configure\Engine\YamlConfig;

try {
  Configure::config('yaml', new YamlConfig());
  Configure::load('your_file', 'yaml');
} catch (\Exception $e) {
  die('Unable to load config/your_file.yml.');
}

你的文件必须在 config/ 目录下,替换 your_file 为你的 YAML 文件名(不包括扩展名)

用法

如果你想要使用插件 Shell 转换当前配置,请将以下行添加到 config/bootstrap.php

Plugin::load('Yaml');

然后在你的控制台或终端中输入

bin/cake convert

可选地,你可以设置你的 YAML 文件名(不包括扩展名),默认为:app.yml

bin/cake convert your_file_name

文件将创建在 config/ 目录下。

示例

debug: true

Asset:
  timestamp: true

# Default Database Connection informations
default_configuration: &default_configuration
  className: Cake\Database\Connection
  driver: Cake\Database\Driver\Mysql
  persistent: false
  host: localhost
  login: root
  password: secret
  prefix: false
  encoding: utf8
  timezone: +01:00
  cacheMetadata: true
  quoteIdentifiers: false  



# Datasources
Datasources:
  # Default datasource
  default: 
    <<: *default_configuration
    database: my_database
  # PHPUnit tests datasource
  test:
    <<: *default_configuration
    database: my_database_test



# Email Configuration
EmailTransport:
  default:
      className: Mail
      host: localhost
      port: 1025
      timeout: 30
      # username: user
      # password: secret
      client: null
      tls: null
Email:
  default:
      transport: default
      from: contact@localhost.dz
      cherset: utf-8
      headerCharset: utf-8