Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Introducing Zend Framework 2.0

Introducing Zend Framework 2.0

Overview of the architecture of Zend Framework 2.0, including showcases of several new components. Shows status as of May 2011.

Matthew Weier O'Phinney

September 27, 2011
Tweet

More Decks by Matthew Weier O'Phinney

Other Decks in Technology

Transcript

  1. Introducting ZF2 1 – 1 / 70 Introducing Zend Framework

    2.0 Matthew Weier O’Phinney Project Lead 25 May 2011
  2. ZF1 Timeline Introducting ZF2 3 – 3 / 70 Oct

    2005: Announcement Mar 2006: 0.1.0 Jul 2007: 1.0.0 Mar 2008: 1.5.0 Sep 2008: 1.6.0 Nov 2008: 1.7.0 Apr 2009: 1.8.0 Aug 2009: 1.9.0 Jan 2010: 1.10.0 Nov 2011: 1.11.0 Announced at first ZendCon.
  3. ZF1 Timeline Introducting ZF2 3 – 3 / 70 Oct

    2005: Announcement Mar 2006: 0.1.0 Jul 2007: 1.0.0 Mar 2008: 1.5.0 Sep 2008: 1.6.0 Nov 2008: 1.7.0 Apr 2009: 1.8.0 Aug 2009: 1.9.0 Jan 2010: 1.10.0 Nov 2011: 1.11.0 First public preview release. Code repository opened. Fall of 2006, rewrite of MVC performed to lead towards stable release.
  4. ZF1 Timeline Introducting ZF2 3 – 3 / 70 Oct

    2005: Announcement Mar 2006: 0.1.0 Jul 2007: 1.0.0 Mar 2008: 1.5.0 Sep 2008: 1.6.0 Nov 2008: 1.7.0 Apr 2009: 1.8.0 Aug 2009: 1.9.0 Jan 2010: 1.10.0 Nov 2011: 1.11.0 First stable release. Basic MVC system, with plugins, action helpers, automated view rendering etc. Many web service API consumers. Server classes for XML-RPC, REST, etc.
  5. ZF1 Timeline Introducting ZF2 3 – 3 / 70 Oct

    2005: Announcement Mar 2006: 0.1.0 Jul 2007: 1.0.0 Mar 2008: 1.5.0 Sep 2008: 1.6.0 Nov 2008: 1.7.0 Apr 2009: 1.8.0 Aug 2009: 1.9.0 Jan 2010: 1.10.0 Nov 2011: 1.11.0 First minor release. Zend_Form introduced. Zend_Layout introduced. Layout-aware view helper system introduced.
  6. ZF1 Timeline Introducting ZF2 3 – 3 / 70 Oct

    2005: Announcement Mar 2006: 0.1.0 Jul 2007: 1.0.0 Mar 2008: 1.5.0 Sep 2008: 1.6.0 Nov 2008: 1.7.0 Apr 2009: 1.8.0 Aug 2009: 1.9.0 Jan 2010: 1.10.0 Nov 2011: 1.11.0 Dojo integration. PHPUnit scaffolding for testing controllers. Introduction of the ContextSwitch action helper.
  7. ZF1 Timeline Introducting ZF2 3 – 3 / 70 Oct

    2005: Announcement Mar 2006: 0.1.0 Jul 2007: 1.0.0 Mar 2008: 1.5.0 Sep 2008: 1.6.0 Nov 2008: 1.7.0 Apr 2009: 1.8.0 Aug 2009: 1.9.0 Jan 2010: 1.10.0 Nov 2011: 1.11.0 AMF support. Performance improvements.
  8. ZF1 Timeline Introducting ZF2 3 – 3 / 70 Oct

    2005: Announcement Mar 2006: 0.1.0 Jul 2007: 1.0.0 Mar 2008: 1.5.0 Sep 2008: 1.6.0 Nov 2008: 1.7.0 Apr 2009: 1.8.0 Aug 2009: 1.9.0 Jan 2010: 1.10.0 Nov 2011: 1.11.0 Introduction of Zend_Tool. Introduction of Zend_Application. First widely usable release of ZF.
  9. ZF1 Timeline Introducting ZF2 3 – 3 / 70 Oct

    2005: Announcement Mar 2006: 0.1.0 Jul 2007: 1.0.0 Mar 2008: 1.5.0 Sep 2008: 1.6.0 Nov 2008: 1.7.0 Apr 2009: 1.8.0 Aug 2009: 1.9.0 Jan 2010: 1.10.0 Nov 2011: 1.11.0 Addition of Zend_Feed_Reader. PHP 5.3 support/compatibility. Primarily community-led additions. Beginning of monthly bug hunts in October.
  10. ZF1 Timeline Introducting ZF2 3 – 3 / 70 Oct

    2005: Announcement Mar 2006: 0.1.0 Jul 2007: 1.0.0 Mar 2008: 1.5.0 Sep 2008: 1.6.0 Nov 2008: 1.7.0 Apr 2009: 1.8.0 Aug 2009: 1.9.0 Jan 2010: 1.10.0 Nov 2011: 1.11.0 Integration of ControllerTestCase with Zend_Application. Addition of Zend_Feed_Writer, marking completion of Zend_Feed refactoring. Documentation changes: adoption of PhD to render end-user manual, introduction of comment system, and new “Learning Zend Framework” section. Primarily community-led additions.
  11. ZF1 Timeline Introducting ZF2 3 – 3 / 70 Oct

    2005: Announcement Mar 2006: 0.1.0 Jul 2007: 1.0.0 Mar 2008: 1.5.0 Sep 2008: 1.6.0 Nov 2008: 1.7.0 Apr 2009: 1.8.0 Aug 2009: 1.9.0 Jan 2010: 1.10.0 Nov 2011: 1.11.0 Mobile support via Zend_Http_UserAgent. SimpleCloud API via Zend_Cloud.
  12. Introducting ZF2 7 – 7 / 70 Zend Framework 2.0’s

    focus is on improving consistency and performance.
  13. Namespaces Introducting ZF2 9 – 9 / 70 The Problem

    Verbose class names The Solution Use PHP namespaces
  14. Basics Introducting ZF2 10 – 10 / 70 Every class

    file declares a namespace One namespace per file
  15. Basics Introducting ZF2 10 – 10 / 70 Every class

    file declares a namespace One namespace per file Any class used that is not in the current namespace (or a subnamespace) is imported and typically aliased
  16. Basics Introducting ZF2 10 – 10 / 70 Every class

    file declares a namespace One namespace per file Any class used that is not in the current namespace (or a subnamespace) is imported and typically aliased Global resolution is discouraged, except in the case of classes referenced in strings
  17. Namespace Example Introducting ZF2 11 – 11 / 70 §

    namespace Zend\EventManager; use Zend\Stdlib\CallbackHandler; class EventManager implements EventCollection { /* ... */ }
  18. Using Aliases Introducting ZF2 12 – 12 / 70 §

    namespace Zend\Mvc; use Zend\Stdlib\Dispatchable , Zend\Di\ServiceLocator as Locator; class FrontController implements Dispatchable { public function __construct(Locator $locator) { $this ->serviceLocator = $locator; } }
  19. Recommendation for Migration Introducting ZF2 13 – 13 / 70

    Use imports instead of require_once calls in your code!
  20. Importing ZF1 Classes Introducting ZF2 14 – 14 / 70

    § use Zend_Controller_Action as Controller; class FooController extends Controller {} // Later, this might become: use Zend\Controller\Action as Controller; class FooController extends Controller {}
  21. Interfaces Introducting ZF2 15 – 15 / 70 The Problem

    What is the extension API for component “x”?
  22. Interfaces Introducting ZF2 15 – 15 / 70 The Problem

    What is the extension API for component “x”? Burgeoning feature requests == Maintenance nightmare
  23. Interfaces Introducting ZF2 15 – 15 / 70 The Problem

    What is the extension API for component “x”? Burgeoning feature requests == Maintenance nightmare The Solution Use PHP interfaces to mark the public API.
  24. Interfaces Introducting ZF2 15 – 15 / 70 The Problem

    What is the extension API for component “x”? Burgeoning feature requests == Maintenance nightmare The Solution Use PHP interfaces to mark the public API. Limit the features in the core framework, and point developers to interfaces for custom features.
  25. Interface Examples Introducting ZF2 16 – 16 / 70 §

    interface MailMessage { public function setTo($to); public function setSubject($subject); public function setHeaders(MailHeaders $headers); public function setBody($body); public function getTo(); public function getSubject(); public function getHeaders(); public function getBody(); }
  26. Exceptions Introducting ZF2 17 – 17 / 70 The Problem

    All exceptions derived from a common class
  27. Exceptions Introducting ZF2 17 – 17 / 70 The Problem

    All exceptions derived from a common class Inability to extend semantic exception types offered in the SPL
  28. Exceptions Introducting ZF2 17 – 17 / 70 The Problem

    All exceptions derived from a common class Inability to extend semantic exception types offered in the SPL The Solution Eliminate Zend_Exception
  29. Exceptions Introducting ZF2 17 – 17 / 70 The Problem

    All exceptions derived from a common class Inability to extend semantic exception types offered in the SPL The Solution Eliminate Zend_Exception Each component defines a marker Exception interface
  30. Exceptions Introducting ZF2 17 – 17 / 70 The Problem

    All exceptions derived from a common class Inability to extend semantic exception types offered in the SPL The Solution Eliminate Zend_Exception Each component defines a marker Exception interface Concrete exceptions live in an Exception subnamespace, and extend SPL exceptions
  31. Exception Definitions Introducting ZF2 18 – 18 / 70 §

    namespace Zend\EventManager; interface Exception {}
  32. Exception Definitions Introducting ZF2 18 – 18 / 70 §

    namespace Zend\EventManager; interface Exception {} § namespace Zend\EventManager\Exception; use Zend\EventManager\Exception; class InvalidArgumentException extends \InvalidArgumentException implements Exception {}
  33. Catching Exceptions Introducting ZF2 19 – 19 / 70 §

    namespace Zend\EventManager\Exception; use Zend\EventManager\Exception; try { $events ->trigger(’foo.bar’, $object); } catch (InvalidArgumentException $e) { } catch (Exception $e) { } catch (\InvalidArgumentException $e) { } catch (\Exception $e) { }
  34. Autoloading Introducting ZF2 20 – 20 / 70 The Problem

    Performance issues, mainly due to filesystem lookups
  35. Autoloading Introducting ZF2 20 – 20 / 70 The Problem

    Performance issues, mainly due to filesystem lookups Problems with error handling when lookups fail or require_once calls are missing
  36. Autoloading Introducting ZF2 21 – 21 / 70 The Solution

    No more require_once calls! Provide fallback autoloading for rapid application development
  37. Autoloading Introducting ZF2 21 – 21 / 70 The Solution

    No more require_once calls! Provide fallback autoloading for rapid application development Map namespaces to specific directories to increase performance
  38. Autoloading Introducting ZF2 21 – 21 / 70 The Solution

    No more require_once calls! Provide fallback autoloading for rapid application development Map namespaces to specific directories to increase performance Use class maps when possible
  39. Autoloading Introducting ZF2 21 – 21 / 70 The Solution

    No more require_once calls! Provide fallback autoloading for rapid application development Map namespaces to specific directories to increase performance Use class maps when possible Provide tools for generating class maps
  40. ZF1-Style Autoloading Introducting ZF2 22 – 22 / 70 §

    require_once ’Zend/Loader/StandardAutoloader.php’; $loader = new Zend\Loader\StandardAutoloader(array( ’fallback_autoloader ’ => true, )); $loader ->register();
  41. ZF2 NS/Prefix Autoloading Introducting ZF2 23 – 23 / 70

    § require_once ’Zend/Loader/StandardAutoloader.php’; $loader = new Zend\Loader\StandardAutoloader(); $loader ->registerNamespace(’My’, __DIR__ . ’/../library/My’) ->registerPrefix(’Phly_’, __DIR__ . ’/../library/Phly’); $loader ->register();
  42. Class-Map Autoloading Introducting ZF2 24 – 24 / 70 §

    return array( ’My\Foo\Bar’ => __DIR__ . ’/Foo/Bar.php’, );
  43. Class-Map Autoloading Introducting ZF2 24 – 24 / 70 §

    return array( ’My\Foo\Bar’ => __DIR__ . ’/Foo/Bar.php’, ); § require_once ’Zend/Loader/ClassMapAutoloader.php’; $loader = new Zend\Loader\ClassMapAutoloader(); $loader ->registerAutoloadMap(__DIR__ . ’/../ library/.classmap.php’); $loader ->register();
  44. Class-Maps? Won’t those require work? Introducting ZF2 25 – 25

    / 70 Yes, they will. But we already have a tool, bin/classmap_generator.php.
  45. Class-Maps? Won’t those require work? Introducting ZF2 25 – 25

    / 70 Yes, they will. But we already have a tool, bin/classmap_generator.php. Usage is trivial: § prompt > cd your/library prompt > php /path/to/classmap_generator.php -w # Class-Map now exists in .classmap.php
  46. Autoloader Factory Introducting ZF2 26 – 26 / 70 With

    multiple strategies comes the need for a factory
  47. Autoloader Factory Introducting ZF2 26 – 26 / 70 With

    multiple strategies comes the need for a factory Choose several strategies
  48. Autoloader Factory Introducting ZF2 26 – 26 / 70 With

    multiple strategies comes the need for a factory Choose several strategies Class-Map for fastest lookup
  49. Autoloader Factory Introducting ZF2 26 – 26 / 70 With

    multiple strategies comes the need for a factory Choose several strategies Class-Map for fastest lookup Namespace/prefix paths for common code
  50. Autoloader Factory Introducting ZF2 26 – 26 / 70 With

    multiple strategies comes the need for a factory Choose several strategies Class-Map for fastest lookup Namespace/prefix paths for common code ZF1/PSR0-style fallback autoloader for development
  51. Autoloader Factory Example Introducting ZF2 27 – 27 / 70

    § require_once ’Zend/Loader/AutoloaderFactory.php’; use Zend\Loader\AutoloaderFactory; AutoloaderFactory::factory(array( ’Zend\Loader\ClassMapAutoloader’ => array( __DIR__ . ’/../ library/.classmap.php’, __DIR__ . ’/../ application/.classmap.php’, ), ’Zend\Loader\StandardAutoloader’ => array( ’namespaces’ => array( ’Zend’ => __DIR__ . ’/../ library/Zend’, ), ’fallback_autoloader ’ => true, ), ));
  52. Start Migrating Introducting ZF2 28 – 28 / 70 You

    can use the ZF2 autoloaders and class-map generation facilities today; start migrating now!
  53. Plugin Loading Introducting ZF2 29 – 29 / 70 Terminology

    For our purposes, a “plugin” is any class that is determined at runtime.
  54. Plugin Loading Introducting ZF2 29 – 29 / 70 Terminology

    For our purposes, a “plugin” is any class that is determined at runtime. Action and view helpers Adapters Filters and validators
  55. Plugin Loading Introducting ZF2 30 – 30 / 70 The

    Problem Varying approaches to dynamically discovering plugin classes
  56. Plugin Loading Introducting ZF2 30 – 30 / 70 The

    Problem Varying approaches to dynamically discovering plugin classes Paths relative to the calling class Prefix-path stacks (most common) Setters to indicate classes
  57. Plugin Loading Introducting ZF2 30 – 30 / 70 The

    Problem Varying approaches to dynamically discovering plugin classes Paths relative to the calling class Prefix-path stacks (most common) Setters to indicate classes Most common approach is terrible
  58. Plugin Loading Introducting ZF2 30 – 30 / 70 The

    Problem Varying approaches to dynamically discovering plugin classes Paths relative to the calling class Prefix-path stacks (most common) Setters to indicate classes Most common approach is terrible Bad performance Hard to debug No caching of discovered plugins
  59. Plugin Loading Introducting ZF2 31 – 31 / 70 The

    Solution Separate Plugin Location interface Allows varying implementation of plugin lookup
  60. Plugin Loading Introducting ZF2 31 – 31 / 70 The

    Solution Separate Plugin Location interface Allows varying implementation of plugin lookup Separate Plugin Broker interface Composes a Plugin Locator
  61. Plugin Locator Implementation Introducting ZF2 32 – 32 / 70

    § namespace Zend\View; use Zend\Loader\PluginClassLoader; class HelperLoader extends PluginClassLoader { /** * @var array Pre-aliased view helpers */ protected $plugins = array( ’action’ => ’Zend\View\Helper\Action’, ’base_url’ => ’Zend\View\Helper\BaseUrl’, /* ... */ ); }
  62. Plugin broker implementation Introducting ZF2 33 – 33 / 70

    § class HelperBroker extends PluginBroker protected $defaultClassLoader = ’Zend\View\HelperLoader’; public function load($plugin , array $options = null) { $helper = parent::load($plugin , $options); if (null !== ($view = $this ->getView())) { $helper ->setView($view); } return $helper; } protected function validatePlugin($plugin) { if (! $plugin instanceof Helper) { throw new InvalidHelperException (); } return true; } }
  63. Composing a broker Introducting ZF2 34 – 34 / 70

    § use Zend\View\HelperLoader; class Foo { protected $broker; public function broker($spec = null , array $options = array()) { if ($spec instanceof Broker) { $this ->broker = $spec; return $spec; } elseif (null === $this ->broker) { $this ->broker = new PluginBroker(); } if (null === $spec) { return $this ->broker; } elseif (!is_string($spec)) { throw new \Exception(); } return $this ->broker ->load($spec , $options); } }
  64. The Problem Introducting ZF2 37 – 37 / 70 How

    do we introduce logging/debug points in framework code?
  65. The Problem Introducting ZF2 37 – 37 / 70 How

    do we introduce logging/debug points in framework code? How do we allow users to introduce caching without needing to extend framework code?
  66. The Problem Introducting ZF2 37 – 37 / 70 How

    do we introduce logging/debug points in framework code? How do we allow users to introduce caching without needing to extend framework code? How do we allow users to introduce validation, filtering, ACL checks, etc., without needing to extend framework code?
  67. The Problem Introducting ZF2 37 – 37 / 70 How

    do we introduce logging/debug points in framework code? How do we allow users to introduce caching without needing to extend framework code? How do we allow users to introduce validation, filtering, ACL checks, etc., without needing to extend framework code? How do we allow users to manipulate the order in which plugins, intercepting filters, events, etc., trigger?
  68. The Problem Introducting ZF2 37 – 37 / 70 How

    do we introduce logging/debug points in framework code? How do we allow users to introduce caching without needing to extend framework code? How do we allow users to introduce validation, filtering, ACL checks, etc., without needing to extend framework code? How do we allow users to manipulate the order in which plugins, intercepting filters, events, etc., trigger? How can we provide tools for userland code to benefit from the above?
  69. The Solution Introducting ZF2 38 – 38 / 70 Aspect

    Oriented Programming Code defines various “aspects” that may be interesting to observe and/or attach to from a consumer.
  70. The Solution Introducting ZF2 38 – 38 / 70 Aspect

    Oriented Programming Code defines various “aspects” that may be interesting to observe and/or attach to from a consumer. Other code executes when the aspect is triggered.
  71. Many Approaches Introducting ZF2 39 – 39 / 70 Subject-Observer

    Intercepting Filters SignalSlots PubSub and Events
  72. ZF2 Introducting ZF2 40 – 40 / 70 Introducing the

    EventManager Cherry-picks from each of PubSub, SignalSlot, and Intercepting Filters to provide a comprehensive solution.
  73. ZF2 Introducting ZF2 40 – 40 / 70 Introducing the

    EventManager Cherry-picks from each of PubSub, SignalSlot, and Intercepting Filters to provide a comprehensive solution. Prioritization of handlers
  74. ZF2 Introducting ZF2 40 – 40 / 70 Introducing the

    EventManager Cherry-picks from each of PubSub, SignalSlot, and Intercepting Filters to provide a comprehensive solution. Prioritization of handlers Interrupting event propagation
  75. ZF2 Introducting ZF2 40 – 40 / 70 Introducing the

    EventManager Cherry-picks from each of PubSub, SignalSlot, and Intercepting Filters to provide a comprehensive solution. Prioritization of handlers Interrupting event propagation Aggregation and introspection of handler results
  76. ZF2 Introducting ZF2 40 – 40 / 70 Introducing the

    EventManager Cherry-picks from each of PubSub, SignalSlot, and Intercepting Filters to provide a comprehensive solution. Prioritization of handlers Interrupting event propagation Aggregation and introspection of handler results Static connection using named managers
  77. EventCollection Interface Introducting ZF2 41 – 41 / 70 §

    namespace Zend\EventManager; use Zend\Stdlib\CallbackHandler; interface EventCollection { public function trigger($event , $context , $argv = array()); public function triggerUntil($event , $context , $argv , $callback); public function attach($event , $callback , $priority = 1); public function detach(CallbackHandler $handle); public function getEvents(); public function getHandlers($event); public function clearHandlers($event); }
  78. Triggering Events Introducting ZF2 42 – 42 / 70 §

    use Zend\EventManager\EventManager; $events = new EventManager(); $events ->trigger($eventName , $object , $params); /* Where: * - $eventName is the name of the event; usually the current * method name * - $object is the object triggering the event * - $params are the parameters the handler might need to access, * usually the method arguments */
  79. CallbackHandler Introducting ZF2 43 – 43 / 70 § $handler

    = $events ->attach(’some -event’, function($e) use ($log) { $event = $e->getName(); $context = get_class($e->getTarget()); $params = json_encode($e->getParams()); $log ->info(sprintf("%s: %s: %s", $event , $context , $params)); });
  80. Composing an EventManager Introducting ZF2 44 – 44 / 70

    § use Zend\EventManager\EventCollection as Events , Zend\EventManager\EventManager; class Foo { protected $events; public function events(Events $events = null) { if (null !== $events) { $this ->events = $events; } elseif (null === $this ->events) { $this ->events = new EventManager(__CLASS__); } return $this ->events; } public function doSomething($param1 , $param2) { $params = compact(’param1’, ’param2’); $this ->events()->trigger(__FUNCTION__ , $this , $params); } }
  81. Using a Trait! Introducting ZF2 45 – 45 / 70

    § use Zend\EventManager\EventCollection as Events , Zend\EventManager\EventManager; trait Eventful { public function events(Events $events = null) { if (null !== $events) { $this ->events = $events; } elseif (null === $this ->events) { $this ->events = new EventManager(__CLASS__); } return $this ->events; } } class Foo { use Eventful; protected $events; }
  82. The Problem Introducting ZF2 47 – 47 / 70 How

    do we lazily manage dependencies for specific request executions?
  83. What is Dependency Injection? Introducting ZF2 49 – 49 /

    70 Quite simply: defining ways to pass dependencies into an object.
  84. What is Dependency Injection? Introducting ZF2 49 – 49 /

    70 Quite simply: defining ways to pass dependencies into an object. § $request = new Request(); $router = new Router($config); $helper = new UrlHelper($request); // constructor injection! $helper ->setRouter($router); // setter injection!
  85. Dependency Injection Container Introducting ZF2 50 – 50 / 70

    An object graph for mapping dependency relations between objects.
  86. Object with Dependencies Introducting ZF2 51 – 51 / 70

    § namespace My\Helper; class Url { public function __construct(Request $request) { $this ->request = $request; } public function setRouter(Router $router) { $this ->router = $router; } }
  87. Another Object with Dependencies Introducting ZF2 52 – 52 /

    70 § namespace mwop\Mvc; class Router { public function addRoute(Route $route) { $this ->routes ->push($route); } }
  88. Grabbing an object and using it Introducting ZF2 53 –

    53 / 70 § $urlHelper = $di ->get(’url -helper’); echo $url ->generate(’/css/site.css’); echo $url ->generate(array(’id’ => $id), array(’name’ => ’blog’));
  89. What are the use cases in ZF2? Introducting ZF2 54

    – 54 / 70 One big one. Pulling MVC controllers from the container
  90. An Action Controller Introducting ZF2 55 – 55 / 70

    § namespace Blog\Controller; class Entry implements Dispatchable { public function setResource(Resource $resource) { $this ->resource = $resource; } public function dispatch(Request $request , Response $response = null) { /* ... */ $entry = $this ->resource ->get($id); /* ... */ } }
  91. The Front Controller Introducting ZF2 56 – 56 / 70

    § class FrontController implements Dispatchable { public function __construct(DependencyInjection $di) { $this ->di = $di; } public function dispatch(Request $request , Response $response = null) { /* ... */ $controller = $this ->di->get($controllerName); $result = $controller ->dispatch($request , $response); /* ... */ } }
  92. Benefits to using DI this way Introducting ZF2 57 –

    57 / 70 Performance Code de-coupling
  93. Benefits to using DI this way Introducting ZF2 57 –

    57 / 70 Performance Code de-coupling Simplification of controller code
  94. The Problems Introducting ZF2 60 – 60 / 70 How

    do controllers get dependencies?
  95. The Problems Introducting ZF2 60 – 60 / 70 How

    do controllers get dependencies? How do we accommodate different controller patterns? What if we want to fine-tune action selection after routing, based on other data in the request environment?
  96. The Problems Introducting ZF2 60 – 60 / 70 How

    do controllers get dependencies? How do we accommodate different controller patterns? What if we want to fine-tune action selection after routing, based on other data in the request environment? What if we want to pass arguments to action names, or prevalidate arguments?
  97. The Problems Introducting ZF2 60 – 60 / 70 How

    do controllers get dependencies? How do we accommodate different controller patterns? What if we want to fine-tune action selection after routing, based on other data in the request environment? What if we want to pass arguments to action names, or prevalidate arguments? What if we don’t like the “Action” suffix in action methods?
  98. The Problems Introducting ZF2 60 – 60 / 70 How

    do controllers get dependencies? How do we accommodate different controller patterns? What if we want to fine-tune action selection after routing, based on other data in the request environment? What if we want to pass arguments to action names, or prevalidate arguments? What if we don’t like the “Action” suffix in action methods? What if . . . ?
  99. The Problems Introducting ZF2 60 – 60 / 70 How

    do controllers get dependencies? How do we accommodate different controller patterns? What if we want to fine-tune action selection after routing, based on other data in the request environment? What if we want to pass arguments to action names, or prevalidate arguments? What if we don’t like the “Action” suffix in action methods? What if . . . ? How can we better use server components within the MVC?
  100. The Problems Introducting ZF2 60 – 60 / 70 How

    do controllers get dependencies? How do we accommodate different controller patterns? What if we want to fine-tune action selection after routing, based on other data in the request environment? What if we want to pass arguments to action names, or prevalidate arguments? What if we don’t like the “Action” suffix in action methods? What if . . . ? How can we better use server components within the MVC? How can we make the MVC more performant?
  101. Introducting ZF2 61 – 61 / 70 The basic structure

    of a web application is that of a Request/Response lifecycle
  102. The Dispatchable Interface Introducting ZF2 62 – 62 / 70

    § namespace Zend\Stdlib; interface Dispatchable { public function dispatch( Request $request , Response $response = null ); }
  103. Anything dispatchable can attach to the MVC Introducting ZF2 63

    – 63 / 70 Dispatchable is simply a formalization of the Command pattern
  104. Anything dispatchable can attach to the MVC Introducting ZF2 63

    – 63 / 70 Dispatchable is simply a formalization of the Command pattern Controllers
  105. Anything dispatchable can attach to the MVC Introducting ZF2 63

    – 63 / 70 Dispatchable is simply a formalization of the Command pattern Controllers Servers
  106. Anything dispatchable can attach to the MVC Introducting ZF2 63

    – 63 / 70 Dispatchable is simply a formalization of the Command pattern Controllers Servers Whatever you may dream of! Just implement Dispatchable!
  107. Simple Front Controller Prototype Introducting ZF2 65 – 65 /

    70 § function dispatch(Request $request , Response $response = null) { $routing = $this ->getRouter()->route($request); if (!$routing) { $routing = array(’controller’ => ’page’, ’page’ => 404); } $controller = $this ->di->get($routing[’controller’]); if (!$controller instanceof Dispatchable) { $controller = new NotFoundController(); } $params = compact(’request’, ’response’, ’routing’); $this ->events()->trigger(__FUNCTION__ . ’.pre’, $params); $result = $controller ->dispatch($request , $response); $params[’__RESULT__’] = $result; $this ->events()->trigger(__FUNCTION__ . ’.post’, $params); return $response; }
  108. Contribute to ZF2! Introducting ZF2 67 – 67 / 70

    ZF2 wiki: http://bit.ly/zf2wiki zf-contributors mailing list: [email protected] IRC: #zftalk.dev on Freenode
  109. ZF2 Git Repository Introducting ZF2 68 – 68 / 70

    Git guide: http://bit.ly/zf2gitguide GitHub: http://github.com/zendframework/zf2 Official repo: git://git.zendframework.com/zf.git http://git.zendframework.com/ You still need to sign a CLA!
  110. References Introducting ZF2 69 – 69 / 70 ZF2 Dependency

    Injection Proposal http://bit.ly/zf2diproposal http://bit.ly/zf2diprototype ZF2 DI/MVC prototype sandbox http://bit.ly/zf2mvcproto1 ZF2 MVC Requirements Gathering http://bit.ly/zf2mvcreqs
  111. Thank You! Introducting ZF2 70 – 70 / 70 Zend

    Framework: http://framework.zend.com/ Feedback: http://joind.in/3407 My Twitter: http://twitter.com/weierophinney My Blog: http://weierophinney.net/matthew