You are on page 1of 61

Matthew Weier O'Phinney

Project Lead

Ralph Schindler
Software Engineer

Introducing Zend Framework 2.0
3 November 2010

Some History Summer 2005:
Coding begins on Zend Framework, with a  handful of cherry­picked partners.

2

Some History Fall 2005:
First annual ZendCon Andi and Zeev announce the PHP Community  Process, which includes involvement in the  Eclipse Foundation, a relaunch of Zend's  Developer Zone, and Zend Framework.

3

4 .Some History March 2006: Zend Framework 0. contributions require a  Contributor License Agreement.1.0 released Project opened up to the public for  contributions.

 and more. service  providers.Some History July 2007: Zend Framework 1.  5 .0.  Authentication and Authorization layers.0 released Project includes MVC stack. Table and Row  Data Gateways. Still largely deemed a work in progress. loads of Service APIs.

  6 . and  many Zend_View enhancements.Some History March 2008: Zend Framework 1.5.0 released Includes Zend_Form and Zend_Layout.

7 .0 released Includes Dojo Toolkit integration. functional test  utilities.6.Some History September 2008: Zend Framework 1.

Some History November 2008: Zend Framework 1.7. performance  improvements. 8 .0 released Includes AMF support.

 Zend_Tool. First release widely seen as providing a full  stack.8.0 released Includes Zend_Application. 9 .Some History April 2009: Zend Framework 1.

9. and tons of community­ driven enhancements. 10 .0 released Includes reworked feed component.Some History July 2009: Zend Framework 1.  Zend_Feed_Reader.

Some History October 2009: First monthly community bug hunts launched. 11 .

 and community­driven  improvements. re­organized  documentation.10.Some History January 2010: Zend Framework 1. 12 .0 released Includes Zend_Feed_Writer.

Some History February 2010: Development on Zend Framework 2.0 begins 13 .

Some History June 2010: Formation of the Community Review Team 14 .

15 .Some History November 2010: Zend Framework 1.0 released Includes mobile support and  SimpleCloud API.11.

Some History The future? 16 .

Revolution? .

.Evolution.

3­specific paradigms  where they fit 19 .Incremental Improvements Autoload only (strip require_once calls) Conversion to PHP namespaces  Refactor and standardize exceptions usage Refactor and consistently implement a  single plugin loading strategy Refactor to use PHP 5.

Rewrite only  where it makes  sense .

21 . Difficult to add pre/post tasks. Difficult to extend. Difficult to get schema metadata in a consistent fashion.Zend_Db Difficult to get the underlying connection  and share it between instances or different  classes.

Zend_Session Black­box design != testable Namespace storage incompatible with  $_SESSION  Many incompatibilities with ext/session 22 .

23 . Zend\Session\Container as SessionContainer.use Zend\Session\SessionManager. $container['somekey'] = 'somevalue'. $manager). $container = new SessionContainer('Foo'. )). $manager = new SessionManager(array( 'class' => 'My\Custom\SessionConfiguration'. $container->setExpirationHops(2). 'storage' => 'My\Custom\SessionStorage'.

Filters and Validators Static access and chain usage were mixed  in the same object Did not use common plugin loading  methodology Paradigms required in Filter_Input and  Form were not supported 24 .

namespace Zend\Validator. if ($chain->isValid($value)) { // passed validation } 25 . 'int')) { // passed validation } $chain = new ValidatorChain(). if (StaticValidator::execute($value. $chain->addValidator(new I nt(). true) ->addValidator(new GreaterThan(10)).

Add features favoring  extensibility .

Examples SignalSlot FilterChain SPL extensions (SplStack. SplQueue) PluginBroker 27 .

 not that kind of explicit… .Favor the Explicit Okay.

too arcane Magic is  sometimes .

/** * Hits Zend_View::__call() * Calls Zend_View::getHelper() * Calls Zend_View::_getPlugin() * Calls Zend_Loader_PluginLoader::load() * Calls Zend_Loader::isReadable() * Calls call_user_func (hits autoloader.)) */ 30 .echo $this->headLink()->appendStylesheet('foo.....css').) * which calls Zend_Loader::loadClass * which calls Zend_Loader::loadFile * which calls include_once * Instantiates helper * Calls method on helper via call_user_func_array() * Returns helper instance * Call method on instance (hits __call.

(hidden) automation  makes learning hard .

} } Where is  this defined? When is  it rendered? What about layouts? 32 .class FooController extends Zend_Controller_Action { public function someAction() { $this->view->foo = 'bar'.

css'). /** * Hits PhpRenderer::broker() * Calls HelperBroker::load() * Calls HelperLoader::load() * Hits autoloader * which simply does an include_once * Instantiates helper * Calls method on helper */ .Explicit code is… easier to  understand $this->broker('head_link') ->appendStylesheet('foo.

Explicit code is… easier to profile .

Explicit code is… easier to maintain .

Optimize for  performance .

37 .

Profiling Profile to determine  where the pain  points are Look for big gains  primarily Fix them 38 .

Autoloading: Problems
Class Maps are fastest But they require maintenance Using the include_path is slow Not using it requires maintenance Using the include_path is most flexible But slower than alternatives

39

Autoloading: Solutions
Ship a ClassMapAutoloader by default
Class maps for full ZF library, and per­component Tools for generating class maps Ultimate in performance

StandardAutoloader requires  namespace/path pairs
Flexibility and performance during development

StandardAutoloader can act as a fallback  autoloader
Flexibility at the cost of performance
40

// .classmap.php return array(
'Foo\SomeController' => __DIR__ . '/foo/controllers/SomeController.php', 'Foo\Model\Bar' => __DIR__ . '/foo/models/Bar.php',

);

// ClassMapAutoloader require_once 'Zend/Loader/ClassMapAutoloader.php'; $loader = new Zend\Loader\ClassMapAutoloader( './.classmap.php'); $loader->register(); $bar = new Foo\Model\Bar();
41

$loader->register(). $loader = new Zend\Loader\StandardAutoloader(array( 'namespaces' => array( 'Foo' => __DIR__ .php'. '/library/Foo'). 42 . $bar = new Foo\Model\Bar(). )).// StandardAutoloader require_once 'Zend/Loader/StandardAutoloader.

Plugin Loading: Problems Path stack­based autoloading is sloooow Prefix paths are hard to grasp Particularly when coupled with stacks Overriding the paths without propagating  paths is hard Case sensitivity becomes an issue 43 .

Plugin Loading: Problems Current solution only solves the class  loading aspect of plugin loading Instantiation happens differently per  component Persistence happens differently per  component 44 .

 including arguments Act as registry Allows attaching single broker to many  objects 45 .Plugin Loading: Solutions Class alias based maps by default Loaders are coupled with brokers Handle instantiation.

/* class loader */ namespace My\Component. } 46 . 'foo_bar' => 'My\Component\FooBar'. ). Zend\Loader\PluginBroker. class ComponentLoader extends PluginClassLoader { protected $plugins = array( 'foo' => 'My\Component\Foo'. use Zend\Loader\PluginClassLoader.

class ComponentBroker extends PluginBroker { protected $defaultClassLoader = 'My\Component\PluginClassLoader'. } } 47 ./* class broker */ namespace My\Component. } return true. protected function validatePlugin($plugin) { if (!$plugin instanceof Adapter) { throw new Exception\RuntimeException(). Zend\Loader\PluginBroker. use Zend\Loader\PluginClassLoader.

$options)./* factory */ namespace My\Component. } } 48 . array $options) { return $this->broker() ->load($adapter. class Factory { /* Not shown: setBroker() and broker() methods */ public function get($adapter.

Ease the learning curve .

Examples do not show common use cases. Inconsistent structure between  documentation of different components.  only using the component individually. 50 . No examples showing complete application  development. methods) is  not presented.Common Documentation Complaints Options are (often) not documented. Available functionality (typically.

Uncertainty where and when to extend or  implement extension points – and how to  get ZF to use them. 51 .Common Learning Problems Magic (“__” methods) is hard to learn  (just ask Harry Potter). Some patterns are non­obvious in usage  (Zend_Form decorators…).

Proposed Solutions Coding: Refactor where usage patterns differ  from design Reduce number of magic calls Refactor for consistency Refactor unclear APIs 52 .

Proposed Solutions Documentation Standards: Introduction Quick Start Options Methods Examples 53 .

The Roadmap .

 Session rewrite.3 namespaces Including SPL additions. and  addition of SignalSlot Autoloading and plugin loading/brokering Including View rewrite Exceptions In fact.Completed Milestones Migration to Git for ZF2 development Stripping of require_once calls Migration to PHP 5. we've just released a new  55 .

0.Completed Milestones Zend Framework 2.0dev2: http://bit.ly/zf2dev2 56 .

Remaining Milestones MVC Refactoring/Rewrite Internationalization and Localization Testing Documentation Packaging Migration tools 57 .

How  YOU  can  help .

zend.dev on Freenode zf­contributors­subscribe@lists.ly/zf2wiki zf­contributors mailing list: IRC:  #zftalk.com 59 .Contribute to ZF2! ZF2 wiki: http://bit.

com/zendframework/zf2 Official repo:  git://git.ZF2 Git Git guide:  http://bit.git http://git.zendframework.zendframework.com/zf.com/ You still need to sign a CLA! 60 .ly/zf2gitguide GitHub:  http://github.

zend.in/2287 Twitter: weierophinney.http://framework.  ralphschindler Thank you! .com Feedback: http:://joind.