SlideShare uma empresa Scribd logo
1 de 38
Foundations of Zend Framework
By:
Adam Culp
Twitter: @adamculp
Foundations of Zend Framework
 About me
 PHP 5.3 Certified
 Consultant at Zend Technologies
 Organizer SoFloPHP (South Florida)
 Organizer SunshinePHP (Miami)
 Long Distance (ultra) Runner
 Judo Black Belt Instructor
Foundations of Zend Framework
 What is...
 90,529,980 installs
(Packagist Dec 5th
, 2016)
 Uses PHP >= 5.6 or 7.0
 Open Source
 On GitHub
 Composer Installation
 Built on MVC design pattern
 Can be used as components or entire framework
(61 packages)
Foundations of Zend Framework
 Skeleton Application
 Git clone Zendframework Skeleton Application
 Github /zendframework/ZendSkeletonApplication
Foundations of Zend Framework
 Composer
 Install Zend Framework
 Collection of 61 packages
 Composer install
 Creates and/or populates '/vendor' directory
 Sets up Composer autoloader (PSR-4)
 composer create-project zendframework/skeleton-
application
 composer require zendframework/zendframework
Foundations of Zend Framework
 Structure
Foundations of Zend Framework
 Zend Framework Usage
 NO MAGIC!!!
 Configuration driven
 No forced structure
 Uses namespaces
Foundations of Zend Framework
 MVC
 Very briefly
Foundations of Zend Framework
 Typical Application Flow - Load
 index.php
 Loads autoloader (PSR-4 = default)
 init Application using application.config.php
Foundations of Zend Framework
 Typical Application Flow – App Config
 application.config.php
 Loads modules one at a time
 (Module.php = convention)
 Specifies where to find modules
 Loads configs in autoload directory (DB settings,
etc.)
Foundations of Zend Framework
 Typical Application Flow – Modules
 Module.php (convention)
 Makes MvcEvent accessible via onBootstrap()
 Giving further access to Application, Event Manager,
and Service Manager.
 Loads module.config.php
 Specifies autoloader and location of files.
 May define services and wire event listeners as
needed.
Foundations of Zend Framework
 Typical Application Flow – Module Config
 module.config.php
 Containers are component specific
 Routes
 Navigation
 Service Manager
 Translator
 Controllers
 View Manager
 Steer clear of Closures (Anonymous Functions)
 Do not cache well within array.
 Less performant (parsed and compiled on every req)
as a factory only parsed when service is used.
Foundations of Zend Framework
 Routes
Foundations of Zend Framework
 Routes
 Carries how controller maps to request
 Types:
 Hostname – 'me.adamculp.com'
 Literal - '/home'
 Method – 'post,put'
 Part – creates a tree of possible routes
 Regex – use regex to match url '/blog/?<id>[0-9]?'
 Scheme – 'https'
 Segment - '/:controller[/:action][/]'
 Query – specify and capture query string params
Foundations of Zend Framework
 Route Example
/module/Application/config/module.config.php
Foundations of Zend Framework
 Event Manager
Foundations of Zend Framework
 Event Manager
 Many Event Managers
 Each is isolated
 Events are actions
 Many custom we create
 Defaults (following slide)
Foundations of Zend Framework
 Diagram of MVC Events
Foundations of Zend Framework
 Event Manager Example
/module/Application/Module.php
Foundations of Zend Framework
 Shared Event Manager
 There is only one!
 Similar to Event Manager
 Obtain from Event Manager
 Allows other lower level
Event Managers to
communicate with each
other.
 Globally available
 Why?
 May want to attach to objects not yet created, such
as attaching to all controllers.
Foundations of Zend Framework
 Shared Event Manager Example
/module/Application/Module.php
Foundations of Zend Framework
 Event Manager Characteristics
 An Object
 Attach Triggers to Events
 Listeners are callbacks when Trigger satisfied
 Function or Anon Function (action)
 Queues by priority (last parameter in call)
 Patterns
 Pub/Sub
 Class that triggers the event is publisher
 Listener is subscribing to the event
 Observer - (Subject/Observer)
 Listener is the observer
 Class Triggering the event is the subject
Foundations of Zend Framework
 Services
 ALL THE THINGS!
Foundations of Zend Framework
 Service Manager
 Recommended alternative to ZendDi
 Di pure DIC, SM is factory-based container
 Everything is a service, even Controllers
 Can be created from:
 Application configuration
 Module classes
 Useful if anon functions desired
 Module configuration (most common)
 No anon functions due to caching issues
 Local override configuration
 For times when vendor keys need over-written
 Specified in application config
Foundations of Zend Framework
 Defining Services
 Beware key name overwritting
 Use fully qualified class name when applicable
 MyAppControllerProductIndex
 Or be descriptive
 {module}-{name}
 'product-category' instead of 'category'
 All keys get normalized
 AppControllerProductIndex == app-controller-
product-index
 Hierarchy of definitions
 Module.php – initial
 module.config.php over-rides Module.php
 Local over-rides module.config.php
Foundations of Zend Framework
 Service Types
 Types:
 Services – Explicit
 key => value pairs (string, boolean, float, object)
 Invokables
 key => class (class/object with no needed
dependencies)
 Factories
 key => object (class/object with needed dependencies)
 Aliases (name => some other name)
 Abstract Factories (unknown services)
 Scoped Containers (limit what can be created)
 Shared (or not; you decide)
Foundations of Zend Framework
 Service Config Example
/module/Application/config/module.config.php
Foundations of Zend Framework
 Service Module Example
/module/Application/config/module.php
Foundations of Zend Framework
 Using Service Example
/module/Application/Module.php
/module/Application/view/layout/layout.phtml
Foundations of Zend Framework
 Using Service In Factory Example
/module/Application/Factory/CategoryControllerFactory.php
Foundations of Zend Framework
 Module Manager
Foundations of Zend Framework
 Module Manager
 Gets directives from application.config.php
 Modules to load
 Order is important if module depends on another
 Where to find modules (convention found in)
 Modules directory
 Vendor directory
 Loads each module
 Module.php
 For dynamic content/settings
 module.config.php (if getConfig() in Module.php)
 Over-rides Module.php
 Then hand off to MvcEvent process to Bootstrap.
Foundations of Zend Framework
 Module Basics
 Relative to a specific “problem”.
 Logical separation of application functionality
 Reusable
 Removing a module doesn't kill the application
 Contains everything specific to given module
 Keep init() and onBootstrap() in modules light.
 Do not add data to module structure.
Foundations of Zend Framework
 Module Contents
 Contents
 PHP Code
 MVC Functionality
 Library Code
 Though better in Application or via Composer
 May not be related to MVC
 View scripts
 Public assets (images, css, javascript)
 More?
Foundations of Zend Framework
 Module Skeleton
 Easy creation using Zend Skeleton Module
 GitHub /zendframework/ZendSkeletonModule
Foundations of Zend Framework
 Other Things Worth Investigating
 Views
 Forms
 Databases
 Navigation
 View Strategies (Action or Restful)
Sorry, just not enough time in a regular talk.
Foundations of Zend Framework
 Resources
 http://framework.zend.com
 http://www.zend.com/en/services/training/course-catal
og/zend-framework-2
 http://www.zend.com/en/services/training/course-cata
log/zend-framework-2-advanced
 http://zendframework2.de/cheat-sheet.html
 https://docs.zendframework.com/tutorials/migration/to-v
3/overview/
 https://olegkrivtsov.github.io/using-zend-framework-3-bo
ok/html/index.html
Foundations of Zend Framework
 Thank You!
 Code: https://github.com/adamculp/foundations-zf2-talk
Adam Culp
http://www.geekyboy.com
http://RunGeekRadio.com
Twitter @adamculp

Mais conteúdo relacionado

Mais procurados

Zend con what-i-learned-about-mobile-first
Zend con what-i-learned-about-mobile-firstZend con what-i-learned-about-mobile-first
Zend con what-i-learned-about-mobile-first
Clark Everetts
 
Behat Workshop at WeLovePHP
Behat Workshop at WeLovePHPBehat Workshop at WeLovePHP
Behat Workshop at WeLovePHP
Marcos Quesada
 

Mais procurados (20)

Zend con 2016 bdd with behat for beginners
Zend con 2016   bdd with behat for beginnersZend con 2016   bdd with behat for beginners
Zend con 2016 bdd with behat for beginners
 
cf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad Woodcf.Objective() 2017 - Design patterns - Brad Wood
cf.Objective() 2017 - Design patterns - Brad Wood
 
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLEAN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
AN EXERCISE IN CLEANER CODE - FROM LEGACY TO MAINTAINABLE
 
Perl6 DBDI YAPC::EU 201008
Perl6 DBDI YAPC::EU 201008Perl6 DBDI YAPC::EU 201008
Perl6 DBDI YAPC::EU 201008
 
Zend con what-i-learned-about-mobile-first
Zend con what-i-learned-about-mobile-firstZend con what-i-learned-about-mobile-first
Zend con what-i-learned-about-mobile-first
 
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
North Virginia Coldfusion User Group Meetup - Testbox - July 19th 2017
 
Yet Another Continuous Integration Story
Yet Another Continuous Integration StoryYet Another Continuous Integration Story
Yet Another Continuous Integration Story
 
Zend Framework 2 - PHPUnit
Zend Framework 2 - PHPUnitZend Framework 2 - PHPUnit
Zend Framework 2 - PHPUnit
 
Practical PHP Deployment with Jenkins
Practical PHP Deployment with JenkinsPractical PHP Deployment with Jenkins
Practical PHP Deployment with Jenkins
 
Automate Thyself
Automate ThyselfAutomate Thyself
Automate Thyself
 
Gradle起步走: 以CLI Application為例 @ JCConf 2014
Gradle起步走: 以CLI Application為例 @ JCConf 2014Gradle起步走: 以CLI Application為例 @ JCConf 2014
Gradle起步走: 以CLI Application為例 @ JCConf 2014
 
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie..."How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
"How to Use Bazel to Manage Monorepos: The Grammarly Front-End Team’s Experie...
 
Bootify your spring application
Bootify your spring applicationBootify your spring application
Bootify your spring application
 
Virtual Bolt Workshop, 5 May 2020
Virtual Bolt Workshop, 5 May 2020Virtual Bolt Workshop, 5 May 2020
Virtual Bolt Workshop, 5 May 2020
 
Build & deploy PHP application (intro level)
Build & deploy PHP application (intro level)Build & deploy PHP application (intro level)
Build & deploy PHP application (intro level)
 
Behat Workshop at WeLovePHP
Behat Workshop at WeLovePHPBehat Workshop at WeLovePHP
Behat Workshop at WeLovePHP
 
Apigility – Lightning Fast API Development - OSSCamp 2014
Apigility – Lightning Fast API Development - OSSCamp 2014 Apigility – Lightning Fast API Development - OSSCamp 2014
Apigility – Lightning Fast API Development - OSSCamp 2014
 
Robotframework
RobotframeworkRobotframework
Robotframework
 
3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API3 WAYS TO TEST YOUR COLDFUSION API
3 WAYS TO TEST YOUR COLDFUSION API
 
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
How do I write Testable Javascript - Presented at dev.Objective() June 16, 2016
 

Destaque

Destaque (6)

Deprecated: Foundations of Zend Framework 2
Deprecated: Foundations of Zend Framework 2Deprecated: Foundations of Zend Framework 2
Deprecated: Foundations of Zend Framework 2
 
Does Your Code Measure Up?
Does Your Code Measure Up?Does Your Code Measure Up?
Does Your Code Measure Up?
 
Build great products
Build great productsBuild great products
Build great products
 
Accidental professional
Accidental professionalAccidental professional
Accidental professional
 
Refactoring Legacy Code
Refactoring Legacy CodeRefactoring Legacy Code
Refactoring Legacy Code
 
Refactoring 101
Refactoring 101Refactoring 101
Refactoring 101
 

Semelhante a Foundations of Zend Framework

Unit Test for ZF SlideShare Component
Unit Test for ZF SlideShare ComponentUnit Test for ZF SlideShare Component
Unit Test for ZF SlideShare Component
zftalk
 

Semelhante a Foundations of Zend Framework (20)

Introduction to Zend Framework 2
Introduction to Zend Framework 2Introduction to Zend Framework 2
Introduction to Zend Framework 2
 
Zend framework 01 - introduction
Zend framework 01 - introductionZend framework 01 - introduction
Zend framework 01 - introduction
 
2007 Zend Con Mvc
2007 Zend Con Mvc2007 Zend Con Mvc
2007 Zend Con Mvc
 
Zf2 phpquebec
Zf2 phpquebecZf2 phpquebec
Zf2 phpquebec
 
Zend Framework Quick Start Walkthrough
Zend Framework Quick Start WalkthroughZend Framework Quick Start Walkthrough
Zend Framework Quick Start Walkthrough
 
ZF2 Modules: Events, Services, and of course, modularity
ZF2 Modules: Events, Services, and of course, modularityZF2 Modules: Events, Services, and of course, modularity
ZF2 Modules: Events, Services, and of course, modularity
 
TomatoCMS in A Nutshell
TomatoCMS in A NutshellTomatoCMS in A Nutshell
TomatoCMS in A Nutshell
 
SeedStack feature tour
SeedStack feature tourSeedStack feature tour
SeedStack feature tour
 
Getting Started with Zend Framework
Getting Started with Zend FrameworkGetting Started with Zend Framework
Getting Started with Zend Framework
 
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
 
Zf2
Zf2Zf2
Zf2
 
Demo
DemoDemo
Demo
 
first pitch
first pitchfirst pitch
first pitch
 
werwr
werwrwerwr
werwr
 
sdfsdf
sdfsdfsdfsdf
sdfsdf
 
college
collegecollege
college
 
first pitch
first pitchfirst pitch
first pitch
 
Greenathan
GreenathanGreenathan
Greenathan
 
Unit Test for ZF SlideShare Component
Unit Test for ZF SlideShare ComponentUnit Test for ZF SlideShare Component
Unit Test for ZF SlideShare Component
 
first pitch
first pitchfirst pitch
first pitch
 

Mais de Adam Culp

Mais de Adam Culp (20)

Hypermedia
HypermediaHypermedia
Hypermedia
 
Putting legacy to REST with middleware
Putting legacy to REST with middlewarePutting legacy to REST with middleware
Putting legacy to REST with middleware
 
php-1701-a
php-1701-aphp-1701-a
php-1701-a
 
Release your refactoring superpower
Release your refactoring superpowerRelease your refactoring superpower
Release your refactoring superpower
 
Managing Technical Debt
Managing Technical DebtManaging Technical Debt
Managing Technical Debt
 
Developing PHP Applications Faster
Developing PHP Applications FasterDeveloping PHP Applications Faster
Developing PHP Applications Faster
 
Containing Quality
Containing QualityContaining Quality
Containing Quality
 
Debugging elephpants
Debugging elephpantsDebugging elephpants
Debugging elephpants
 
Clean application development tutorial
Clean application development tutorialClean application development tutorial
Clean application development tutorial
 
Essential git for developers
Essential git for developersEssential git for developers
Essential git for developers
 
Vagrant for Virtualized Development
Vagrant for Virtualized DevelopmentVagrant for Virtualized Development
Vagrant for Virtualized Development
 
Clean application development (talk)
Clean application development (talk)Clean application development (talk)
Clean application development (talk)
 
Using an API
Using an APIUsing an API
Using an API
 
Puppet and Vagrant in development
Puppet and Vagrant in developmentPuppet and Vagrant in development
Puppet and Vagrant in development
 
Refactoring PHP
Refactoring PHPRefactoring PHP
Refactoring PHP
 
Selenium testing IDE 101
Selenium testing IDE 101Selenium testing IDE 101
Selenium testing IDE 101
 
Intro to OOP and new features in PHP 5.3
Intro to OOP and new features in PHP 5.3Intro to OOP and new features in PHP 5.3
Intro to OOP and new features in PHP 5.3
 
Development Environment Tips
Development Environment TipsDevelopment Environment Tips
Development Environment Tips
 
Getting your project_started
Getting your project_startedGetting your project_started
Getting your project_started
 
PHP and PDFLib
PHP and PDFLibPHP and PDFLib
PHP and PDFLib
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

Foundations of Zend Framework

  • 1. Foundations of Zend Framework By: Adam Culp Twitter: @adamculp
  • 2. Foundations of Zend Framework  About me  PHP 5.3 Certified  Consultant at Zend Technologies  Organizer SoFloPHP (South Florida)  Organizer SunshinePHP (Miami)  Long Distance (ultra) Runner  Judo Black Belt Instructor
  • 3. Foundations of Zend Framework  What is...  90,529,980 installs (Packagist Dec 5th , 2016)  Uses PHP >= 5.6 or 7.0  Open Source  On GitHub  Composer Installation  Built on MVC design pattern  Can be used as components or entire framework (61 packages)
  • 4. Foundations of Zend Framework  Skeleton Application  Git clone Zendframework Skeleton Application  Github /zendframework/ZendSkeletonApplication
  • 5. Foundations of Zend Framework  Composer  Install Zend Framework  Collection of 61 packages  Composer install  Creates and/or populates '/vendor' directory  Sets up Composer autoloader (PSR-4)  composer create-project zendframework/skeleton- application  composer require zendframework/zendframework
  • 6. Foundations of Zend Framework  Structure
  • 7. Foundations of Zend Framework  Zend Framework Usage  NO MAGIC!!!  Configuration driven  No forced structure  Uses namespaces
  • 8. Foundations of Zend Framework  MVC  Very briefly
  • 9. Foundations of Zend Framework  Typical Application Flow - Load  index.php  Loads autoloader (PSR-4 = default)  init Application using application.config.php
  • 10. Foundations of Zend Framework  Typical Application Flow – App Config  application.config.php  Loads modules one at a time  (Module.php = convention)  Specifies where to find modules  Loads configs in autoload directory (DB settings, etc.)
  • 11. Foundations of Zend Framework  Typical Application Flow – Modules  Module.php (convention)  Makes MvcEvent accessible via onBootstrap()  Giving further access to Application, Event Manager, and Service Manager.  Loads module.config.php  Specifies autoloader and location of files.  May define services and wire event listeners as needed.
  • 12. Foundations of Zend Framework  Typical Application Flow – Module Config  module.config.php  Containers are component specific  Routes  Navigation  Service Manager  Translator  Controllers  View Manager  Steer clear of Closures (Anonymous Functions)  Do not cache well within array.  Less performant (parsed and compiled on every req) as a factory only parsed when service is used.
  • 13. Foundations of Zend Framework  Routes
  • 14. Foundations of Zend Framework  Routes  Carries how controller maps to request  Types:  Hostname – 'me.adamculp.com'  Literal - '/home'  Method – 'post,put'  Part – creates a tree of possible routes  Regex – use regex to match url '/blog/?<id>[0-9]?'  Scheme – 'https'  Segment - '/:controller[/:action][/]'  Query – specify and capture query string params
  • 15. Foundations of Zend Framework  Route Example /module/Application/config/module.config.php
  • 16. Foundations of Zend Framework  Event Manager
  • 17. Foundations of Zend Framework  Event Manager  Many Event Managers  Each is isolated  Events are actions  Many custom we create  Defaults (following slide)
  • 18. Foundations of Zend Framework  Diagram of MVC Events
  • 19. Foundations of Zend Framework  Event Manager Example /module/Application/Module.php
  • 20. Foundations of Zend Framework  Shared Event Manager  There is only one!  Similar to Event Manager  Obtain from Event Manager  Allows other lower level Event Managers to communicate with each other.  Globally available  Why?  May want to attach to objects not yet created, such as attaching to all controllers.
  • 21. Foundations of Zend Framework  Shared Event Manager Example /module/Application/Module.php
  • 22. Foundations of Zend Framework  Event Manager Characteristics  An Object  Attach Triggers to Events  Listeners are callbacks when Trigger satisfied  Function or Anon Function (action)  Queues by priority (last parameter in call)  Patterns  Pub/Sub  Class that triggers the event is publisher  Listener is subscribing to the event  Observer - (Subject/Observer)  Listener is the observer  Class Triggering the event is the subject
  • 23. Foundations of Zend Framework  Services  ALL THE THINGS!
  • 24. Foundations of Zend Framework  Service Manager  Recommended alternative to ZendDi  Di pure DIC, SM is factory-based container  Everything is a service, even Controllers  Can be created from:  Application configuration  Module classes  Useful if anon functions desired  Module configuration (most common)  No anon functions due to caching issues  Local override configuration  For times when vendor keys need over-written  Specified in application config
  • 25. Foundations of Zend Framework  Defining Services  Beware key name overwritting  Use fully qualified class name when applicable  MyAppControllerProductIndex  Or be descriptive  {module}-{name}  'product-category' instead of 'category'  All keys get normalized  AppControllerProductIndex == app-controller- product-index  Hierarchy of definitions  Module.php – initial  module.config.php over-rides Module.php  Local over-rides module.config.php
  • 26. Foundations of Zend Framework  Service Types  Types:  Services – Explicit  key => value pairs (string, boolean, float, object)  Invokables  key => class (class/object with no needed dependencies)  Factories  key => object (class/object with needed dependencies)  Aliases (name => some other name)  Abstract Factories (unknown services)  Scoped Containers (limit what can be created)  Shared (or not; you decide)
  • 27. Foundations of Zend Framework  Service Config Example /module/Application/config/module.config.php
  • 28. Foundations of Zend Framework  Service Module Example /module/Application/config/module.php
  • 29. Foundations of Zend Framework  Using Service Example /module/Application/Module.php /module/Application/view/layout/layout.phtml
  • 30. Foundations of Zend Framework  Using Service In Factory Example /module/Application/Factory/CategoryControllerFactory.php
  • 31. Foundations of Zend Framework  Module Manager
  • 32. Foundations of Zend Framework  Module Manager  Gets directives from application.config.php  Modules to load  Order is important if module depends on another  Where to find modules (convention found in)  Modules directory  Vendor directory  Loads each module  Module.php  For dynamic content/settings  module.config.php (if getConfig() in Module.php)  Over-rides Module.php  Then hand off to MvcEvent process to Bootstrap.
  • 33. Foundations of Zend Framework  Module Basics  Relative to a specific “problem”.  Logical separation of application functionality  Reusable  Removing a module doesn't kill the application  Contains everything specific to given module  Keep init() and onBootstrap() in modules light.  Do not add data to module structure.
  • 34. Foundations of Zend Framework  Module Contents  Contents  PHP Code  MVC Functionality  Library Code  Though better in Application or via Composer  May not be related to MVC  View scripts  Public assets (images, css, javascript)  More?
  • 35. Foundations of Zend Framework  Module Skeleton  Easy creation using Zend Skeleton Module  GitHub /zendframework/ZendSkeletonModule
  • 36. Foundations of Zend Framework  Other Things Worth Investigating  Views  Forms  Databases  Navigation  View Strategies (Action or Restful) Sorry, just not enough time in a regular talk.
  • 37. Foundations of Zend Framework  Resources  http://framework.zend.com  http://www.zend.com/en/services/training/course-catal og/zend-framework-2  http://www.zend.com/en/services/training/course-cata log/zend-framework-2-advanced  http://zendframework2.de/cheat-sheet.html  https://docs.zendframework.com/tutorials/migration/to-v 3/overview/  https://olegkrivtsov.github.io/using-zend-framework-3-bo ok/html/index.html
  • 38. Foundations of Zend Framework  Thank You!  Code: https://github.com/adamculp/foundations-zf2-talk Adam Culp http://www.geekyboy.com http://RunGeekRadio.com Twitter @adamculp