Zend Framework Classloading Performance

As outlined in the Zend Framework Documentation it’s possible to speed things up a little by removing (almost) all require_once calls from the Framework and relying solely on the autoloading mechanism. I haven’t benchmarked this and I’m fairly certain that it’s a case of micro-optimization but I thought I’d give it a try anyway. The snipped posted there has some minor problems on OS X however. For one the -wholename parameter for find isn’t implemented (can be replaced with -path) and although sed does work, you need to use gsed if you want to pass the arguments as described in the documentation. So here’s the OS X version of the snippet:

find . -name '*.php' -not -path '*/Loader/Autoloader.php' \
  -not -path '*/Application.php' -print0 | \
  xargs -0 gsed --regexp-extended --in-place 's/(require_once)/\/\/ \1/g'
Published on Aug 25, 2009 at 9:56 pm by Jan Gorman.
Filed under: Code Tags:, , , , , , , , , , , | No Comments
Zend_Form_Element_Exception

After upgrading to Zend Framework 1.8 earlier this week we’ve had a few more minor glitches that have surfaced since. The one which took me some time to figure out was 'Zend_Form_Element_Exception' with message 'No file decorator found... unable to render file element' To ease the generation of forms and get them all to look the same we use a class named Form_Static_Render that the Zend_Form gets pushed into and which takes care of styling, decorators, preview pages and display of form errors. It’s quite a clever little thing. To achieve the proper styling our extension to Zend_Form calls

$element->clearDecorators();

and then either adds the default ViewHelper or whatever gets passed to the method and that was the root of the problem. When clearing the decorators, Zend_Form_Element_File now explicitly requires you to add the File Decorator again before rendering. After discovering that, it turned out being a quick fix…

Published on May 28, 2009 at 1:32 pm by Jan Gorman.
Filed under: Code, Hint Tags:, , , , | 1 Comment
Replacing Zend_Loader with Zend_Loader_Autoloader

It’s been a while since my last post but I’ve been very busy the last couple of weeks. That’s what also kept me from updating to Zend Framework 1.8 (or 1.8.1 by now already) in our production environment. It has been very smooth so far, the only change that required some work was the deprecation of the old

Zend_Loader::registerAutoload( '...' );

However, upgrading everything to the new Zend_Loader_Autoloader_Interface actually worked quite a lot easier than expected:

class Webwerk_Autoloader implements Zend_Loader_Autoloader_Interface
{
  /**
   * Autoloader
   */
  public function autoload ( $class )
  {
    // Custom autoloading of different classes
    // Each one has a return value
 
    // Fallback
    try {
      Zend_Loader::loadClass( $class );
      return $class;
    } catch ( Exception $e ) {
      return false; // Nothing there
    }
 
  }
}

And in the bootstrapper we have:

$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader( true );
$autoloader->pushAutoloader( new Webwerk_Autoloader( ) );

So the only change was making Webwerk_Autoloader match the Zend_Loader_Autoloader_Interface as well as changing the bootstrap to use the default autoloader as fallback and registering the custom autoloader.

Published on May 25, 2009 at 1:25 pm by Jan Gorman.
Filed under: Code, Hint Tags:, , , , , | No Comments
PHP Quick Profiler

Wow, this is really cool. Ryan Campbell of Particle Tree just put up a post about a tool they developed and now released called PQP to help with profiling PHP code. We developed and use something similar on top of Zend Framework (just not as cool looking) and ours doesn’t come with the memory logging and timing features that PQP provides. Definitely going to give this a try and spruce up the own tool..

Published on Apr 23, 2009 at 7:12 pm by Jan Gorman.
Filed under: Code, Hint Tags:, , , , | No Comments
Zend Framework 1.8 Preview Release

The Zend Framework 1.8 Preview Release is now available for testing! This latest release includes a new CLI for creating your initial project structure, adding resources to your project so no more rails envy:

$ zf create project theNewProject

This will create the initial project layout with directories, controllers and all. Brilliant.

The new Zend_Application has been added to handle the task of bootstrapping your application and other cool stuff, one of the most important features is the new way that modules are treated in Zend_Application which should help keep your application DRYer than ever.

Published on Apr 08, 2009 at 6:33 am by Jan Gorman.
Filed under: Code, Link Tags:, , , , | No Comments


Zend_Form decorator

Since Matthew Weier O’Phinney can explain this a lot better than I ever could, I’ll simply refer you to his excellent post about Zend_Form decorators, well worth a read.

Published on Apr 06, 2009 at 8:05 am by Jan Gorman.
Filed under: Code, Hint Tags:, , , , , | No Comments
Using a different Zend_Layout for each module

Time for another little code hint. I really like the Zend-Framework and we’ve been using it very successfully on quite a large project for the last couple of months now. We’ve extended the basis quite a bit with plenty of wrappers to fit our client’s needs and the way the framework is put together all of this works very elegantly.
One of the shortcomings I find is the way layouts are handled. From my experience, Zend_Layout is one of the hardest parts to grasp for beginners anyway, the lack of a bulit in support for modules makes it even harder. Controller-Plugins to the rescue!

Read the full post

Published on Mar 20, 2009 at 3:58 pm by Jan Gorman.
Filed under: Code Tags:, , , , | No Comments