symfony - Parsing YAML to check structure -


in symfony2 project want make configuration file gets loaded , gives indication, each form field, if display field or not, , if making required or not, depending on attributes of "project" entity.

parameters:     fieldproperty:         myprofile:             name:                 label: 'your name'                             projecttype:                     it: 2                     non-it: 2                     hybrid: 2                 projectsize:                     small: 2                     medium: 2                     large: 2                     massive: 2                 projectcomplexity:                     low: 2                     medium:  2                     high: 2                 projecttimingurgency:                     regular: 2                     urgent: 2                     mandatory: 2                     critical: 2                     highlycritical: 2                 sensitivity: 'none'             nickname:                 label: 'your nickname'                             projecttype:                     it: 0                     non-it: 0                     hybrid: 0                 projectsize:                     small: 0                     medium: 0                     large: 0                     massive: 0                 projectcomplexity:                     low: 0                     medium:  0                     high: 1                 projecttimingurgency:                     regular: 0                     urgent: 0                     mandatory: 0                     critical: 0                     highlycritical: 1                 sensitivity: 'none' 

i use determine form label of given field. considering have 2000 fields i'm thinking elegant make attr section of $builder->add of formbuilder dynamic, instance if it's of type "textarea" expect in attr section parameter rows defines number of rows. means need define proper structure of yaml document: if field exists , of type "whatever" expect field b (and maybe possibility of specifying if there no field b default "4") , on.

i need structured parser. consider first "child" of fieldproperty attribute entity name, parser doesn't have expect word there, string. same story following child field name (in example below entity "myprofile" , 2 fields "name" , "nickname"). moment on structure enters play.

is doable in yaml or have switch xml, bit less human friendly?

you need specify structure in way , kwalify or other schema validator can that.

there can in yaml if familiar programming. interesting yaml file consists of basic scalars, mapping , sequences only, description seem indicate mappings more objects have (or should have) properties.

using standard yaml tags can indicate kind of objects nodes represents, check values or existence of values require have objects in program (i have done python , ruamel.yaml package¹, other languages , parsers should work well).

in addition need add tags hand. if can automate tag assignment, reading in mapping/sequence tree , replacing nodes using algorithm don't need tag, can run assignments , have objects check rules specify classes. adding tags in source might confuse symfony2, in case have pre-process (hand) tagged yaml before can use (often safe-load , dump enough that).

there larger choice of tools xml. need 1 tool, or 1 method 1 indicated above, works you. wouldn't give on readability of yaml yet if you.


¹ although yaml round-trip package ruamel.yaml open source (it enhanced version of pyyaml), code verify yaml using objects unfortunately not.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -