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. ZF2 For User Groups
    by Ralph Schindler
    Tuesday, January 15, 13

    View Slide

  2. 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

    View Slide

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

    View Slide

  4. 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

    View Slide

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

    View Slide

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

    View Slide

  7. 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

    View Slide

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

    View Slide

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

    View Slide

  10. 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

    View Slide

  11. 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

    View Slide

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

    View Slide

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

    View Slide

  14. 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

    View Slide

  15. Example: Listener
    15
    Tuesday, January 15, 13

    View Slide

  16. Example: Triggering
    16
    Tuesday, January 15, 13

    View Slide

  17. Example: Implication
    17
    Tuesday, January 15, 13

    View Slide

  18. 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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  22. 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

    View Slide

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

    View Slide

  24. Instances
    24
    Tuesday, January 15, 13

    View Slide

  25. Invokables
    25
    Tuesday, January 15, 13

    View Slide

  26. Factories
    26
    Tuesday, January 15, 13

    View Slide

  27. Abstract Factories
    27
    Tuesday, January 15, 13

    View Slide

  28. Aliases
    28
    Tuesday, January 15, 13

    View Slide

  29. Initializers
    29
    Tuesday, January 15, 13

    View Slide

  30. 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

    View Slide

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

    View Slide

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

    View Slide

  33. 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

    View Slide

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

    View Slide

  35. 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

    View Slide

  36. 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

    View Slide

  37. 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

    View Slide

  38. Simple Example
    38
    Tuesday, January 15, 13

    View Slide

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

    View Slide

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

    View Slide

  41. Everything Is An Event
    41
    Tuesday, January 15, 13

    View Slide

  42. 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

    View Slide

  43. 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

    View Slide

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

    View Slide

  45. 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

    View Slide

  46. 46
    Tuesday, January 15, 13

    View Slide

  47. Everything is a Module
    47
    Tuesday, January 15, 13

    View Slide

  48. 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

    View Slide

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

    View Slide

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

    View Slide

  51. 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

    View Slide

  52. Enabling them
    52
    Tuesday, January 15, 13

    View Slide

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

    View Slide

  54. 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

    View Slide

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

    View Slide

  56. 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

    View Slide

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

    View Slide

  58. 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

    View Slide

  59. 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

    View Slide

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

    View Slide