Slide 1

Slide 1 text

MVC + Event + Module: the new architecture of ZF2 Enrico Zimuel (@ezimuel) Software Engineer – Zend Framework Team

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

New Architecture

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

Example: listener

Slide 8

Slide 8 text

Example: triggering

Slide 9

Slide 9 text

Example: implications

Slide 10

Slide 10 text

MVC is driven by events

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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

Slide 13

Slide 13 text

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)

Slide 14

Slide 14 text

Module A module is all related code and assets that solve a specific problem. Modules inform the MVC about services and event listeners

Slide 15

Slide 15 text

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

Slide 16

Slide 16 text

Modules ● modules.zendframework.com (>200 modules)

Slide 17

Slide 17 text

DEMO

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

Thanks! Rate this talk at https://joind.in/8051 http://framework.zend.com