Archive for 'PHP Fever Framework'

Module Support Added to Fever Framework

Posted on 22. Feb, 2010 by Will Fitch.

0

I’m excited to announce that modules will be supported in time for the public preview on Friday! This is just one of the many steps taken to make Fever as flexible as possible.

Modules Overview

Modules are kind of mini-applications within a larger web application. They maximize component reuse by developing the controllers, models, libraries and views based solely on that module. When that module is needed, you simply add the path to that module in your configuration and you’re done!

An example would be a CMS that has the following components: blog, forms-builder and page generator. All three of those are components that make up the CMS (being the “larger” web application). The modules can be developed so that the views only contain the necessary HTML to present that functionality. The CMS can then use a layout (also included in Fever) to surround the view contents of the module. The layout will contain the primary HTML (usually CSS, JS, navigation, etc), and the blog module will supply the supplemental HTML to fill the rest.

How do you maximize component reuse? If you develop the HTML completely CSS-based (no inline CSS, please ;p), each application using that component can customize their own CSS file, include it in the layout and the component will look unique to each application using it.

Telling Fever You’re Using Modules

You can tell Fever that you’re using modules in your application two ways: configuration or through the FrontController API.

Text
  1. fever.app.useModules = true

or

PHP
  1. <?php
  2. $front = Fever\Controller\FrontController::getInstance();
  3. $front->setUseModules(true);

At this point, your entire application must use modules. You will no longer be able to use simple controller-based functionality. That said, Fever implements modules a little different, and there’s some important information you need to know when using them:

What Makes Modules Different in Fever?

There may be cases where you need to customize a module’s functionality, or the module may require key information specific to each application. We recognized this, and added shared models and libraries. This means every module has access to each application’s models and libraries, and vice-versa.

Each module also has it’s own bootstrap to customize its MVC needs. While this is handy, module-based bootstraps do not have the same flexibility as application bootstraps. This is due to the way the request is handled.

An application’s bootstrap is called before the request/response objects are initialized and the FrontController actually does any work. This makes a difference in the module bootstraps as the request object has been initialized and the module has been identified. Beyond this, nothing is different.

Continue Reading

Fever Framework Update

Posted on 11. Feb, 2010 by Will Fitch.

0

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!

Continue Reading

Introducing the PHP Fever Framework

Posted on 05. Feb, 2010 by Will Fitch.

3

Overview

The birth of a new MVC framework, like most others, is spawned by frustrations with the functionality of one or more other frameworks: too much emphasis on design theory, not enough in others, speed, flexibility… the list goes on. The Fever Framework is no different. In an attempt to find a happy medium with design theory, speed, flexibility and latest PHP functionality, this framework is targeted at many audiences from small, shared-hosting environments to enterprise-level web applications. That said, let me provide some goals I’ve kept in mind while developing the Fever Framework.

Some Goals

Design theory and flexibility

I have often wrestled among object-oriented design theory, development time and speed, not to mention optimization which is usually the 800 pound gorilla in the room. Developers deal with this all the time; trying to squeeze a few more days in to ensure the code looks as good as it behaves.

The Fever Framework implements many OOP design theories and MVC functions. However, in some cases, it specifically goes out of the way to provide an easier interface for developers. For example, let’s say you’re implementing a series of actions which return JSON encoded objects. In many frameworks, this is taken care of within the model, provided back to the controller and sent to the browser. In the Fever Framework, you have a few options:

Controller-level

PHP
  1. <?php
  2. class MyBlog extends \Fever\Controller\Json
  3. {
  4.    
  5.     public function getPost($id)
  6.     {
  7.         $posts = new BlogPosts();
  8.         return $blog->findByPrimaryKey($id);
  9.     }
  10. }

The above example is a controller which extends the Json controller. The “BlogPosts” class is a model which extends the \Fever\Db\ActiveRecord class. The “findByPrimaryKey” is a method provided within AR. Once the object is returned, the Json controller handles the JSON encoding and sending proper HTTP headers to the client.

Model-level

PHP
  1. <?php
  2. class BlogPosts extends \Fever\Db\ActiveRecord
  3. {
  4.    
  5.     public function getBlogPost($id)
  6.     {
  7.         $post = parent::findByPrimaryKey($id);
  8.         return $this->setData($post)->toJson();
  9.     }
  10.    
  11.     public function __construct()
  12.     {
  13.         parent::__construct(array(‘db’ => \MyApp\Db::getReadInstance()));
  14.     }
  15. }

This example returns the data already JSON encoded to the caller. It extends the ActiveRecord class, set’s the data via “setData” (provide in DataModel), and chains “toJson” to the request. This returns the JSON encoded string needed.

This is only two of many ways to achieve the above goal. Design theory and flexibility aren’t mutually exclusive, and flexibility is just as important as design.

Latest PHP functionality

As you’ve already noticed, I’ve incorporated namespaces into the framework. This is especially nice when editing inside an IDE and you can dive down into each namespace to find code (remember the frameworks that use hack namespace styles that make the class name 50+ characters long?). The naming convention is easy to read and makes sense!

Speed

The Fever Framework can be used as a set of libraries, but I’ve taken the liberty to assume you’ll be using autoloading. There is a provided class, Fever\Autoloader which takes care of the inclusion of files for classes/namespaces. Since FF is setup to so that each class falls under a directory based on it’s namespace, autoloading is fast and efficient! With that in mind, there is an important feature (some might argue) you should keep in mind.

Each class comes with a comment block that contains all of the file dependencies as require_once statements. If you so choose, you can remove the comment block and everything will be just fine. However, keep in mind that each require_once call makes a full file scan. This is extremely unoptimized!

When you get the code base , you’ll also notice that a printed stack trace will be relatively short. You won’t have 30 classes printed out that are abstracts of abstracts of abstracts of interfaces. Like I said before, design theory isn’t the most important feature!

Models

As a PHP developer, this is likely where you’ll spend most of your time. Like Zend Framework, Fever doesn’t come with a abstract model. It provides a subset of classes for you to decide to use. For example, if you’re working at the table level, you might choose to use Fever\Db\ActiveRecord, which provides most of the functionality of the Active Record pattern. If you are only using stored procedures, Fever\Db\Procedure might be your choice. But databases aren’t the only types of models. What if you’re working with a SOAP client? You could extend the Fever\Soap\Client, which provides functionality related to SOAP.

Modules

Module-based application development is included. If you choose to use this, you simply add a couple of lines of code to your global bootstrap. If not, do nothing!

Each module is allowed to have its own bootstrap. That means you can customize it as a separate application. You can also define how modules are recognized. If each module is a subdomain, you simply provide that match to the router, and it will recognize it. If it’s a subdirectory, do the same!

Views

To provide some options, the framework comes with both a standard PHP view type as well as Smarty. By default, the standard PHP type is used. This is easily changed within the bootstrap of your application, or even module. Each view type comes with a set of helpers as well.

How do I get the code?

The alpha review will start on February 19th. This will include developer code reviews and testing. This circle will be relatively small (10 – 20 developers) and will last one week. The public beta will begin on February 26th, and a download will be available here.

If you are interested in joining the alpha review, please email me at will[at]phpfever[dot]com or use the contact form.

Continue Reading