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
 
Lviv 2013 d7 vs d8
Lviv 2013   d7 vs d8Lviv 2013   d7 vs d8
Lviv 2013 d7 vs d8
 
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: от бутстрапа до рендера
 
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

Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5DianaGray10
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1DianaGray10
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAshyamraj55
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1DianaGray10
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...Daniel Zivkovic
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024SkyPlanner
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaborationbruanjhuli
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
The Kubernetes Gateway API and its role in Cloud Native API Management
The Kubernetes Gateway API and its role in Cloud Native API ManagementThe Kubernetes Gateway API and its role in Cloud Native API Management
The Kubernetes Gateway API and its role in Cloud Native API ManagementNuwan Dias
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsSeth Reyes
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6DianaGray10
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?IES VE
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXTarek Kalaji
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdfPedro Manuel
 

Recently uploaded (20)

Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5UiPath Studio Web workshop series - Day 5
UiPath Studio Web workshop series - Day 5
 
Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1Secure your environment with UiPath and CyberArk technologies - Session 1
Secure your environment with UiPath and CyberArk technologies - Session 1
 
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPAAnypoint Code Builder , Google Pub sub connector and MuleSoft RPA
Anypoint Code Builder , Google Pub sub connector and MuleSoft RPA
 
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1UiPath Platform: The Backend Engine Powering Your Automation - Session 1
UiPath Platform: The Backend Engine Powering Your Automation - Session 1
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
All in AI: LLM Landscape & RAG in 2024 with Mark Ryan (Google) & Jerry Liu (L...
 
Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024Salesforce Miami User Group Event - 1st Quarter 2024
Salesforce Miami User Group Event - 1st Quarter 2024
 
20230104 - machine vision
20230104 - machine vision20230104 - machine vision
20230104 - machine vision
 
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online CollaborationCOMPUTER 10: Lesson 7 - File Storage and Online Collaboration
COMPUTER 10: Lesson 7 - File Storage and Online Collaboration
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
The Kubernetes Gateway API and its role in Cloud Native API Management
The Kubernetes Gateway API and its role in Cloud Native API ManagementThe Kubernetes Gateway API and its role in Cloud Native API Management
The Kubernetes Gateway API and its role in Cloud Native API Management
 
Computer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and HazardsComputer 10: Lesson 10 - Online Crimes and Hazards
Computer 10: Lesson 10 - Online Crimes and Hazards
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6UiPath Studio Web workshop series - Day 6
UiPath Studio Web workshop series - Day 6
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBX
 
Nanopower In Semiconductor Industry.pdf
Nanopower  In Semiconductor Industry.pdfNanopower  In Semiconductor Industry.pdf
Nanopower In Semiconductor Industry.pdf
 

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