News Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Matthew Turland's Blog:
The Configuration Pattern in Zend Framework
September 28, 2009 @ 09:07:31

Matthew Turland has pointed out a pattern he's seen happening over and over again in the Zend Framework, what he calls the "Configuration Pattern".

Here's how it works. Have a look at the constructor for Zend_Form. It accepts an $options parameter, which can be an associative array or Zend_Config instance. If it's an array, setOptions() is called. If it's a Zend_Config instance, setConfig() is called, which then converts the Zend_Config instance to an associative array and passes that to setOptions(). So, either way, you end up in the same method with the same type of data. setOptions() then iterates over the associative array it receives. It takes the index of each element and looks for a corresponding setter method.

This method helps to reduce the overall function calls (including a method_exists) and can help to produce cleaner code in the process. A comment on the post also points out related comments from Matthew Weier O'Phinney about these options.

0 comments voice your opinion now!
zendframework configure pattern getoptions


blog comments powered by Disqus

Similar Posts

Blue Parabola Blog: Getting Started with Zend_Test

Jani Hartikainen's Blog: Improving Ajax performance in Zend Framework applications

Maarten Balliauw's Blog: Indexing Word 2007 (docx) files with Zend_Search_Lucene

CodeForest.net: Android JSON-RPC client and PHP Zend Framework server

Matthew Weier O'Phinney's Blog: Using Action Helpers To Implement Re-Usable Widgets


Community Events

Don't see your event here?
Let us know!


application performance framework configure podcast conference laravel community api library release introduction symfony2 php7 composer interview part2 series example opinion

All content copyright, 2015 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework