Fever Framework Update

Posted on 11. Feb, 2010 by Will Fitch in News, PHP Fever Framework

I just want to update everyone on the status of the framework. It is still on schedule for the February 26th release!

As we countdown to the public beta release, I want to keep you informed of some exciting functionality that’s being added.

Functionality

Along with the JSON controller, a new XML controller has been added. This allows you to return nearly anything from an action and it will automatically convert it to XML, send the proper content-type header and provide the data to the client. Here is an example of how it would work:

PHP
  1. <?php
  2.  
  3. class MyController extends \Fever\Controller\Action\AbstractXml
  4. {
  5.     public function getTestData()
  6.     {
  7.         return array
  8.             (
  9.             ‘name’ => ‘Will Fitch’,
  10.             ‘attributes’ =>
  11.                 array(
  12.                 ‘height’ => 76,
  13.                 ‘hair’ => ‘brown’,
  14.                 ‘eyes’ => ‘brown’
  15.                 )
  16.             );
  17.     }
  18. }

This will, in turn, produce the following XML document to the client:

XML
  1. <results>
  2.     <name>Will Fitch</name>
  3.     <attributes>
  4.         <height>76</height>
  5.         <hair>brown</hair>
  6.         <eyes>brown</eyes>
  7.     </attributes>
  8. </results>

Now I’m sure there are those out there that are screaming, “But I want to customize the name of the elements!!!”. No problem! There is a method withing the AbstractXml controller called “setXmlElement” which accepts an instance of SimpleXMLElement. This will be used when converting data provided into XML.

This is all thanks to a new component called “XmlConverter” which lives in the \Fever\IO\Xml namespace. It follows the chain-of-command pattern and iterates until it finds the correct data type provided. Here are a list of converters available for iteration:

  • ArrayToXml
  • BooleanToXml
  • NullToXml
  • NumberToXml
  • ObjectToXml
  • StringToXml

All of these are separate entities, so they can be used independently.

I’ll continue to update throughout the upcoming days before the public beta!

Tags: ,

Related Articles

Leave a Reply