PHP, Zend Framework and Other Crazy Stuff
YAML for the Zend Framework – well, maybe…
It’s funny sometimes how you end up being involved in an open source contribution
.
A few days ago I was on the PHP Developer’s Network forums – not so surprising since I like being involved there and the problems you run across can get you thinking about new ideas and learning new things. I was responding to a theory post about adding a filter/validation chain to the Zend Framework and suggested the end result should be configurable – i.e. if I have a configuration file, a Factory class should be able to easily generate a filter chain without manual tinkering (something I absolutely hate doing is manually setting up filters and validation since it’s a pain in the ass to modify by hand later). In any case being configurable would be a good pointer to the simplicity (KISS) of use in setting up a chain if nothing else.
Since I’m used to the format from Ruby and Perl and since it’s used for a similar purpose in the PHP Symfony framework, I also suggested using YAML configuration files since they are far more readable than XML and remain machine readable. I believe this went over quite well. Later on I realised the Zend Framework has no YAML support, and after some searching noticed the only (apparent) PHP parser was the Spyc library. Now kudos to the Spyc developers because it works – but it’s not a full grammer parser (that I could tell) so I’m not sure exactly how compliant with the full YAML 1.1 specification it is. I haven’t tested it so I’m not judging.
So I fired off a few emails to the fw-general mailing list of the Zend Framework to see if there was any interest. I’d like to thank Matthew and Gavin for their feedback and I’ve since decided to have a go at implementing a YAML parser in PHP.
Now before folk go off the deepend, there is a PHP5 extension which is based on a YAML parser and emitter in C called “Syck”. Those of you in other languages are likely vaguely familiar with the Syck bindings for Ruby, Python, Perl, etc. But since YAML is overlooked in PHP to such a huge extent it’s pretty hard to pin it down for PHP5. Gavin Vess posted a link to Gentoo Linux in a reply which shows it’s available and being maintained.
So, YAML Parser – where to start? YAML has a few defining format characteristics – it’s so useable because it’s written in a typical western style, top to bottom and left to right. Nesting of YAML nodes is based on indentation levels (likely the main “problem issue” of sorts). In addition the syntax is fairly simple to learn though those single characters call for having a reference card posted over your PC unless you’re a total YAML fiend.
A quick look around the web at the most recent YAML parsers pretty much confirms that LL(1) parsers have gained widespread adoption for YAML. It’s easy to see why since the grammer set is short and an LL(1) parser (recursive descent) is simple enough to implement and test. I see no reason not to take a similar approach. I’m going to dig around at putting together a Parser structure over the weekend – something to get the ball rolling and provide fodder for a formal proposal.
Related posts:
| Print article | This entry was posted by Pádraic Brady on March 21, 2007 at 10:55 am, and is filed under PHP General, PHP Security, Zend Framework. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |
-
Pierre Minnieur
-
http://blog.astrumfutura.com Pádraic Brady
-
http://blog.milkfarmsoft.com/ Alexey Zakhlestin
-
David Sanders
-
http://blog.milkfarmsoft.com/ Alexey Zakhlestin
-
http://blog.astrumfutura.com Pádraic Brady
-
Jcart
-
http://blog.astrumfutura.com Pádraic
-
http://drakos7.net Awn
-
kevwilliams at g mail dot com
