Step right up for Zend Framework 1.8

Zend Framework

The new framework 1.8 is out... *happy* Here is a rough list of my experiences with version 1.8, which I have been using for a week. The list is not complete, but should still give a brief overview of what's new in version 1.8. What stands out to me in particular is the effort to turn the Zend Framework into a real framework now. The criticism that it is merely a collection of PHP classes no longer holds true as of version 1.8.

Components such as Zend_Application and Zend_Tool now also offer scaffolding, which you may know from Rails. Behind the scenes, Zend_Tool uses the new Zend_CodeGenerator component, which can generate PHP code "on the fly." This is complemented by simplified read access through Zend_Reflection (example at the end of the article).

Zend_Loader

The old autoloader Zend_Loader::autoloader, which was registered through Zend\_Loader::registerAutoload, is now marked as deprecated. You should now use the new Zend_Loader_Autoloader. The API change is not very nice, but the new autoloader makes up for it with several new features. For example, namespaces can now be defined.

Example:

// Register autoloader
require_once 'Zend/Loader/Autoloader.php';
$autoLoader = Zend_Loader_Autoloader::getInstance();
$autoLoader->registerNamespace('Inmon_');

You can even use autoloaders from other frameworks:
Example with ezComponents:

$autoloader->pushAutoloader(array('ezcBase', 'autoload'), 'ezc');

The new resource loader is also great: it can load plugins, helpers, models, forms and so on. It can be initialized in a bootstrap class inside a module, for example. For this, Zend_Application provides the new Zend_Application_Module_Bootstrap class. The bootstrap should be located directly in the module directory.

Example of a module bootstrap for an admin module:

'Admin',
            'basePath'  => dirname(\_\_FILE\_\_),
        ));
        return $autoloader;
    }
}

Zend_Application looks for the Bootstrap class in each module. If it finds one, all "_init" methods are executed automatically. In the previous case, the autoloader for the module is initialized. The autoloader initializes all paths itself.
Zend_Application_Module_Autoloader can load the following resources out of the box:

  • Forms
  • Plugins
  • Models
  • DbTables
  • Services
  • View helpers
  • View filters

Zend_Application

Zend_Application is a new component that lets you standardize initialization and access to resources such as database connections, helpers and so on.

The component allows you to define your own resources and manage their configuration in a Zend_Config. Several standard resources are already available, such as FrontController, View, Router, Db, Layout, Translate and Session.

If you use Zend_Application consistently, you can reuse resources that you use in different applications. It is also possible to configure the application's modules through Zend_Application. Internally, this is done by the Zend_Application_Resource_Modules resource.

Warning! For this to be initialized, the configuration must contain an entry for the resource. In my case, the following entry must be in the INI file (it also works with XML).

; Modules resource -> Ohne diesen Eintrag werden die Module-Konfiguration nicht geladen!
resources.modules =

; Beispiel für das Überschreiben einer Datenbank Konfiguration innerhalb eines Moduls...
; Dies wird nur für das Modul "mymodule" durchgeführt
mymodule.resources.db.params.dbname = "meine_datenbank"

The component encapsulates all resources in smaller "bootstraps" controlled by a "large" bootstrap class. With this new organization of resources, it is now also possible to load only specific resources for a cron job.

It is noticeable that dependencies have been considered too.

A more detailed description would go beyond the scope of this article.

The manual http://www.framework.zend.com/manual/de/zend.application.html reveals the remaining possibilities.

Zend_Controller

Routes now support translating parameters using Zend_Translate. See: http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.standard.translated-segments

Zend_Reflection

The package provides a wrapper for the PHP Reflection API. It simplifies access to information. Example (methods of the parent class from within a class):

$reflectionClass = new Zend_Reflection_Class(__CLASS__);
print_r($reflectionClass->getParentClass()->getMethods());

Official list of changes

http://devzone.zend.com/article/4524-Zend-Framework-1.8.0-Released

  • Zend_Tool, contributed by Ralph Schindler
  • Zend_Application, contributed by Ben Scholzen and Matthew Weier O'Phinney
  • Zend_Loader_Autoloader and Zend_Loader_Autoloader_Resource, contributed by Matthew Weier O'Phinney
  • Zend_Navigation, contributed by Robin Skoglund
  • Zend_CodeGenerator, by Ralph Schindler
  • Zend_Reflection, Ralph Schindler and Matthew Weier O'Phinney
  • Zend Server backend for Zend_Cache, contributed by Alexander Veremyev
  • Zend_Service_Amazon_Ec2, contributed by Jon Whitcraft
  • Zend_Service_Amazon_S3, Justin Plock and Stas Malyshev
  • Incorporated Dojo 1.3
  • Added support for arbitrary Dojo Dijits via view helpers
  • Zend_Filter_Encrypt, contributed by Thomas Weidner
  • Zend_Filter_Decrypt, contributed by Thomas Weidner
  • Zend_Filter_LocalizedToNormalized and _NormalizedToLocalized, contributed by Thomas Weidner
  • Support for file upload progress support in Zend_File_Transfer, contributed by Thomas Weidner
  • Translation-aware routes, contributed by Ben Scholzen
  • Route chaining capabilities, contributed by Ben Scholzen
  • Zend_Json expression support, contributed by Benjamin Eberlei and Oscar Reales
  • Zend_Http_Client_Adapter_Curl, contributed by Benjamin Eberlei
  • SOAP input and output header support, contributed by Alexander Veremyev
  • Support for keyword field search using query strings, contributed by Alexander Veremyev
  • Support for searching across multiple indexes in Zend_Search_Lucene, contributed by Alexander Veremyev
  • Significant improvements for Zend_Search_Lucene search result match highlighting capabilities, contributed by Alexander Veremyev
  • Support for page scaling, shifting and skewing in Zend_Pdf, contributed by Alexander Veremyev
  • Zend_Tag_Cloud, contributed by Ben Scholzen
  • Locale support in Zend_Validate_Int and Zend_Validate_Float, contributed by Thomas Weidner
  • Phonecode support in Zend_Locale, contributed by Thomas Weidner
  • Zend_Validate_Db_RecordExists and _RecordNotExists, contributed by Ryan Mauger
  • Zend_Validate_Iban, contributed by Thomas Weidner
  • Zend_Validate_File_WordCount, contributed by Thomas Weidner