Share
Embed
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
Transcript
133 slides
-
Introducting ZF2 1 – 1 / 70 Introducing Zend Framework
2.0 Matthew Weier O’Phinney Project Lead 25 May 2011 -
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. -
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. -
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. -
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. -
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. -
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. -
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. -
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. -
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. -
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. -
Introducting ZF2 7 – 7 / 70 Zend Framework 2.0’s
focus is on improving consistency and performance. -
Namespaces Introducting ZF2 9 – 9 / 70 The Problem
Verbose class names -
Namespaces Introducting ZF2 9 – 9 / 70 The Problem
Verbose class names The Solution Use PHP namespaces -
Basics Introducting ZF2 10 – 10 / 70 Every class
file declares a namespace -
Basics Introducting ZF2 10 – 10 / 70 Every class
file declares a namespace One namespace per file -
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 -
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 -
Namespace Example Introducting ZF2 11 – 11 / 70 §
namespace Zend\EventManager; use Zend\Stdlib\CallbackHandler; class EventManager implements EventCollection { /* ... */ } -
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; } } -
Recommendation for Migration Introducting ZF2 13 – 13 / 70
Use imports instead of require_once calls in your code! -
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 {} -
Interfaces Introducting ZF2 15 – 15 / 70 The Problem
What is the extension API for component “x”? -
Interfaces Introducting ZF2 15 – 15 / 70 The Problem
What is the extension API for component “x”? Burgeoning feature requests == Maintenance nightmare -
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. -
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. -
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(); } -
Exceptions Introducting ZF2 17 – 17 / 70 The Problem
All exceptions derived from a common class -
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 -
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 -
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 -
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 -
Exception Definitions Introducting ZF2 18 – 18 / 70 §
namespace Zend\EventManager; interface Exception {} -
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 {} -
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) { } -
Autoloading Introducting ZF2 20 – 20 / 70 The Problem
Performance issues, mainly due to filesystem lookups -
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 -
Autoloading Introducting ZF2 21 – 21 / 70 The Solution
No more require_once calls! -
Autoloading Introducting ZF2 21 – 21 / 70 The Solution
No more require_once calls! Provide fallback autoloading for rapid application development -
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 -
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 -
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 -
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(); -
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(); -
Class-Map Autoloading Introducting ZF2 24 – 24 / 70 §
return array( ’My\Foo\Bar’ => __DIR__ . ’/Foo/Bar.php’, ); -
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(); -
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. -
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 -
Autoloader Factory Introducting ZF2 26 – 26 / 70 With
multiple strategies comes the need for a factory -
Autoloader Factory Introducting ZF2 26 – 26 / 70 With
multiple strategies comes the need for a factory Choose several strategies -
Autoloader Factory Introducting ZF2 26 – 26 / 70 With
multiple strategies comes the need for a factory Choose several strategies Class-Map for fastest lookup -
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 -
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 -
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, ), )); -
Start Migrating Introducting ZF2 28 – 28 / 70 You
can use the ZF2 autoloaders and class-map generation facilities today; start migrating now! -
Plugin Loading Introducting ZF2 29 – 29 / 70 Terminology
For our purposes, a “plugin” is any class that is determined at runtime. -
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 -
Plugin Loading Introducting ZF2 30 – 30 / 70 The
Problem Varying approaches to dynamically discovering plugin classes -
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 -
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 -
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 -
Plugin Loading Introducting ZF2 31 – 31 / 70 The
Solution Separate Plugin Location interface Allows varying implementation of plugin lookup -
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 -
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’, /* ... */ ); } -
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; } } -
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); } } -
The Problem Introducting ZF2 37 – 37 / 70 How
do we introduce logging/debug points in framework code? -
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? -
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? -
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? -
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? -
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. -
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. -
Many Approaches Introducting ZF2 39 – 39 / 70 Subject-Observer
Intercepting Filters -
Many Approaches Introducting ZF2 39 – 39 / 70 Subject-Observer
Intercepting Filters SignalSlots -
Many Approaches Introducting ZF2 39 – 39 / 70 Subject-Observer
Intercepting Filters SignalSlots PubSub and Events -
ZF2 Introducting ZF2 40 – 40 / 70 Introducing the
EventManager Cherry-picks from each of PubSub, SignalSlot, and Intercepting Filters to provide a comprehensive solution. -
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 -
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 -
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 -
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 -
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); } -
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 */ -
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)); }); -
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); } } -
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; } -
The Problem Introducting ZF2 47 – 47 / 70 How
do we lazily manage dependencies for specific request executions? -
The Solution Introducting ZF2 48 – 48 / 70 Dependency
Injection well, a solution... -
What is Dependency Injection? Introducting ZF2 49 – 49 /
70 Quite simply: defining ways to pass dependencies into an object. -
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! -
Dependency Injection Container Introducting ZF2 50 – 50 / 70
An object graph for mapping dependency relations between objects. -
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; } } -
Another Object with Dependencies Introducting ZF2 52 – 52 /
70 § namespace mwop\Mvc; class Router { public function addRoute(Route $route) { $this ->routes ->push($route); } } -
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’)); -
What are the use cases in ZF2? Introducting ZF2 54
– 54 / 70 One big one. -
What are the use cases in ZF2? Introducting ZF2 54
– 54 / 70 One big one. Pulling MVC controllers from the container -
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); /* ... */ } } -
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); /* ... */ } } -
Benefits to using DI this way Introducting ZF2 57 –
57 / 70 Performance -
Benefits to using DI this way Introducting ZF2 57 –
57 / 70 Performance Code de-coupling -
Benefits to using DI this way Introducting ZF2 57 –
57 / 70 Performance Code de-coupling Simplification of controller code -
The Problems Introducting ZF2 60 – 60 / 70 How
do controllers get dependencies? -
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? -
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? -
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? -
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 . . . ? -
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? -
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? -
Introducting ZF2 61 – 61 / 70 The basic structure
of a web application is that of a Request/Response lifecycle -
The Dispatchable Interface Introducting ZF2 62 – 62 / 70
§ namespace Zend\Stdlib; interface Dispatchable { public function dispatch( Request $request , Response $response = null ); } -
Anything dispatchable can attach to the MVC Introducting ZF2 63
– 63 / 70 Dispatchable is simply a formalization of the Command pattern -
Anything dispatchable can attach to the MVC Introducting ZF2 63
– 63 / 70 Dispatchable is simply a formalization of the Command pattern Controllers -
Anything dispatchable can attach to the MVC Introducting ZF2 63
– 63 / 70 Dispatchable is simply a formalization of the Command pattern Controllers Servers -
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! -
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; } -
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 -
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! -
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 -
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