Symfony 筆記 (2): YAML

Symfony 的設定檔都是用 YAML 格式來搞定的,當然要用 ini 或者 xml 也是可以,不過 YAML 算是很簡單好用的選擇。選擇使用 YAML 的好處就跟選擇用 Python 寫程式差不多,好讀好編輯然後記得要用 space 不要用 tab。

# Never use tabs
all:
-> mail:
-> -> webmaster:  webmaster@example.com

# Use blanks instead
all:
  mail:
    webmaster: webmaster@example.com
# All valid formats
error1: This field is compulsory
error2: '  This field is compulsory  '
error3: 'Don''t leave this field blank'   # Single quotes must be doubled
# Multiline
# Folded style, introduced by >
# Each line break is folded to a space
# Makes YAML more readable
accomplishment: >
  Mark set a major league
  home run record in 1998.

# Literal style, introduced by |
# All line breaks count
# Indentation doesn't appear in the resulting string
stats: |
  65 Home Runs
  0.278 Batting Average
# Shorthand syntax for arrays
players: [ Mark McGwire, Sammy Sosa, Ken Griffey ]

# Expanded syntax for arrays
players:
  - Mark McGwire
  - Sammy Sosa
  - Ken Griffey
# Incorrect syntax, blanks are missing after the colon
mail: {webmaster:webmaster@example.com,contact:contact@example.com}

# Correct shorthand syntax for associative arrays
mail: { webmaster: webmaster@example.com, contact: contact@example.com }

# Expanded syntax for associative arrays
mail:
  webmaster: webmaster@example.com
  contact:   contact@example.com
# Boolean Values
true_values:   [ on, 1, true ]
false_values:  [ off, 0, false ]
# Header
all:
  .general: # Key starts with . is ignored, 完全是方便閱讀而存在
    tax:        19.6

Tags: , , , ,

Leave a Reply

All Rights Reserved Copyright © 2008 Design by StyleShout and Clazh