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

MVC + Events + Modules: the new architecture of...

Enrico Zimuel
February 23, 2013

MVC + Events + Modules: the new architecture of ZF2

The new architecture of Zend Framework 2 is based on a new MVC design that uses events and modules. In this talk we will show how to build web applications in ZF2 using the SOLID principle (Single responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency inversion). We will show how to use Events to manage the application flow, how to organize and reuse the code using Modules and how to separate the responsibility using the new MVC design of ZF2.

Enrico Zimuel

February 23, 2013
Tweet

More Decks by Enrico Zimuel

Other Decks in Programming

Transcript

  1. MVC + Event + Module: the new architecture of ZF2

    Enrico Zimuel (@ezimuel) Software Engineer – Zend Framework Team
  2. About me • Enrico Zimuel (@ezimuel) • Software Engineer since

    1996 • PHP Engineer at Zend Technologies • Zend Framework Core Team • International speaker, author of books about secure software and web programming • Co-founder PUG Torino (Italy) http://torino.grusp.org
  3. Zend Framework 2 • Open source PHP Framework • 100%

    OOP, PHP 5.3.3+, Unit tested (PHPUnit) • New MVC architecture: Event, Service, Module • New security components (Crypt, Escaper, etc) • Packaging system (composer, pyrus) • http://framework.zend.com
  4. SOLID principle • In ZF2 we followed the SOLID principle

    – Single responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency inversion • Some design used: – Dependency Injection (Zend\Di) – Service Locator (Zend\ServiceLocator) – Modular architecture (single components) – Extensive use of Interface
  5. Events • An event is an action (and a value

    object) • An event is triggered by an EventManager • A listener is a callback that can react to an event • An EventManager is an object that holds a collection of listeners for one or more named events, and which triggers events
  6. Services • Services are the “objects” shared in a ZF2

    application (e.g. Db connection) • Can be everything: class, object, callback • Managed by a Service Locator (Zend\ServiceManager) • Replacement of the Zend\Registry in ZF1
  7. Zend\ServiceManager • The ServiceManager is a Service Locator implementation •

    A Service Locator is a well-known object in which you may register objects (more in general services) and later retrieve them • Driven by configuration
  8. Type of Services • Explicit (name => object pairs) •

    Invokables (name => class to instantiate) • Factories (name => callable returning object) • Aliases (name => some other name) • Abstract Factories (unknown services) • Scoped Containers (limit what can be created) • Shared (or not; you decide)
  9. Module A module is all related code and assets that

    solve a specific problem. Modules inform the MVC about services and event listeners
  10. Modules in ZF2 • The basic unit in a ZF2

    application is a Module • Modules are “Plug and play” technology • Modules are simple: – A namespace – Containing a single classfile: Module.php
  11. Where to start? • Getting started on framework.zend.com – http://framework.zend.com/learn

    • Free webinar about ZF2 – http://www.zend.com/en/resources/webinars/framework • Modules – http://modules.zendframework.com • ZFTool – PHAR https://packages.zendframework.com/zftool.phar – Github https://github.com/zendframework/ZFTool