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

zf2-for-common

Ralph Schindler
April 10, 2013
150

 zf2-for-common

Ralph Schindler

April 10, 2013
Tweet

Transcript

  1. ZF2 For COMMON
    by Ralph Schindler
    Wednesday, April 10, 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
    Wednesday, April 10, 13

    View Slide

  3. Before we get started
    •Slides:
    https://speakerdeck.com/ralphschindler/zf2-for-common
    3
    Wednesday, April 10, 13

    View Slide

  4. Outline of Talk
    •ZF2 Intro
    •ZF2 Application Quickstart
    •MVC Application Core Concepts
    •Zend\Db Connectivity
    •Modules / Exploring / Development
    4
    Wednesday, April 10, 13

    View Slide

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

    View Slide

  6. Insert->Header & Footer
    ZF2 Application Quickstart
    6
    Wednesday, April 10, 13

    View Slide

  7. Quickstart
    •Get ZF2 Application Skeleton:
    download the zip
    [or] use composer’s create-skeleton
    7
    Wednesday, April 10, 13

    View Slide

  8. Skeleton
    •Download skeleton
    https://github.com/zendframework/ZendSkeletonApplication
    •Copy files to project on i
    •Start coding!
    8
    Wednesday, April 10, 13

    View Slide

  9. Insert->Header & Footer
    Tutorial / Demo
    9
    Wednesday, April 10, 13

    View Slide

  10. Insert->Header & Footer
    Core Concepts
    10
    Wednesday, April 10, 13

    View Slide

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

    View Slide

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

    View Slide

  13. Insert->Header & Footer
    Zend\EventManager
    13
    Wednesday, April 10, 13

    View Slide

  14. Events
    •Some objects trigger an events
    •Some objects listen for events
    14
    Wednesday, April 10, 13

    View Slide

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

    View Slide

  16. Example: Listener
    16
    Wednesday, April 10, 13

    View Slide

  17. Example: Triggering
    17
    Wednesday, April 10, 13

    View Slide

  18. Example: Implication
    18
    Wednesday, April 10, 13

    View Slide

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

    View Slide

  20. •Stop propagation
    from inside a listener, or based on the result of a
    listener
    •Aggregate and introspect listener results
    20
    Wednesday, April 10, 13

    View Slide

  21. Insert->Header & Footer
    Zend\ServiceManager
    21
    Wednesday, April 10, 13

    View Slide

  22. Services
    •Objects you work with (including Controllers!)
    •Substitutable, replaceable
    •Define how you want them built
    •Inversion of Control
    22
    Wednesday, April 10, 13

    View Slide

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

    View Slide

  24. Examples notes
    •Can be done programmatically
    •Or in Zend\Mvc Application: via configuration
    •(both shown)
    24
    Wednesday, April 10, 13

    View Slide

  25. Instances
    25
    Wednesday, April 10, 13

    View Slide

  26. Invokables
    26
    Wednesday, April 10, 13

    View Slide

  27. Factories
    27
    Wednesday, April 10, 13

    View Slide

  28. Abstract Factories
    28
    Wednesday, April 10, 13

    View Slide

  29. Aliases
    29
    Wednesday, April 10, 13

    View Slide

  30. Initializers
    30
    Wednesday, April 10, 13

    View Slide

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

    View Slide

  32. Services Are Configurable
    •Application configuration
    •Module classes (we'll get to that...)
    •Module configuration
    •"Global" and "Local" override configuration
    32
    Wednesday, April 10, 13

    View Slide

  33. Insert->Header & Footer
    Modules &
    Zend\ModuleManager
    33
    Wednesday, April 10, 13

    View Slide

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

    View Slide

  35. “stuff”
    •At least a namespaced “Module.php”
    •... anything:
    file assets
    classes
    mvc members
    35
    Wednesday, April 10, 13

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  39. Simple Example
    39
    Wednesday, April 10, 13

    View Slide

  40. Insert->Header & Footer
    Zend\Mvc
    40
    Wednesday, April 10, 13

    View Slide

  41. Zend\Mvc
    •Composes EventManager so that Everything is an
    Event
    41
    Wednesday, April 10, 13

    View Slide

  42. Everything Is An Event
    42
    Wednesday, April 10, 13

    View Slide

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

    View Slide

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

    View Slide

  45. Mvc: Routing
    •Literal: /foo
    •Segment: /literal/:id[/:optional]
    •Regex:/literal(?P[a-f0-9]{8})
    •Scheme
    •Method
    •Wildcard
    45
    Wednesday, April 10, 13

    View Slide

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

    View Slide

  47. 47
    Wednesday, April 10, 13

    View Slide

  48. Everything is a Module
    48
    Wednesday, April 10, 13

    View Slide

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

    View Slide

  50. Insert->Header & Footer
    Back to Modules
    50
    Wednesday, April 10, 13

    View Slide

  51. Build your own
    •Module Skeleton available for download tarball
    •Via composer
    •https://github.com/zendframework/
    ZendSkeletonModule
    51
    Wednesday, April 10, 13

    View Slide

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

    View Slide

  53. Enabling them
    53
    Wednesday, April 10, 13

    View Slide

  54. Insert->Header & Footer
    Exploring / Development / Misc.
    54
    Wednesday, April 10, 13

    View Slide

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

    View Slide

  56. Want ZF2 As a Microframework?
    •https://github.com/weierophinney/phlyty
    56
    Wednesday, April 10, 13

    View Slide

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

    View Slide

  58. Insert->Header & Footer
    Zend\Db (for the i)
    Just a few words & examples
    58
    Wednesday, April 10, 13

    View Slide

  59. Connecting
    59
    Wednesday, April 10, 13

    View Slide

  60. •SQL Examples
    60
    Wednesday, April 10, 13

    View Slide

  61. Insert->Header & Footer
    Wrapping up
    61
    Wednesday, April 10, 13

    View Slide

  62. Per-component Packages
    •http://packages.zendframework.com/
    •http://framework.zend.com/downloads
    Composer
    Pyrus
    Git submodules
    Tarball/zipball
    62
    Wednesday, April 10, 13

    View Slide

  63. 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
    63
    Wednesday, April 10, 13

    View Slide

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

    View Slide

  65. Insert->Header & Footer
    Thank You!
    Q / A?
    65
    Wednesday, April 10, 13

    View Slide