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

ZF2 For User Groups (Draft)

ZF2 For User Groups (Draft)

Ralph Schindler

January 16, 2013
Tweet

More Decks by Ralph Schindler

Other Decks in Technology

Transcript

  1. 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
  2. Outline of Talk •ZF2 Intro •ZF2 Application Quickstart •MVC Application

    Core Concepts •Modules / Exploring / Development 3 Tuesday, January 15, 13
  3. 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
  4. Quickstart •Get ZF2 Application Skeleton: download the zip [or] use

    composer’s create-skeleton 6 Tuesday, January 15, 13
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. •Stop propagation from inside a listener, or based on the

    result of a listener •Aggregate and introspect listener results 19 Tuesday, January 15, 13
  11. Services •Objects you work with (including Controllers!) •Substitutable, replaceable •Define

    how you want them built •Inversion of Control 21 Tuesday, January 15, 13
  12. 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
  13. Examples notes •Can be done programmatically •Or in Zend\Mvc Application:

    via configuration •(both shown) 23 Tuesday, January 15, 13
  14. 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
  15. Services Are Configurable •Application configuration •Module classes (we'll get to

    that...) •Module configuration •"Global" and "Local" override configuration 31 Tuesday, January 15, 13
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. 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
  23. 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
  24. Build your own •Module Skeleton available for download tarball •Via

    composer •https://github.com/zendframework/ ZendSkeletonModule 50 Tuesday, January 15, 13
  25. 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
  26. 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
  27. 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
  28. 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