Slide 1

Slide 1 text

ZF2 For User Groups by Ralph Schindler Tuesday, January 15, 13

Slide 2

Slide 2 text

Who Am I? •Ralph Schindler (ralphschindler) Software Engineer on the Zend Framework team •At Zend for 5 years •Before that TippingPoint/3Com Programming PHP for 13+ years Live in New Orleans, LA. •Lived in Austin, Tx for 5 years 2 Tuesday, January 15, 13

Slide 3

Slide 3 text

Outline of Talk •ZF2 Intro •ZF2 Application Quickstart •MVC Application Core Concepts •Modules / Exploring / Development 3 Tuesday, January 15, 13

Slide 4

Slide 4 text

ZF 2.0 •Next generation of Zend Framework •Embrace 5.3 (and 5.4 in some places) •Embrace multiple programming paradigms AOP Event driven programming •More SOLID http://en.wikipedia.org/wiki/SOLID_(object-oriented_design) More interfaces, more possibility for extension Practice dependency injection •More Agile and open! No more CLA Code on github.com 4 Tuesday, January 15, 13

Slide 5

Slide 5 text

Insert->Header & Footer ZF2 Application Quickstart 5 Tuesday, January 15, 13

Slide 6

Slide 6 text

Quickstart •Get ZF2 Application Skeleton: download the zip [or] use composer’s create-skeleton 6 Tuesday, January 15, 13

Slide 7

Slide 7 text

Composer Skeleton •Download composer •Run command to create skeleton •Setup Apache [or] PHP 5.4 built-in web server •Start coding 7 Tuesday, January 15, 13

Slide 8

Slide 8 text

Insert->Header & Footer Tutorial / Demo 8 Tuesday, January 15, 13

Slide 9

Slide 9 text

Insert->Header & Footer Core Concepts 9 Tuesday, January 15, 13

Slide 10

Slide 10 text

Why Core Concepts •“How does my action controller get dispatched?” •“How do I create re-usable compoents/modules for my team/public consumption?” •“I’m just generally curious about the architecture.” 10 Tuesday, January 15, 13

Slide 11

Slide 11 text

3 Central Components •Zend\Mvc composes: Zend\EventManager to build a workflow based on an event model Zend\ServiceManager for members in this workflow to consume and provide instances of objects Zend\ModuleManager to encapsulate members together 11 Tuesday, January 15, 13

Slide 12

Slide 12 text

Insert->Header & Footer Zend\EventManager 12 Tuesday, January 15, 13

Slide 13

Slide 13 text

Events •Some objects trigger an events •Some objects listen for events 13 Tuesday, January 15, 13

Slide 14

Slide 14 text

Terminology •An Event is both an action and a value object. •A Listener is a callback that accepts an Event and acts on it. •An Event Manager is an object that aggregates listeners for named events, and which triggers events. 14 Tuesday, January 15, 13

Slide 15

Slide 15 text

Example: Listener 15 Tuesday, January 15, 13

Slide 16

Slide 16 text

Example: Triggering 16 Tuesday, January 15, 13

Slide 17

Slide 17 text

Example: Implication 17 Tuesday, January 15, 13

Slide 18

Slide 18 text

Other Features •Shared listeners attach listeners even when you don't have the target instance •Priority specify the order in which listeners are triggered 18 Tuesday, January 15, 13

Slide 19

Slide 19 text

•Stop propagation from inside a listener, or based on the result of a listener •Aggregate and introspect listener results 19 Tuesday, January 15, 13

Slide 20

Slide 20 text

Insert->Header & Footer Zend\ServiceManager 20 Tuesday, January 15, 13

Slide 21

Slide 21 text

Services •Objects you work with (including Controllers!) •Substitutable, replaceable •Define how you want them built •Inversion of Control 21 Tuesday, January 15, 13

Slide 22

Slide 22 text

Types •Instances (services) •Constructor-less classes (invokables) •Factories when objects have dependencies (factories) •Factories for multiple related objects (abstract_factories) •Aliased services (aliases) •Automated initialization (initializers) 22 Tuesday, January 15, 13

Slide 23

Slide 23 text

Examples notes •Can be done programmatically •Or in Zend\Mvc Application: via configuration •(both shown) 23 Tuesday, January 15, 13

Slide 24

Slide 24 text

Instances 24 Tuesday, January 15, 13

Slide 25

Slide 25 text

Invokables 25 Tuesday, January 15, 13

Slide 26

Slide 26 text

Factories 26 Tuesday, January 15, 13

Slide 27

Slide 27 text

Abstract Factories 27 Tuesday, January 15, 13

Slide 28

Slide 28 text

Aliases 28 Tuesday, January 15, 13

Slide 29

Slide 29 text

Initializers 29 Tuesday, January 15, 13

Slide 30

Slide 30 text

ZF2 MVC Implications / Other Features •All plugin managers are service managers! You can now inject dependencies into helpers, plugins, etc! •Services are shared by default; you can disable this selectively •Manager "peering" is available 30 Tuesday, January 15, 13

Slide 31

Slide 31 text

Services Are Configurable •Application configuration •Module classes (we'll get to that...) •Module configuration •"Global" and "Local" override configuration 31 Tuesday, January 15, 13

Slide 32

Slide 32 text

Insert->Header & Footer Modules & Zend\ModuleManager 32 Tuesday, January 15, 13

Slide 33

Slide 33 text

What is a Module? •A named encapsulation of “stuff” •Provide the MVC with: Autoloading Configuration Services (including controllers, plugins, etc.) Event listeners / event wiring •Are reusable 33 Tuesday, January 15, 13

Slide 34

Slide 34 text

“stuff” •At least a namespaced “Module.php” •... anything: file assets classes mvc members 34 Tuesday, January 15, 13

Slide 35

Slide 35 text

Zend\ModuleManager •Loops through modules •Consumes the EventManager to: Triggers an event for each module allowing listeners to act on Module classes 35 Tuesday, January 15, 13

Slide 36

Slide 36 text

ModuleManager Events •loadModules: the loop in which modules are loaded •loadModule: triggered once we have a Module class instance •loadModules.post: to allow listeners to act on aggregated information from all Modules 36 Tuesday, January 15, 13

Slide 37

Slide 37 text

ModuleManager Built-in Listeners •AutoloaderListener •ConfigListener: aggregate config from all modules •ServiceListener: aggregate `ServiceManager` (and plugin manager) !configurations from Module classes and/or module configuration •OnBootstrapListener: register a Module as a "bootstrap" event listener !more ... including any you want to write 37 Tuesday, January 15, 13

Slide 38

Slide 38 text

Simple Example 38 Tuesday, January 15, 13

Slide 39

Slide 39 text

Insert->Header & Footer Zend\Mvc 39 Tuesday, January 15, 13

Slide 40

Slide 40 text

Zend\Mvc •Composes EventManager so that Everything is an Event 40 Tuesday, January 15, 13

Slide 41

Slide 41 text

Everything Is An Event 41 Tuesday, January 15, 13

Slide 42

Slide 42 text

The MVC Events •bootstrap •route •dispatch and dispatch.error •render (and, in 2.1, render.error) •finish •(These are actual event names) 42 Tuesday, January 15, 13

Slide 43

Slide 43 text

Mvc: Routing •Routing matches the Request to a Controller (really a set of parameters that the dispatch listener will use to marshall a controller) •Route definitions are a tree structure (i.e., routes can have child routes!) Zend\Mvc\Router implementation •(See Ben Scholzens Zendcon Router Slides) 43 Tuesday, January 15, 13

Slide 44

Slide 44 text

Mvc: Routing •Literal: /foo •Segment: /literal/:id[/:optional] •Regex:/literal(?P[a-f0-9]{8}) •Scheme •Method •Wildcard 44 Tuesday, January 15, 13

Slide 45

Slide 45 text

Mvc: Controllers •Controllers are Services •Controllers must implement Zend\Stdlib \DispatchableInterface more useful to extend a base controller: •AbstractController •AbstractActionController •AbstractRestfulController 45 Tuesday, January 15, 13

Slide 46

Slide 46 text

46 Tuesday, January 15, 13

Slide 47

Slide 47 text

Everything is a Module 47 Tuesday, January 15, 13

Slide 48

Slide 48 text

Philosophy •Models are still up to you to decide how to implement •More functionality can be found in 3rd party modules ... •so ......... 48 Tuesday, January 15, 13

Slide 49

Slide 49 text

Insert->Header & Footer Back to Modules 49 Tuesday, January 15, 13

Slide 50

Slide 50 text

Build your own •Module Skeleton available for download tarball •Via composer •https://github.com/zendframework/ ZendSkeletonModule 50 Tuesday, January 15, 13

Slide 51

Slide 51 text

Or, 3rd Party Modules •“Theres a module for that” •http://modules.zendframework.com/ ZfcUser (ZF Commons) PhlyRestfully (Matthews Rest module) DoctrineModule ScnSocialAuth •Download or use composer to put in vendor/ 51 Tuesday, January 15, 13

Slide 52

Slide 52 text

Enabling them 52 Tuesday, January 15, 13

Slide 53

Slide 53 text

Insert->Header & Footer Exploring / Development / Misc. 53 Tuesday, January 15, 13

Slide 54

Slide 54 text

Explore via Debugging •Places for breakpoints: Inside Zend\Mvc\Route::onRoute() Inside Zend\Mvc\DispatchListener::onDispatch() Inside Zend\Mvc\Controller \AbstactActionController::onDispatch() Various: Zend\Mvc\View\Http\* 54 Tuesday, January 15, 13

Slide 55

Slide 55 text

Want ZF2 As a Microframework? •https://github.com/weierophinney/phlyty 55 Tuesday, January 15, 13

Slide 56

Slide 56 text

Other components? •Zend\Db re-written •Service components moved out to own namespace / repository •Full auto-wiring / auto-instantiation in Zend\DI •Zend\Form re-architected ground up •Zend\Http re-architected ground up 56 Tuesday, January 15, 13

Slide 57

Slide 57 text

Per-component Packages •http://packages.zendframework.com/ •http://framework.zend.com/downloads Composer Pyrus Git submodules Tarball/zipball 57 Tuesday, January 15, 13

Slide 58

Slide 58 text

Contributing •http://framework.zend.com/participate •https://github.com/zendframework/zf2 Create issue reports Submit patches (pull requests) Review others patches Write tests •- Write documentation 58 Tuesday, January 15, 13

Slide 59

Slide 59 text

Participate •IRC General help: #zftalk Framework development: #zftalk.dev •Mailing lists http://framework.zend.com/archives •GitHub Issues / Pull Requests 59 Tuesday, January 15, 13

Slide 60

Slide 60 text

Insert->Header & Footer Thank You! Q / A? 60 Tuesday, January 15, 13