SlideShare a Scribd company logo
1 of 45
Download to read offline
Zend Framework 2:
state of the art
by Enrico Zimuel (enrico@zend.com)

Senior Software Engineer
Zend Framework Core Team
Zend Technologies Ltd



                        PHPTour Lille 2011 – 25 November
                 http://afup.org/pages/phptourlille2011/
                                                           © All rights reserved. Zend Technologies, Inc.
About me

                                   • Software Engineer since 1996
                                          – Assembly x86, C/C++, Java, Perl, PHP
                                   • Enjoying PHP since 1999
                                   • PHP Engineer at Zend since 2008
                                   • ZF Core Team from April 2011
                                   • B.Sc. Computer Science and Economics
Email: enrico@zend.com
Twitter: @ezimuel                               from University of Pescara (Italy)




                         © All rights reserved. Zend Technologies, Inc.
Summary

●   Overview of ZF2
●
    Autoloading
●   Dependency Injection
●
    Event Manager
●
    The new MVC architecture
●
    Migrate from ZF1 to ZF2




                      © All rights reserved. Zend Technologies, Inc.
Overview of ZF2
●   Open source framework for PHP, evolution of ZF1
    (over 10 million downloads)
●   Still in development
       – ZF2 beta1 released in October 2011
●
    New Betas at least every six weeks (until we're done)
●   No more CLA to contribute to ZF2
●   We use github (no more SVN)




                      © All rights reserved. Zend Technologies, Inc.
A new core
●   The ZF1 way:
       ▶   Singletons, Registries, and Hard-Coded
              Dependencies
●
    The ZF2 approach:
       ▶   Aspect Oriented Design and Dependency
             Injection




                       © All rights reserved. Zend Technologies, Inc.
Architectural approach

●   Methodologies used in the development
      – Decoupling (ZendDi)
      – Event driven (ZendEventManager)
      – Standard interfaces (ZendStdlib)
●   Take advantages of PHP 5.3+




                     © All rights reserved. Zend Technologies, Inc.
Our goal for ZF2


                  Better consistency
                   and performance




             © All rights reserved. Zend Technologies, Inc.
Autoloading




  © All rights reserved. Zend Technologies, Inc.
Autoloading

●   No more require_once calls!
●
    Multiple approaches:
      – ZF1-style include_path autoloader
      – Per-namespace/prefix autoloading
      – Class-map autoloading




                    © All rights reserved. Zend Technologies, Inc.
ZF1-Style


require_once 'Zend/Loader/StandardAutoloader.php';

$loader = new ZendLoaderStandardAutoloader(array(
    'fallback_autoloader' => true,
));

$loader->register();




                       © All rights reserved. Zend Technologies, Inc.
ZF2 NS/Prefix

require_once 'Zend/Loader/StandardAutoloader.php';

$loader = new ZendLoaderStandardAutoloader();

$loader->registerNamespace(
            'My', __DIR__ . '/../library/My')
       ->registerPrefix(
            'Foo_', __DIR__ . '/../library/Foo');

$loader->register();




                       © All rights reserved. Zend Technologies, Inc.
ZF2 Class-Map

return array(
    'MyFooBar' => __DIR__ . '/Foo/Bar.php',
);
                                                                        .classmap.php


require_once 'Zend/Loader/ClassMapAutoloader.php';

$loader = new ZendLoaderClassMapAutoloader();

$loader->registerAutoloadMap(
    __DIR__ . '/../library/.classmap.php');

$loader->register();




                       © All rights reserved. Zend Technologies, Inc.
Classmap generator

●   How to generate the .classmap.php ?
     We provided a command line tool:
     bin/classmap_generator.php
●
    Usage is trivial:

    $ cd your/library
    $ php /path/to/classmap_generator.php -w


●   Class-Map will be created in .classmap.php



                        © All rights reserved. Zend Technologies, Inc.
Performance

 ●
     Class-Maps show a 25% improvement on the ZF1
       autoloader when no acceleration is present
     ▶   and 60-85% improvements when an opcode cache is
         in place!

 ●
     Pairing namespaces/prefixes with specific paths
       shows >10% gains with no acceleration
     ▶   and 40% improvements when an opcode cache is in
         place!




                       © All rights reserved. Zend Technologies, Inc.
Dependency
 Injection



  © All rights reserved. Zend Technologies, Inc.
Dependency injection
●
    How to manage dependencies between objects?
●
    Dependency injection (Di) is a design pattern whose
    purpose is to reduce the coupling between software
    components




                     © All rights reserved. Zend Technologies, Inc.
Di by construct


         Without Di                                           With Di (construct)

class Foo {                                             class Foo {
  protected $bar;                                          protected $bar;
  …                                                        …
  public function __construct() {                          public function
    $this->bar= new Bar();                                   __construct(Bar $bar) {
  }                                                           $this->bar = $bar;
  …                                                        }
}                                                          …
                                                        }

 Cons:                                                           Pros:
 Difficult to test                                               Easy to test
 No isolation                                                    Isolation
 Difficult to reuse code                                         Flexible architecture
                           © All rights reserved. Zend Technologies, Inc.
Di by setter


class Foo {
   protected $bar;
   …
   public function setBar(Bar $bar) {
      $this->bar = $bar;
   }
   …
}




                 © All rights reserved. Zend Technologies, Inc.
ZendDi
●   Supports the 3 different injection patterns:
       – Constructor
       – Interface
       – Setter
●
    Implements a Di Container:
       – Manage the dependencies using configuration
           and annotation
       – Provide a compiler to autodiscover classes in a
           path and create the class definitions, for
           dependencies

                       © All rights reserved. Zend Technologies, Inc.
Sample definition

 $definition = array(
     'Foo' => array(
         'setBar' => array(
             'bar' => array(
                 'type'      => 'Bar',
                 'required' => true,
             ),
         ),
     ),
 );




                     © All rights reserved. Zend Technologies, Inc.
Using the Di container

 use ZendDiDi,
     ZendDiConfiguration;

 $di     = new Di;
 $config = new Configuration(array(
     'definition' => array('class' => $definition)
 ));
 $config->configure($di);

 $foo = $di->get('Foo'); // contains Bar!




                    © All rights reserved. Zend Technologies, Inc.
Di by annotation

 namespace FooBar {
    use ZendDiDefinitionAnnotation as Di;

     class Baz {
        public $bam;
        /**
          * @DiInject()
          */
        public function setBam(Bam $bam){
             $this->bam = $bam;
        }
     }

     class Bam {
     }
 }


                      © All rights reserved. Zend Technologies, Inc.
Di by annotation (2)

$compiler = new ZendDiDefinitionCompilerDefinition();
$compiler->addDirectory('File path of Baz and Bar');
$compiler->compile();

$definitions = new ZendDiDefinitionList($compiler);
$di = new ZendDiDi($definitions);

$baz = $di->get('FooBarBaz');




More use cases of ZendDi:
https://github.com/ralphschindler/zf2-di-use-cases


                        © All rights reserved. Zend Technologies, Inc.
Event Manager




   © All rights reserved. Zend Technologies, Inc.
The problem

●
    How do we introduce logging/debug points in
    framework code?
●
    How do we allow users to introduce caching
    without needing to extend framework code?
●
    How do we allow users to introduce validation,
    filtering, ACL checks, etc., without needing to
    extend framework code?




                      © All rights reserved. Zend Technologies, Inc.
Event Manager

●
    An Event Manager is an object that aggregates
    listeners for one or more named events, and
    which triggers events.
●
    A Listener is a callback that can react to an
    event.
●
    An Event is an action.




                      © All rights reserved. Zend Technologies, Inc.
Example

use ZendEventManagerEventManager;

$events = new EventManager();
$events->attach('do', function($e) {
    $event = $e->getName();
    $params = $e->getParams();
    printf(
        'Handled event “%s”, with parameters %s',
        $event,
        json_encode($params)
    );
});
$params = array('foo' => 'bar', 'baz' => 'bat');
$events->trigger('do', null, $params);




                     © All rights reserved. Zend Technologies, Inc.
MVC



© All rights reserved. Zend Technologies, Inc.
Event driven architecture

●
    An Application composes a router, a locator, and an
    event manager
●
    A matching route should return a controller name
●
    Controllers are pulled from the locator and
    dispatched
●   Routing and dispatching are events




                      © All rights reserved. Zend Technologies, Inc.
Module architecture


  “A module is a collection of code and other
    files that solves a more specific atomic
   problem of the larger business problem.”
                                                        (from the ZF2 RFC)




                 © All rights reserved. Zend Technologies, Inc.
Modules

●
    The basic unit in a ZF2 MVC application is
    a Module
●
    Modules are simply:
       ▶   A namespace
       ▶   containing a single classfile, a Module




                      © All rights reserved. Zend Technologies, Inc.
Example

●
    modules/
●     Foo/
●       Module.php




                 © All rights reserved. Zend Technologies, Inc.
Module.php

       namespace Foo;

       class Module { }



 ●   Modules usually also provide:
        ▶   Autoloading artifacts
        ▶   Basic configuration



                       © All rights reserved. Zend Technologies, Inc.
index.php

use ZendModuleManager,
    ZendMvcBootstrap,
    ZendMvcApplication;

$config = include __DIR__. '/../configs/app.config.php';
$modules = new Manager($config['modules']);

$bootstrap = new Bootstrap($modules);
$app       = new Application();
$bootstrap->bootstrap($app);
$app->run()->send();




                     © All rights reserved. Zend Technologies, Inc.
Controller

namespace FooController;

use ZendMvcControllerActionController;

class HelloController extends ActionController
{
    public function worldAction()
    {
        $query   = $this->request->query();
        $message = $query->get('message', 'Nobody');
        return array('message' => $message);
    }
}



                    © All rights reserved. Zend Technologies, Inc.
Render a view

use ZendEventManagerEventCollection as Events,
    ZendEventManagerListenerAggregate;

class ViewListener implements ListenerAggregate
{
    /* ... */

    public function attach(Events $events)
    {
        $events->attach('dispatch',
            array($this, 'renderView', -100);
        $events->attach('dispatch',
            array($this, 'renderLayout', -1000);
    }

    /* ... */
}

                     © All rights reserved. Zend Technologies, Inc.
Getting dependencies

namespace ContactController;

use ZendMailTransport,
    ZendMvcControllerActionController;

class ContactController extends ActionController
{
    public function setMailer(Transport $transport)
    {
        $this->transport = $transport;
    }
}




                     © All rights reserved. Zend Technologies, Inc.
Di configuration
return array('di' => array(
  'definition' => array('class' => array(
    'ZendMailTransportSmtp' => array(
      '__construct' => array(
        'host' => array('required' => true, 'type'                      => false),
        'user' => array('required' => true, 'type'                      => false),
        'pass' => array('required' => true, 'type'                      => false),
      ),
    ),
  )),
  'instance' => array(
    'ZendMailTransport' => array('parameters' =>                      array(
      'host' => 'some.host.tld',
      'user' => 'user',
      'pass' => 'pass'
    )),
  ),
);



                       © All rights reserved. Zend Technologies, Inc.
Source package




    © All rights reserved. Zend Technologies, Inc.
Source package

 ●
     http://packages.zendframework.com/
 ●
     Source packages (download + github)
 ●   Pyrus packages:
      ▶   wget http://packages.zendframework.com/pyrus.phar
      ▶   pyrus.phar .
      ▶   pyrus.phar . channel­discover 
          packages.zendframework.com
      ▶   pyrus.phar . install zf2/<zf­package>
      ▶   pyrus.phar . install zf2/Zend_<component>




                        © All rights reserved. Zend Technologies, Inc.
From ZF1 to ZF2




    © All rights reserved. Zend Technologies, Inc.
Migrate to ZF2

●   Our goal: migrate without rewriting much code!
●   Main steps
      – Namespace: Zend_Foo => ZendFoo
      – Exceptions: an Interface for each components,
          no more Zend_Exception
      – Autoloading: 3 possible options (one is the same
          of ZF1)
       ▶   MVC: module, event based, dispatchable



                      © All rights reserved. Zend Technologies, Inc.
ZF1 migration prototype

●
    Source code: http://bit.ly/pvc0X1
●
    Creates a "Zf1Compat" version of the ZF1
    dispatcher as an event listener.
●
    The bootstrap largely mimics how ZF1's
    Zend_Application bootstrap works.
●   The default route utilizes the new ZF2 MVC
    routing, but mimics what ZF1 provided.




                     © All rights reserved. Zend Technologies, Inc.
Helping out

●
    http://framework.zend.com/zf2
●
    http://github.com/zendframework
●
    Bi-weekly IRC meetings (#zf2-meeting on
    Freenode IRC)
●   #zftalk.2 on Freenode IRC




                     © All rights reserved. Zend Technologies, Inc.
Thank you!
 ●
     Vote this talk:
        ▶   http://joind.in/4359

●
     Comments and feedbacks:
       – enrico@zend.com




                        © All rights reserved. Zend Technologies, Inc.

More Related Content

What's hot

Zend Framework 2 Components
Zend Framework 2 ComponentsZend Framework 2 Components
Zend Framework 2 ComponentsShawn Stratton
 
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)ZFConf Conference
 
Deprecated: Foundations of Zend Framework 2
Deprecated: Foundations of Zend Framework 2Deprecated: Foundations of Zend Framework 2
Deprecated: Foundations of Zend Framework 2Adam Culp
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Nikita Popov
 
Create your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaCreate your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaPatrick Allaert
 
Have Your Cake and Eat It Too: Meta-Programming Techniques for Java
Have Your Cake and Eat It Too: Meta-Programming Techniques for JavaHave Your Cake and Eat It Too: Meta-Programming Techniques for Java
Have Your Cake and Eat It Too: Meta-Programming Techniques for JavaHoward Lewis Ship
 
Secure Programming
Secure ProgrammingSecure Programming
Secure Programmingalpha0
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Nikita Popov
 
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)ZFConf Conference
 
PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021Ayesh Karunaratne
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Fwdays
 
Fantastic DSL in Python
Fantastic DSL in PythonFantastic DSL in Python
Fantastic DSL in Pythonkwatch
 
Testing untestable code - ConFoo13
Testing untestable code - ConFoo13Testing untestable code - ConFoo13
Testing untestable code - ConFoo13Stephan Hochdörfer
 
Dependency Injection in PHP
Dependency Injection in PHPDependency Injection in PHP
Dependency Injection in PHPKacper Gunia
 
Advanced PHP Simplified - Sunshine PHP 2018
Advanced PHP Simplified - Sunshine PHP 2018Advanced PHP Simplified - Sunshine PHP 2018
Advanced PHP Simplified - Sunshine PHP 2018Mark Niebergall
 

What's hot (20)

Zend Framework 2 Components
Zend Framework 2 ComponentsZend Framework 2 Components
Zend Framework 2 Components
 
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
 
Deprecated: Foundations of Zend Framework 2
Deprecated: Foundations of Zend Framework 2Deprecated: Foundations of Zend Framework 2
Deprecated: Foundations of Zend Framework 2
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
Zend Framework 2
Zend Framework 2Zend Framework 2
Zend Framework 2
 
Intro to J Ruby
Intro to J RubyIntro to J Ruby
Intro to J Ruby
 
Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?Typed Properties and more: What's coming in PHP 7.4?
Typed Properties and more: What's coming in PHP 7.4?
 
Create your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaCreate your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 Verona
 
Have Your Cake and Eat It Too: Meta-Programming Techniques for Java
Have Your Cake and Eat It Too: Meta-Programming Techniques for JavaHave Your Cake and Eat It Too: Meta-Programming Techniques for Java
Have Your Cake and Eat It Too: Meta-Programming Techniques for Java
 
Secure Programming
Secure ProgrammingSecure Programming
Secure Programming
 
Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)Static Optimization of PHP bytecode (PHPSC 2017)
Static Optimization of PHP bytecode (PHPSC 2017)
 
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
ZFConf 2012: Dependency Management в PHP и Zend Framework 2 (Кирилл Чебунин)
 
PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021PHP Enums - PHPCon Japan 2021
PHP Enums - PHPCon Japan 2021
 
Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"Nikita Popov "What’s new in PHP 8.0?"
Nikita Popov "What’s new in PHP 8.0?"
 
Fantastic DSL in Python
Fantastic DSL in PythonFantastic DSL in Python
Fantastic DSL in Python
 
Testing untestable code - ConFoo13
Testing untestable code - ConFoo13Testing untestable code - ConFoo13
Testing untestable code - ConFoo13
 
Dependency Injection in PHP
Dependency Injection in PHPDependency Injection in PHP
Dependency Injection in PHP
 
DSLs in JavaScript
DSLs in JavaScriptDSLs in JavaScript
DSLs in JavaScript
 
DSLs In Erlang
DSLs In ErlangDSLs In Erlang
DSLs In Erlang
 
Advanced PHP Simplified - Sunshine PHP 2018
Advanced PHP Simplified - Sunshine PHP 2018Advanced PHP Simplified - Sunshine PHP 2018
Advanced PHP Simplified - Sunshine PHP 2018
 

Similar to ZF2 Presentation @PHP Tour 2011 in Lille

How to Manage Cloud Infrastructures using Zend Framework
How to Manage Cloud Infrastructures using Zend FrameworkHow to Manage Cloud Infrastructures using Zend Framework
How to Manage Cloud Infrastructures using Zend FrameworkZend by Rogue Wave Software
 
Z ray plugins for dummies
Z ray plugins for dummiesZ ray plugins for dummies
Z ray plugins for dummiesDmitry Zbarski
 
Eclipse HandsOn Workshop
Eclipse HandsOn WorkshopEclipse HandsOn Workshop
Eclipse HandsOn WorkshopBastian Feder
 
Php7 extensions workshop
Php7 extensions workshopPhp7 extensions workshop
Php7 extensions workshopjulien pauli
 
Using Zend_Tool to Establish Your Project's Skeleton
Using Zend_Tool to Establish Your Project's SkeletonUsing Zend_Tool to Establish Your Project's Skeleton
Using Zend_Tool to Establish Your Project's SkeletonJeremy Brown
 
Ростислав Михайлив "Zend Framework 3 - evolution or revolution"
Ростислав Михайлив "Zend Framework 3 - evolution or revolution"Ростислав Михайлив "Zend Framework 3 - evolution or revolution"
Ростислав Михайлив "Zend Framework 3 - evolution or revolution"Fwdays
 
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)Enrico Zimuel
 
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)James Titcumb
 
Php Development With Eclipde PDT
Php Development With Eclipde PDTPhp Development With Eclipde PDT
Php Development With Eclipde PDTBastian Feder
 
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)James Titcumb
 
Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)James Titcumb
 
Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009Bastian Feder
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy CodeRowan Merewood
 
Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Deepak Garg
 
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Bastian Feder
 
Debugging PHP with xDebug inside of Eclipse PDT 2.1
Debugging PHP with xDebug inside of Eclipse PDT 2.1Debugging PHP with xDebug inside of Eclipse PDT 2.1
Debugging PHP with xDebug inside of Eclipse PDT 2.1Bastian Feder
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)James Titcumb
 
2010 07-28-testing-zf-apps
2010 07-28-testing-zf-apps2010 07-28-testing-zf-apps
2010 07-28-testing-zf-appsVenkata Ramana
 

Similar to ZF2 Presentation @PHP Tour 2011 in Lille (20)

How to Manage Cloud Infrastructures using Zend Framework
How to Manage Cloud Infrastructures using Zend FrameworkHow to Manage Cloud Infrastructures using Zend Framework
How to Manage Cloud Infrastructures using Zend Framework
 
Z ray plugins for dummies
Z ray plugins for dummiesZ ray plugins for dummies
Z ray plugins for dummies
 
Eclipse HandsOn Workshop
Eclipse HandsOn WorkshopEclipse HandsOn Workshop
Eclipse HandsOn Workshop
 
Php7 extensions workshop
Php7 extensions workshopPhp7 extensions workshop
Php7 extensions workshop
 
Getting Native with NDK
Getting Native with NDKGetting Native with NDK
Getting Native with NDK
 
Zf2 phpquebec
Zf2 phpquebecZf2 phpquebec
Zf2 phpquebec
 
Using Zend_Tool to Establish Your Project's Skeleton
Using Zend_Tool to Establish Your Project's SkeletonUsing Zend_Tool to Establish Your Project's Skeleton
Using Zend_Tool to Establish Your Project's Skeleton
 
Ростислав Михайлив "Zend Framework 3 - evolution or revolution"
Ростислав Михайлив "Zend Framework 3 - evolution or revolution"Ростислав Михайлив "Zend Framework 3 - evolution or revolution"
Ростислав Михайлив "Zend Framework 3 - evolution or revolution"
 
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
Manage cloud infrastructures in PHP using Zend Framework 2 (and 1)
 
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP South Africa 2018)
 
Php Development With Eclipde PDT
Php Development With Eclipde PDTPhp Development With Eclipde PDT
Php Development With Eclipde PDT
 
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
Kicking off with Zend Expressive and Doctrine ORM (ConFoo YVR 2017)
 
Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)
Kicking off with Zend Expressive and Doctrine ORM (PHP MiNDS March 2018)
 
Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009Eclipse Pdt2.0 26.05.2009
Eclipse Pdt2.0 26.05.2009
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 
Bangpypers april-meetup-2012
Bangpypers april-meetup-2012Bangpypers april-meetup-2012
Bangpypers april-meetup-2012
 
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
 
Debugging PHP with xDebug inside of Eclipse PDT 2.1
Debugging PHP with xDebug inside of Eclipse PDT 2.1Debugging PHP with xDebug inside of Eclipse PDT 2.1
Debugging PHP with xDebug inside of Eclipse PDT 2.1
 
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
Kicking off with Zend Expressive and Doctrine ORM (PHP Srbija 2017)
 
2010 07-28-testing-zf-apps
2010 07-28-testing-zf-apps2010 07-28-testing-zf-apps
2010 07-28-testing-zf-apps
 

More from Zend by Rogue Wave Software

Building and managing applications fast for IBM i
Building and managing applications fast for IBM iBuilding and managing applications fast for IBM i
Building and managing applications fast for IBM iZend by Rogue Wave Software
 
Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Speed up web APIs with Expressive and Swoole (PHP Day 2018) Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Speed up web APIs with Expressive and Swoole (PHP Day 2018) Zend by Rogue Wave Software
 
The Sodium crypto library of PHP 7.2 (PHP Day 2018)
The Sodium crypto library of PHP 7.2 (PHP Day 2018)The Sodium crypto library of PHP 7.2 (PHP Day 2018)
The Sodium crypto library of PHP 7.2 (PHP Day 2018)Zend by Rogue Wave Software
 
Develop web APIs in PHP using middleware with Expressive (Code Europe)
Develop web APIs in PHP using middleware with Expressive (Code Europe)Develop web APIs in PHP using middleware with Expressive (Code Europe)
Develop web APIs in PHP using middleware with Expressive (Code Europe)Zend by Rogue Wave Software
 

More from Zend by Rogue Wave Software (20)

Develop microservices in php
Develop microservices in phpDevelop microservices in php
Develop microservices in php
 
Speed and security for your PHP application
Speed and security for your PHP applicationSpeed and security for your PHP application
Speed and security for your PHP application
 
Building and managing applications fast for IBM i
Building and managing applications fast for IBM iBuilding and managing applications fast for IBM i
Building and managing applications fast for IBM i
 
Building web APIs in PHP with Zend Expressive
Building web APIs in PHP with Zend ExpressiveBuilding web APIs in PHP with Zend Expressive
Building web APIs in PHP with Zend Expressive
 
To PHP 7 and beyond
To PHP 7 and beyondTo PHP 7 and beyond
To PHP 7 and beyond
 
Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Speed up web APIs with Expressive and Swoole (PHP Day 2018) Speed up web APIs with Expressive and Swoole (PHP Day 2018)
Speed up web APIs with Expressive and Swoole (PHP Day 2018)
 
The Sodium crypto library of PHP 7.2 (PHP Day 2018)
The Sodium crypto library of PHP 7.2 (PHP Day 2018)The Sodium crypto library of PHP 7.2 (PHP Day 2018)
The Sodium crypto library of PHP 7.2 (PHP Day 2018)
 
Develop web APIs in PHP using middleware with Expressive (Code Europe)
Develop web APIs in PHP using middleware with Expressive (Code Europe)Develop web APIs in PHP using middleware with Expressive (Code Europe)
Develop web APIs in PHP using middleware with Expressive (Code Europe)
 
Middleware web APIs in PHP 7.x
Middleware web APIs in PHP 7.xMiddleware web APIs in PHP 7.x
Middleware web APIs in PHP 7.x
 
Ongoing management of your PHP 7 application
Ongoing management of your PHP 7 applicationOngoing management of your PHP 7 application
Ongoing management of your PHP 7 application
 
Developing web APIs using middleware in PHP 7
Developing web APIs using middleware in PHP 7Developing web APIs using middleware in PHP 7
Developing web APIs using middleware in PHP 7
 
The Docker development template for PHP
The Docker development template for PHPThe Docker development template for PHP
The Docker development template for PHP
 
The most exciting features of PHP 7.1
The most exciting features of PHP 7.1The most exciting features of PHP 7.1
The most exciting features of PHP 7.1
 
Unit testing for project managers
Unit testing for project managersUnit testing for project managers
Unit testing for project managers
 
The new features of PHP 7
The new features of PHP 7The new features of PHP 7
The new features of PHP 7
 
Deploying PHP apps on the cloud
Deploying PHP apps on the cloudDeploying PHP apps on the cloud
Deploying PHP apps on the cloud
 
Data is dead. Long live data!
Data is dead. Long live data! Data is dead. Long live data!
Data is dead. Long live data!
 
Optimizing performance
Optimizing performanceOptimizing performance
Optimizing performance
 
Resolving problems & high availability
Resolving problems & high availabilityResolving problems & high availability
Resolving problems & high availability
 
Developing apps faster
Developing apps fasterDeveloping apps faster
Developing apps faster
 

Recently uploaded

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 

Recently uploaded (20)

Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 

ZF2 Presentation @PHP Tour 2011 in Lille

  • 1. Zend Framework 2: state of the art by Enrico Zimuel (enrico@zend.com) Senior Software Engineer Zend Framework Core Team Zend Technologies Ltd PHPTour Lille 2011 – 25 November http://afup.org/pages/phptourlille2011/ © All rights reserved. Zend Technologies, Inc.
  • 2. About me • Software Engineer since 1996 – Assembly x86, C/C++, Java, Perl, PHP • Enjoying PHP since 1999 • PHP Engineer at Zend since 2008 • ZF Core Team from April 2011 • B.Sc. Computer Science and Economics Email: enrico@zend.com Twitter: @ezimuel from University of Pescara (Italy) © All rights reserved. Zend Technologies, Inc.
  • 3. Summary ● Overview of ZF2 ● Autoloading ● Dependency Injection ● Event Manager ● The new MVC architecture ● Migrate from ZF1 to ZF2 © All rights reserved. Zend Technologies, Inc.
  • 4. Overview of ZF2 ● Open source framework for PHP, evolution of ZF1 (over 10 million downloads) ● Still in development – ZF2 beta1 released in October 2011 ● New Betas at least every six weeks (until we're done) ● No more CLA to contribute to ZF2 ● We use github (no more SVN) © All rights reserved. Zend Technologies, Inc.
  • 5. A new core ● The ZF1 way: ▶ Singletons, Registries, and Hard-Coded Dependencies ● The ZF2 approach: ▶ Aspect Oriented Design and Dependency Injection © All rights reserved. Zend Technologies, Inc.
  • 6. Architectural approach ● Methodologies used in the development – Decoupling (ZendDi) – Event driven (ZendEventManager) – Standard interfaces (ZendStdlib) ● Take advantages of PHP 5.3+ © All rights reserved. Zend Technologies, Inc.
  • 7. Our goal for ZF2 Better consistency and performance © All rights reserved. Zend Technologies, Inc.
  • 8. Autoloading © All rights reserved. Zend Technologies, Inc.
  • 9. Autoloading ● No more require_once calls! ● Multiple approaches: – ZF1-style include_path autoloader – Per-namespace/prefix autoloading – Class-map autoloading © All rights reserved. Zend Technologies, Inc.
  • 10. ZF1-Style require_once 'Zend/Loader/StandardAutoloader.php'; $loader = new ZendLoaderStandardAutoloader(array( 'fallback_autoloader' => true, )); $loader->register(); © All rights reserved. Zend Technologies, Inc.
  • 11. ZF2 NS/Prefix require_once 'Zend/Loader/StandardAutoloader.php'; $loader = new ZendLoaderStandardAutoloader(); $loader->registerNamespace( 'My', __DIR__ . '/../library/My') ->registerPrefix( 'Foo_', __DIR__ . '/../library/Foo'); $loader->register(); © All rights reserved. Zend Technologies, Inc.
  • 12. ZF2 Class-Map return array( 'MyFooBar' => __DIR__ . '/Foo/Bar.php', ); .classmap.php require_once 'Zend/Loader/ClassMapAutoloader.php'; $loader = new ZendLoaderClassMapAutoloader(); $loader->registerAutoloadMap( __DIR__ . '/../library/.classmap.php'); $loader->register(); © All rights reserved. Zend Technologies, Inc.
  • 13. Classmap generator ● How to generate the .classmap.php ? We provided a command line tool: bin/classmap_generator.php ● Usage is trivial: $ cd your/library $ php /path/to/classmap_generator.php -w ● Class-Map will be created in .classmap.php © All rights reserved. Zend Technologies, Inc.
  • 14. Performance ● Class-Maps show a 25% improvement on the ZF1 autoloader when no acceleration is present ▶ and 60-85% improvements when an opcode cache is in place! ● Pairing namespaces/prefixes with specific paths shows >10% gains with no acceleration ▶ and 40% improvements when an opcode cache is in place! © All rights reserved. Zend Technologies, Inc.
  • 15. Dependency Injection © All rights reserved. Zend Technologies, Inc.
  • 16. Dependency injection ● How to manage dependencies between objects? ● Dependency injection (Di) is a design pattern whose purpose is to reduce the coupling between software components © All rights reserved. Zend Technologies, Inc.
  • 17. Di by construct Without Di With Di (construct) class Foo { class Foo { protected $bar; protected $bar; … … public function __construct() { public function $this->bar= new Bar(); __construct(Bar $bar) { } $this->bar = $bar; … } } … } Cons: Pros: Difficult to test Easy to test No isolation Isolation Difficult to reuse code Flexible architecture © All rights reserved. Zend Technologies, Inc.
  • 18. Di by setter class Foo { protected $bar; … public function setBar(Bar $bar) { $this->bar = $bar; } … } © All rights reserved. Zend Technologies, Inc.
  • 19. ZendDi ● Supports the 3 different injection patterns: – Constructor – Interface – Setter ● Implements a Di Container: – Manage the dependencies using configuration and annotation – Provide a compiler to autodiscover classes in a path and create the class definitions, for dependencies © All rights reserved. Zend Technologies, Inc.
  • 20. Sample definition $definition = array( 'Foo' => array( 'setBar' => array( 'bar' => array( 'type' => 'Bar', 'required' => true, ), ), ), ); © All rights reserved. Zend Technologies, Inc.
  • 21. Using the Di container use ZendDiDi, ZendDiConfiguration; $di = new Di; $config = new Configuration(array( 'definition' => array('class' => $definition) )); $config->configure($di); $foo = $di->get('Foo'); // contains Bar! © All rights reserved. Zend Technologies, Inc.
  • 22. Di by annotation namespace FooBar { use ZendDiDefinitionAnnotation as Di; class Baz { public $bam; /** * @DiInject() */ public function setBam(Bam $bam){ $this->bam = $bam; } } class Bam { } } © All rights reserved. Zend Technologies, Inc.
  • 23. Di by annotation (2) $compiler = new ZendDiDefinitionCompilerDefinition(); $compiler->addDirectory('File path of Baz and Bar'); $compiler->compile(); $definitions = new ZendDiDefinitionList($compiler); $di = new ZendDiDi($definitions); $baz = $di->get('FooBarBaz'); More use cases of ZendDi: https://github.com/ralphschindler/zf2-di-use-cases © All rights reserved. Zend Technologies, Inc.
  • 24. Event Manager © All rights reserved. Zend Technologies, Inc.
  • 25. The problem ● How do we introduce logging/debug points in framework code? ● How do we allow users to introduce caching without needing to extend framework code? ● How do we allow users to introduce validation, filtering, ACL checks, etc., without needing to extend framework code? © All rights reserved. Zend Technologies, Inc.
  • 26. Event Manager ● An Event Manager is an object that aggregates listeners for one or more named events, and which triggers events. ● A Listener is a callback that can react to an event. ● An Event is an action. © All rights reserved. Zend Technologies, Inc.
  • 27. Example use ZendEventManagerEventManager; $events = new EventManager(); $events->attach('do', function($e) { $event = $e->getName(); $params = $e->getParams(); printf( 'Handled event “%s”, with parameters %s', $event, json_encode($params) ); }); $params = array('foo' => 'bar', 'baz' => 'bat'); $events->trigger('do', null, $params); © All rights reserved. Zend Technologies, Inc.
  • 28. MVC © All rights reserved. Zend Technologies, Inc.
  • 29. Event driven architecture ● An Application composes a router, a locator, and an event manager ● A matching route should return a controller name ● Controllers are pulled from the locator and dispatched ● Routing and dispatching are events © All rights reserved. Zend Technologies, Inc.
  • 30. Module architecture “A module is a collection of code and other files that solves a more specific atomic problem of the larger business problem.” (from the ZF2 RFC) © All rights reserved. Zend Technologies, Inc.
  • 31. Modules ● The basic unit in a ZF2 MVC application is a Module ● Modules are simply: ▶ A namespace ▶ containing a single classfile, a Module © All rights reserved. Zend Technologies, Inc.
  • 32. Example ● modules/ ● Foo/ ● Module.php © All rights reserved. Zend Technologies, Inc.
  • 33. Module.php namespace Foo; class Module { } ● Modules usually also provide: ▶ Autoloading artifacts ▶ Basic configuration © All rights reserved. Zend Technologies, Inc.
  • 34. index.php use ZendModuleManager, ZendMvcBootstrap, ZendMvcApplication; $config = include __DIR__. '/../configs/app.config.php'; $modules = new Manager($config['modules']); $bootstrap = new Bootstrap($modules); $app = new Application(); $bootstrap->bootstrap($app); $app->run()->send(); © All rights reserved. Zend Technologies, Inc.
  • 35. Controller namespace FooController; use ZendMvcControllerActionController; class HelloController extends ActionController { public function worldAction() { $query = $this->request->query(); $message = $query->get('message', 'Nobody'); return array('message' => $message); } } © All rights reserved. Zend Technologies, Inc.
  • 36. Render a view use ZendEventManagerEventCollection as Events, ZendEventManagerListenerAggregate; class ViewListener implements ListenerAggregate { /* ... */ public function attach(Events $events) { $events->attach('dispatch', array($this, 'renderView', -100); $events->attach('dispatch', array($this, 'renderLayout', -1000); } /* ... */ } © All rights reserved. Zend Technologies, Inc.
  • 37. Getting dependencies namespace ContactController; use ZendMailTransport, ZendMvcControllerActionController; class ContactController extends ActionController { public function setMailer(Transport $transport) { $this->transport = $transport; } } © All rights reserved. Zend Technologies, Inc.
  • 38. Di configuration return array('di' => array( 'definition' => array('class' => array( 'ZendMailTransportSmtp' => array( '__construct' => array( 'host' => array('required' => true, 'type' => false), 'user' => array('required' => true, 'type' => false), 'pass' => array('required' => true, 'type' => false), ), ), )), 'instance' => array( 'ZendMailTransport' => array('parameters' => array( 'host' => 'some.host.tld', 'user' => 'user', 'pass' => 'pass' )), ), ); © All rights reserved. Zend Technologies, Inc.
  • 39. Source package © All rights reserved. Zend Technologies, Inc.
  • 40. Source package ● http://packages.zendframework.com/ ● Source packages (download + github) ● Pyrus packages: ▶ wget http://packages.zendframework.com/pyrus.phar ▶ pyrus.phar . ▶ pyrus.phar . channel­discover  packages.zendframework.com ▶ pyrus.phar . install zf2/<zf­package> ▶ pyrus.phar . install zf2/Zend_<component> © All rights reserved. Zend Technologies, Inc.
  • 41. From ZF1 to ZF2 © All rights reserved. Zend Technologies, Inc.
  • 42. Migrate to ZF2 ● Our goal: migrate without rewriting much code! ● Main steps – Namespace: Zend_Foo => ZendFoo – Exceptions: an Interface for each components, no more Zend_Exception – Autoloading: 3 possible options (one is the same of ZF1) ▶ MVC: module, event based, dispatchable © All rights reserved. Zend Technologies, Inc.
  • 43. ZF1 migration prototype ● Source code: http://bit.ly/pvc0X1 ● Creates a "Zf1Compat" version of the ZF1 dispatcher as an event listener. ● The bootstrap largely mimics how ZF1's Zend_Application bootstrap works. ● The default route utilizes the new ZF2 MVC routing, but mimics what ZF1 provided. © All rights reserved. Zend Technologies, Inc.
  • 44. Helping out ● http://framework.zend.com/zf2 ● http://github.com/zendframework ● Bi-weekly IRC meetings (#zf2-meeting on Freenode IRC) ● #zftalk.2 on Freenode IRC © All rights reserved. Zend Technologies, Inc.
  • 45. Thank you! ● Vote this talk: ▶ http://joind.in/4359 ● Comments and feedbacks: – enrico@zend.com © All rights reserved. Zend Technologies, Inc.