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

zf2-for-common

Ralph Schindler
April 10, 2013
160

 zf2-for-common

Ralph Schindler

April 10, 2013
Tweet

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 Wednesday, April 10, 13
  2. Outline of Talk •ZF2 Intro •ZF2 Application Quickstart •MVC Application

    Core Concepts •Zend\Db Connectivity •Modules / Exploring / Development 4 Wednesday, April 10, 13
  3. ZF 2.0 •Next generation of Zend Framework •Embrace 5.3 (and

    5.4 in some places, not required) •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 5 Wednesday, April 10, 13
  4. Quickstart •Get ZF2 Application Skeleton: download the zip [or] use

    composer’s create-skeleton 7 Wednesday, April 10, 13
  5. Why Core Concepts •“How does my action controller get dispatched?”

    •“How do I create re-usable components/modules for my team/public consumption?” •“I’m just generally curious about the architecture.” 11 Wednesday, April 10, 13
  6. 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 12 Wednesday, April 10, 13
  7. 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. 15 Wednesday, April 10, 13
  8. Other Features •Shared listeners attach listeners even when you don't

    have the target instance •Priority specify the order in which listeners are triggered 19 Wednesday, April 10, 13
  9. •Stop propagation from inside a listener, or based on the

    result of a listener •Aggregate and introspect listener results 20 Wednesday, April 10, 13
  10. Services •Objects you work with (including Controllers!) •Substitutable, replaceable •Define

    how you want them built •Inversion of Control 22 Wednesday, April 10, 13
  11. 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) 23 Wednesday, April 10, 13
  12. Examples notes •Can be done programmatically •Or in Zend\Mvc Application:

    via configuration •(both shown) 24 Wednesday, April 10, 13
  13. 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 31 Wednesday, April 10, 13
  14. Services Are Configurable •Application configuration •Module classes (we'll get to

    that...) •Module configuration •"Global" and "Local" override configuration 32 Wednesday, April 10, 13
  15. 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 34 Wednesday, April 10, 13
  16. Zend\ModuleManager •Loops through modules •Consumes the EventManager to: Triggers an

    event for each module allowing listeners to act on Module classes 36 Wednesday, April 10, 13
  17. 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 37 Wednesday, April 10, 13
  18. 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 38 Wednesday, April 10, 13
  19. The MVC Events •bootstrap •route •dispatch and dispatch.error •render (and,

    in 2.1, render.error) •finish •(These are actual event names) 43 Wednesday, April 10, 13
  20. 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) 44 Wednesday, April 10, 13
  21. Mvc: Controllers •Controllers are Services •Controllers must implement Zend\Stdlib \DispatchableInterface

    more useful to extend a base controller: •AbstractController •AbstractActionController •AbstractRestfulController 46 Wednesday, April 10, 13
  22. Philosophy •Models are still up to you to decide how

    to implement •More functionality can be found in 3rd party modules ... •so ......... 49 Wednesday, April 10, 13
  23. Build your own •Module Skeleton available for download tarball •Via

    composer •https://github.com/zendframework/ ZendSkeletonModule 51 Wednesday, April 10, 13
  24. 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/ 52 Wednesday, April 10, 13
  25. 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\* 55 Wednesday, April 10, 13
  26. 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 57 Wednesday, April 10, 13
  27. Insert->Header & Footer Zend\Db (for the i) Just a few

    words & examples 58 Wednesday, April 10, 13
  28. Participate •IRC General help: #zftalk Framework development: #zftalk.dev •Mailing lists

    http://framework.zend.com/archives •GitHub Issues / Pull Requests 64 Wednesday, April 10, 13