SlideShare a Scribd company logo
1 of 24
Download to read offline
Zend Framework 2
Basic components
Who is this guy?
name:
     Mateusz Tymek
age:
     26
job:
     Developer at
Zend Framework 2

Zend Framework 1 is great! Why do we need
new version?
Zend Framework 2

Zend Framework 1 is great! Why do we need
new version?

●   ZF1 is inflexible
●   performance sucks
●   difficult to learn
●   doesn't use PHP 5.3 goodies
Zend Framework 2
● development started in 2010
● latest release is BETA3
● release cycle is following the "Gmail" style of
  betas
● developed on GitHub
● no CLA needed anymore!
● aims to provide modern, fast web
  framework...
● ...that solves all problems with its
  predecessor
ZF1             ZF2
application     config
  configs       module
  controllers     Application
  modules            config
  views              src
library                Application
public                    Controller
                     view
                public
                vendor
New module system
module
  Application
     config            "A Module is a
     public            collection of code and
     src
       Application
                       other files that solves
          Controller
                       a more specific
          Form         atomic problem of the
          Model        larger business
          Service      problem"
     view
Module class
class Module implements AutoloaderProvider {
        public function init(Manager $moduleManager)   // module initialization
        {}


        public function getAutoloaderConfig()   // configure PSR-0 autoloader
        {
            return array(
               'ZendLoaderStandardAutoloader' => array(
                    'namespaces' => array(
                        'Application' => __DIR__ . '/src/Application ',
                    )));
        }


        public function getConfig() // provide module configuration
        {
            return include __DIR__ . '/config/module.config.php';
        }
    }
Module configuration

Default:                                          User override:

modules/Doctrine/config/module.config.php         config/autoload/doctrine.local.config.php

return array(                                     return array(
   // connection parameters                           // connection parameters
   'connection' => array(                             'connection' => array(
       'driver'   => 'pdo_mysql',                         'host'     => 'localhost',
       'host'     => 'localhost',                         'user'     => 'username',
       'port'     => '3306',                              'password' => 'password',
       'user'     => 'username',                          'dbname'   => 'database',
       'password' => 'password',                      ),
       'dbname'   => 'database',                  );
   ),
   // driver settings
   'driver' => array(
       'class'     =>
'DoctrineORMMappingDriverAnnotationDriver',
       'namespace' => 'ApplicationEntity',
      ),
);
ZendEventManager
Why do we need aspect-oriented
programming?
ZendEventManager

Define your events

ZendModuleManager    ZendMvcApplication

● loadModules.pre      ●   bootstrap
● loadModule.resolve   ●   route
● loadModules.post     ●   dispatch
                       ●   render
                       ●   finish
ZendEventManager

Attach event listeners
class Module implements AutoloaderProvider
{
    public function init(Manager $moduleManager)
    {
        $events       = $moduleManager->events();
        $sharedEvents = $events->getSharedManager();

        $sharedEvents->attach(
              'ZendMvcApplication', 'finish',
               function(Event $e) {
                    echo memory_get_usage();
               });
    }
}
Example: blog engine
class BlogEngine {
    public $events;

    public $blogPost;

    public function __construct() {
        $this->events = new EventManager(__CLASS__);
    }

    public function showBlogPost() {
        $this->events->trigger('render', $this);
        echo $this->blogPost;
    }
}
Example: blog engine
class BlogEngine {
    public $events;

    public $blogPost;

    public function __construct() {
        $this->events = new EventManager(__CLASS__);
    }

    public function showBlogPost() {
        $this->events->trigger('render', $this);
        echo $this->blogPost;
    }
}

// ...
$blogEngine->events->attach('render', function($event) {
    $engine = $event->getTarget();
    $engine->blogPost = strip_tags($engine->blogPost);
});
Dependency Injection

How do you manage your dependencies?
● globals, singletons, registry
public function indexAction() {
   global $application;
   $user = Zend_Auth::getInstance()->getIdentity();
   $db = Zend_Registry::get('db');
}
Dependency Injection

How do you manage your dependencies?
● Zend_Application_Bootstrap
public function _initPdo() {
   $pdo = new PDO(...);
   return $pdo;
}

public function _initTranslations() {
   $this->bootstrap('pdo');
   $pdo = $this->getResource('pdo'); // dependency!
   $stmt = $pdo->prepare('SELECT * FROM translations');
   // ...
}
Solution: ZendDi

● First, let's consider simple service class:
class UserService {
   protected $pdo;

    public function __construct($pdo) {
       $this->pdo = $pdo;
    }

    public function fetchAll() {
       $stmt = $this->pdo->prepare('SELECT * FROM users');
       $stmt->execute();
       return $stmt->fetchAll();
    }
}
Solution: ZendDi

● Wire it with PDO, using DI configuration:
return array(
  'di' => array(
      'instance' => array(
         'PDO' => array(
            'parameters' => array(
                 'dsn' => 'mysql:dbname=test;host=127.0.0.1',
                 'username' => 'root',
                 'passwd' => ''
          )),

         'UserService' => array(
            'parameters' => array(
                'pdo' => 'PDO'
         )
)));
Solution: ZendDi

● Use it from controllers:
public function indexAction() {

    $sUsers = $this->locator->get('UserService');

    $listOfUsers = $sUsers->fetchAll();

}
Definitions can be complex.
return array(
   'di' => array(
       'instance' => array(
           'ZendViewRendererPhpRenderer' => array(
                'parameters' => array(
                     'resolver' => 'ZendViewResolverAggregateResolver',
                ),
           ),
           'ZendViewResolverAggregateResolver' => array(
                'injections' => array(
                     'ZendViewResolverTemplateMapResolver',
                     'ZendViewResolverTemplatePathStack',
                ),
           ),
           // Defining where the layout/layout view should be located
           'ZendViewResolverTemplateMapResolver' => array(
                'parameters' => array(
                     'map'   => array(
                          'layout/layout' => __DIR__ . '/../view/layout/layout.phtml',
                     ),
                ),
           // ...




                                                                 This could go on and on...
Solution: ZendServiceLocator

Simplified application config:
return array(
    'view_manager' => array(
        'doctype'                  => 'HTML5',
        'not_found_template'       => 'error/404',
        'exception_template'       => 'error/index',
        'template_path_stack' => array(
            'application' => __DIR__ . '/../view',
        ),
    ),
);
What about performance?

 ●   PSR-0 loader

 ●   cache where possible

 ●   DiC

 ●   accelerator modules:
     EdpSuperluminal, ZfModuleLazyLoading
More info

● http://zendframework.com/zf2/

● http://zend-framework-community.634137.n4.
  nabble.com/

● https://github.com/zendframework/zf2

● http://modules.zendframework.com/

● http://mwop.net/blog.html
Thank you!

More Related Content

What's hot

Instant ACLs with Zend Framework 2
Instant ACLs with Zend Framework 2Instant ACLs with Zend Framework 2
Instant ACLs with Zend Framework 2Stefano Valle
 
ZFConf 2012: Zend Framework 2, a quick start (Enrico Zimuel)
ZFConf 2012: Zend Framework 2, a quick start (Enrico Zimuel)ZFConf 2012: Zend Framework 2, a quick start (Enrico Zimuel)
ZFConf 2012: Zend Framework 2, a quick start (Enrico Zimuel)ZFConf Conference
 
Get Started with Zend Framework 2
Get Started with Zend Framework 2Get Started with Zend Framework 2
Get Started with Zend Framework 2Mindfire Solutions
 
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)Enrico Zimuel
 
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)ZFConf Conference
 
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
 
Ростислав Михайлив "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
 
Cryptography with Zend Framework
Cryptography with Zend FrameworkCryptography with Zend Framework
Cryptography with Zend FrameworkEnrico Zimuel
 
You must know about CodeIgniter Popular Library
You must know about CodeIgniter Popular LibraryYou must know about CodeIgniter Popular Library
You must know about CodeIgniter Popular LibraryBo-Yi Wu
 
Modular architecture today
Modular architecture todayModular architecture today
Modular architecture todaypragkirk
 
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
 
Introduction to Zend framework
Introduction to Zend framework Introduction to Zend framework
Introduction to Zend framework Matteo Magni
 
How to build customizable multitenant web applications - PHPBNL11
How to build customizable multitenant web applications - PHPBNL11How to build customizable multitenant web applications - PHPBNL11
How to build customizable multitenant web applications - PHPBNL11Stephan Hochdörfer
 
Apigility reloaded
Apigility reloadedApigility reloaded
Apigility reloadedRalf Eggert
 

What's hot (20)

Instant ACLs with Zend Framework 2
Instant ACLs with Zend Framework 2Instant ACLs with Zend Framework 2
Instant ACLs with Zend Framework 2
 
ZFConf 2012: Zend Framework 2, a quick start (Enrico Zimuel)
ZFConf 2012: Zend Framework 2, a quick start (Enrico Zimuel)ZFConf 2012: Zend Framework 2, a quick start (Enrico Zimuel)
ZFConf 2012: Zend Framework 2, a quick start (Enrico Zimuel)
 
Get Started with Zend Framework 2
Get Started with Zend Framework 2Get Started with Zend Framework 2
Get Started with Zend Framework 2
 
Zf2 phpquebec
Zf2 phpquebecZf2 phpquebec
Zf2 phpquebec
 
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)Manage cloud infrastructures using Zend Framework 2 (and ZF1)
Manage cloud infrastructures using Zend Framework 2 (and ZF1)
 
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
ZFConf 2012: Capistrano для деплоймента PHP-приложений (Роман Лапин)
 
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 (Кирилл Чебунин)
 
Zend Framework 2 Patterns
Zend Framework 2 PatternsZend Framework 2 Patterns
Zend Framework 2 Patterns
 
Ростислав Михайлив "Zend Framework 3 - evolution or revolution"
Ростислав Михайлив "Zend Framework 3 - evolution or revolution"Ростислав Михайлив "Zend Framework 3 - evolution or revolution"
Ростислав Михайлив "Zend Framework 3 - evolution or revolution"
 
Cryptography with Zend Framework
Cryptography with Zend FrameworkCryptography with Zend Framework
Cryptography with Zend Framework
 
You must know about CodeIgniter Popular Library
You must know about CodeIgniter Popular LibraryYou must know about CodeIgniter Popular Library
You must know about CodeIgniter Popular Library
 
Modular architecture today
Modular architecture todayModular architecture today
Modular architecture today
 
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)
 
Introduction to Zend framework
Introduction to Zend framework Introduction to Zend framework
Introduction to Zend framework
 
Introduction to Zend Framework
Introduction to Zend FrameworkIntroduction to Zend Framework
Introduction to Zend Framework
 
How to build customizable multitenant web applications - PHPBNL11
How to build customizable multitenant web applications - PHPBNL11How to build customizable multitenant web applications - PHPBNL11
How to build customizable multitenant web applications - PHPBNL11
 
2007 Zend Con Mvc Edited Irmantas
2007 Zend Con Mvc Edited Irmantas2007 Zend Con Mvc Edited Irmantas
2007 Zend Con Mvc Edited Irmantas
 
Apigility reloaded
Apigility reloadedApigility reloaded
Apigility reloaded
 
Extending Zend_Tool
Extending Zend_ToolExtending Zend_Tool
Extending Zend_Tool
 
ZF2 Presentation @PHP Tour 2011 in Lille
ZF2 Presentation @PHP Tour 2011 in LilleZF2 Presentation @PHP Tour 2011 in Lille
ZF2 Presentation @PHP Tour 2011 in Lille
 

Viewers also liked

A SOA approximation on symfony
A SOA approximation on symfonyA SOA approximation on symfony
A SOA approximation on symfonyJoseluis Laso
 
PHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniterPHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniterKHALID C
 
Presentation1
Presentation1Presentation1
Presentation1SKvande
 
PHP is the King, nodejs the prince and python the fool
PHP is the King, nodejs the prince and python the foolPHP is the King, nodejs the prince and python the fool
PHP is the King, nodejs the prince and python the foolAlessandro Cinelli (cirpo)
 
Zend Framework 2 - Best Practices
Zend Framework 2 - Best PracticesZend Framework 2 - Best Practices
Zend Framework 2 - Best PracticesRalf Eggert
 
A brief overview of java frameworks
A brief overview of java frameworksA brief overview of java frameworks
A brief overview of java frameworksMD Sayem Ahmed
 
Zend Framework 2 : Dependency Injection
Zend Framework 2 : Dependency InjectionZend Framework 2 : Dependency Injection
Zend Framework 2 : Dependency InjectionAbdul Malik Ikhsan
 
Php Frameworks
Php FrameworksPhp Frameworks
Php FrameworksRyan Davis
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkBo-Yi Wu
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkBo-Yi Wu
 
JavaScript Frameworks and Java EE – A Great Match
JavaScript Frameworks and Java EE – A Great MatchJavaScript Frameworks and Java EE – A Great Match
JavaScript Frameworks and Java EE – A Great MatchReza Rahman
 

Viewers also liked (14)

A SOA approximation on symfony
A SOA approximation on symfonyA SOA approximation on symfony
A SOA approximation on symfony
 
PHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniterPHP Frameworks and CodeIgniter
PHP Frameworks and CodeIgniter
 
Presentation1
Presentation1Presentation1
Presentation1
 
PHP is the King, nodejs the prince and python the fool
PHP is the King, nodejs the prince and python the foolPHP is the King, nodejs the prince and python the fool
PHP is the King, nodejs the prince and python the fool
 
Zend Framework 2 - Best Practices
Zend Framework 2 - Best PracticesZend Framework 2 - Best Practices
Zend Framework 2 - Best Practices
 
A brief overview of java frameworks
A brief overview of java frameworksA brief overview of java frameworks
A brief overview of java frameworks
 
Zend Framework 2 : Dependency Injection
Zend Framework 2 : Dependency InjectionZend Framework 2 : Dependency Injection
Zend Framework 2 : Dependency Injection
 
Php Frameworks
Php FrameworksPhp Frameworks
Php Frameworks
 
CodeIgniter PHP MVC Framework
CodeIgniter PHP MVC FrameworkCodeIgniter PHP MVC Framework
CodeIgniter PHP MVC Framework
 
Work at GlobalLogic India
Work at GlobalLogic IndiaWork at GlobalLogic India
Work at GlobalLogic India
 
RESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP FrameworkRESTful API Design & Implementation with CodeIgniter PHP Framework
RESTful API Design & Implementation with CodeIgniter PHP Framework
 
Why MVC?
Why MVC?Why MVC?
Why MVC?
 
Model View Controller (MVC)
Model View Controller (MVC)Model View Controller (MVC)
Model View Controller (MVC)
 
JavaScript Frameworks and Java EE – A Great Match
JavaScript Frameworks and Java EE – A Great MatchJavaScript Frameworks and Java EE – A Great Match
JavaScript Frameworks and Java EE – A Great Match
 

Similar to Zend Framework 2 - Basic Components

ZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperGary Hockin
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the TrenchesJonathan Wage
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenchesLukas Smith
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf Conference
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolGordon Forsythe
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Shinya Ohyanagi
 
"Angular.js Concepts in Depth" by Aleksandar Simović
"Angular.js Concepts in Depth" by Aleksandar Simović"Angular.js Concepts in Depth" by Aleksandar Simović
"Angular.js Concepts in Depth" by Aleksandar SimovićJS Belgrade
 
Doctrine with Symfony - SymfonyCon 2019
Doctrine with Symfony - SymfonyCon 2019Doctrine with Symfony - SymfonyCon 2019
Doctrine with Symfony - SymfonyCon 2019julien pauli
 
Lviv 2013 d7 vs d8
Lviv 2013 d7 vs d8Lviv 2013 d7 vs d8
Lviv 2013 d7 vs d8Skilld
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
Beyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance JavascriptBeyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance Javascriptaglemann
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 
Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера
Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендераAndy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера
Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендераLEDC 2016
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony AppsKris Wallsmith
 
Magento Dependency Injection
Magento Dependency InjectionMagento Dependency Injection
Magento Dependency InjectionAnton Kril
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS ArchitectureEyal Vardi
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS InternalEyal Vardi
 
Getting up & running with zend framework
Getting up & running with zend frameworkGetting up & running with zend framework
Getting up & running with zend frameworkSaidur Rahman
 

Similar to Zend Framework 2 - Basic Components (20)

ZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperZF2 for the ZF1 Developer
ZF2 for the ZF1 Developer
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
 
Zend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_ToolZend Framework 1.9 Setup & Using Zend_Tool
Zend Framework 1.9 Setup & Using Zend_Tool
 
Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2Zend Framework Study@Tokyo #2
Zend Framework Study@Tokyo #2
 
Drupal 8 migrate!
Drupal 8 migrate!Drupal 8 migrate!
Drupal 8 migrate!
 
"Angular.js Concepts in Depth" by Aleksandar Simović
"Angular.js Concepts in Depth" by Aleksandar Simović"Angular.js Concepts in Depth" by Aleksandar Simović
"Angular.js Concepts in Depth" by Aleksandar Simović
 
Doctrine with Symfony - SymfonyCon 2019
Doctrine with Symfony - SymfonyCon 2019Doctrine with Symfony - SymfonyCon 2019
Doctrine with Symfony - SymfonyCon 2019
 
Lviv 2013 d7 vs d8
Lviv 2013 d7 vs d8Lviv 2013 d7 vs d8
Lviv 2013 d7 vs d8
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
Beyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance JavascriptBeyond DOMReady: Ultra High-Performance Javascript
Beyond DOMReady: Ultra High-Performance Javascript
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера
Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендераAndy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера
Andy Postnikov - Drupal 7 vs Drupal 8: от бутстрапа до рендера
 
Lviv 2013 d7 vs d8
Lviv 2013   d7 vs d8Lviv 2013   d7 vs d8
Lviv 2013 d7 vs d8
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 
Magento Dependency Injection
Magento Dependency InjectionMagento Dependency Injection
Magento Dependency Injection
 
AngularJS Architecture
AngularJS ArchitectureAngularJS Architecture
AngularJS Architecture
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS Internal
 
Getting up & running with zend framework
Getting up & running with zend frameworkGetting up & running with zend framework
Getting up & running with zend framework
 

Recently uploaded

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Recently uploaded (20)

Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

Zend Framework 2 - Basic Components

  • 2. Who is this guy? name: Mateusz Tymek age: 26 job: Developer at
  • 3. Zend Framework 2 Zend Framework 1 is great! Why do we need new version?
  • 4. Zend Framework 2 Zend Framework 1 is great! Why do we need new version? ● ZF1 is inflexible ● performance sucks ● difficult to learn ● doesn't use PHP 5.3 goodies
  • 5. Zend Framework 2 ● development started in 2010 ● latest release is BETA3 ● release cycle is following the "Gmail" style of betas ● developed on GitHub ● no CLA needed anymore! ● aims to provide modern, fast web framework... ● ...that solves all problems with its predecessor
  • 6. ZF1 ZF2 application config configs module controllers Application modules config views src library Application public Controller view public vendor
  • 7. New module system module Application config "A Module is a public collection of code and src Application other files that solves Controller a more specific Form atomic problem of the Model larger business Service problem" view
  • 8. Module class class Module implements AutoloaderProvider { public function init(Manager $moduleManager) // module initialization {} public function getAutoloaderConfig() // configure PSR-0 autoloader { return array( 'ZendLoaderStandardAutoloader' => array( 'namespaces' => array( 'Application' => __DIR__ . '/src/Application ', ))); } public function getConfig() // provide module configuration { return include __DIR__ . '/config/module.config.php'; } }
  • 9. Module configuration Default: User override: modules/Doctrine/config/module.config.php config/autoload/doctrine.local.config.php return array( return array( // connection parameters // connection parameters 'connection' => array( 'connection' => array( 'driver' => 'pdo_mysql', 'host' => 'localhost', 'host' => 'localhost', 'user' => 'username', 'port' => '3306', 'password' => 'password', 'user' => 'username', 'dbname' => 'database', 'password' => 'password', ), 'dbname' => 'database', ); ), // driver settings 'driver' => array( 'class' => 'DoctrineORMMappingDriverAnnotationDriver', 'namespace' => 'ApplicationEntity', ), );
  • 10. ZendEventManager Why do we need aspect-oriented programming?
  • 11. ZendEventManager Define your events ZendModuleManager ZendMvcApplication ● loadModules.pre ● bootstrap ● loadModule.resolve ● route ● loadModules.post ● dispatch ● render ● finish
  • 12. ZendEventManager Attach event listeners class Module implements AutoloaderProvider { public function init(Manager $moduleManager) { $events = $moduleManager->events(); $sharedEvents = $events->getSharedManager(); $sharedEvents->attach( 'ZendMvcApplication', 'finish', function(Event $e) { echo memory_get_usage(); }); } }
  • 13. Example: blog engine class BlogEngine { public $events; public $blogPost; public function __construct() { $this->events = new EventManager(__CLASS__); } public function showBlogPost() { $this->events->trigger('render', $this); echo $this->blogPost; } }
  • 14. Example: blog engine class BlogEngine { public $events; public $blogPost; public function __construct() { $this->events = new EventManager(__CLASS__); } public function showBlogPost() { $this->events->trigger('render', $this); echo $this->blogPost; } } // ... $blogEngine->events->attach('render', function($event) { $engine = $event->getTarget(); $engine->blogPost = strip_tags($engine->blogPost); });
  • 15. Dependency Injection How do you manage your dependencies? ● globals, singletons, registry public function indexAction() { global $application; $user = Zend_Auth::getInstance()->getIdentity(); $db = Zend_Registry::get('db'); }
  • 16. Dependency Injection How do you manage your dependencies? ● Zend_Application_Bootstrap public function _initPdo() { $pdo = new PDO(...); return $pdo; } public function _initTranslations() { $this->bootstrap('pdo'); $pdo = $this->getResource('pdo'); // dependency! $stmt = $pdo->prepare('SELECT * FROM translations'); // ... }
  • 17. Solution: ZendDi ● First, let's consider simple service class: class UserService { protected $pdo; public function __construct($pdo) { $this->pdo = $pdo; } public function fetchAll() { $stmt = $this->pdo->prepare('SELECT * FROM users'); $stmt->execute(); return $stmt->fetchAll(); } }
  • 18. Solution: ZendDi ● Wire it with PDO, using DI configuration: return array( 'di' => array( 'instance' => array( 'PDO' => array( 'parameters' => array( 'dsn' => 'mysql:dbname=test;host=127.0.0.1', 'username' => 'root', 'passwd' => '' )), 'UserService' => array( 'parameters' => array( 'pdo' => 'PDO' ) )));
  • 19. Solution: ZendDi ● Use it from controllers: public function indexAction() { $sUsers = $this->locator->get('UserService'); $listOfUsers = $sUsers->fetchAll(); }
  • 20. Definitions can be complex. return array( 'di' => array( 'instance' => array( 'ZendViewRendererPhpRenderer' => array( 'parameters' => array( 'resolver' => 'ZendViewResolverAggregateResolver', ), ), 'ZendViewResolverAggregateResolver' => array( 'injections' => array( 'ZendViewResolverTemplateMapResolver', 'ZendViewResolverTemplatePathStack', ), ), // Defining where the layout/layout view should be located 'ZendViewResolverTemplateMapResolver' => array( 'parameters' => array( 'map' => array( 'layout/layout' => __DIR__ . '/../view/layout/layout.phtml', ), ), // ... This could go on and on...
  • 21. Solution: ZendServiceLocator Simplified application config: return array( 'view_manager' => array( 'doctype' => 'HTML5', 'not_found_template' => 'error/404', 'exception_template' => 'error/index', 'template_path_stack' => array( 'application' => __DIR__ . '/../view', ), ), );
  • 22. What about performance? ● PSR-0 loader ● cache where possible ● DiC ● accelerator modules: EdpSuperluminal, ZfModuleLazyLoading
  • 23. More info ● http://zendframework.com/zf2/ ● http://zend-framework-community.634137.n4. nabble.com/ ● https://github.com/zendframework/zf2 ● http://modules.zendframework.com/ ● http://mwop.net/blog.html