SlideShare uma empresa Scribd logo
1 de 35
Extending ZF &
Extending with ZF
By Ralph Schindler
Software Engineer, Zend Framework Team
Who is this guy?
    •Ralph Schindler
     PHP’er since 1998-ish, 3.0 days
     Software Engineer
     Zend Framework team since Jan 2008
     New Orleans born, currently reside in Austin, TX
    •Me on the interwebs:
     IRC:
        •Freenode - ralphschindler
        •EFNet - ralphschi / ralphs
     ralph.schindler@zend.com
     http://twitter.com/ralphschindler
     http://ralphschindler.com
     http://slideshare.com/ralphschindler
2
Who is this talk for?

    •Anyone who has an interest in extending ZF beyond it’s current
     capabilities
    •Anyone who has an existing infrastructure / library / framework
     that wants to enhance it with ZF functionality
    •People love Getting Things Done!




3
Extending ZF
      Lets explore ZF as an extensible library




4   Insert->Header & Footer
What is Zend Framework?
    •Released in March 2006
    •1.0 in July 1, 2007
    •Goals
      Don’t change PHP
      Use-at-will architecture
      Best practices
        •Object oriented / Design patterns
      High quality
        •Continuous integration
        •Proper versioning scheme
        •Backwards compatible minor releases
        •Predictable release cycle



5
Zend Framework Components
    •Many components
    •Different levels of optional
     coupling
      Infrastructure components
      Stand-alone components




6
What is an extension?
    •“Extending software” is the act of taking software and
     enhancing it with more specific or value added features
    •Extension is typically based around a pre-existing API
    •Extension software is typically not useful on its own




7
Extending before OO
    •Patched existing functions
     Managing .diff or .patch files
     Worked b/c when consuming a specific version of a library, then
      patching, typically not concerned with new versions of base library
    •Extended into an extension or plugin style framework
     Naming conventions
        •scripts
        •functions
     Registered callbacks
    •Dynamic code paths
     example: url name loaded a script with a specific name




8
Life in the OO fast lane
    •PHP5 has a very robust object model, exploit it
    •Object oriented code is well suited for “extensibility”
      Principal of polymorphic code
        •PHP is a single inheritance, multiple interface language
        •OO Libraries built with best practices in mind should be easy to extend
    •Patching is NO LONGER OK!
      Consumed libraries should have adopted a lifecycle
      Your software (should) have adopted a lifecycle
      You don’t want to manage a “patching” process
        •patch -> test -> update, patch -> test -> update
        •complexity grows exponentially for each patch




9
ZF’s Dual Nature API
     •Public “Consumable” API
      Public members (properties, methods, constants)
      Well defined use cases
      Very strict backwards compatibility rules
     •Protected “Extension” API
      Protected members (properties, methods)
      No private members
      Use cases include:
         •Overriding methods
         •Extending abstract classes or implementing interfaces
         •As defined as the original author has fore-thought




10
Extensibility as an Application Infrastructure
     •Use “extends” as a feature
      By extending base classes, they “plug into” a working system
     •Conventions also help serve the easy by which an extensions
      infrastructure
      Examples of extendable elements:
         •Zend_Controller_Action
         •Zend_Controller_Plugin, Zend_Controller_Action_Helper
         •Zend_Controller_View (.phtml files)
         •Zend_Controller_View_Helper
      Conventions that aid in ease of use:
         •ZF’s loader: PEAR naming convention assumed
         •ZF’s MVC system: placement of controller file, action method



11
ZF is coded for extensibility
     •No private members (unless private is required)
     •Methods kept as fairly small, discreet responsibilities
     •Public API fully tested, with very high levels of code coverage
     •All predictable use cases included in tests
     •The ultimate balancing act:
       Interfaces - the signature of the contract, no implementation
       Abstracts - the contract in a pseudo-implementation form
     •Low levels of coupling
       Coupling should be optional
       Should work in default use case, poke-yoke style




12
Examples of Extension as an Infrastructure




13
Examples of Extension as an Infrastructure
     •Zend_Controller
      class FooController extends Zend_Controller_Action
      FooController’s public function barAction()
      Placement of this file in a specific location
     •Zend_View_Helper
      My_View_Helper_Foo must implement Zend_View_Helper_Interface
      Must be placed inside the application/views/helpers/ directory,
       named as Foo.php
     •Zend_Controller_Action_Helper
      (same as above)
     •Zend_Application’s Resource_Module & Module_Autoloader
      Assume a particular directory structure, file name, & class name


14
Examples of Application Solution Components




15
Examples of Stand Alone Components




16
Extending Stand-Alone Components
     •Zend_Auth_Adapter_DbTable is well suited for this
      Extend any method, and place this adapter in your models folder (or
       library)
     •Any Service component that does not implement a feature you
      need
     •Components with adapter pattern:
      Zend_Cache_Frontend & Zend_Cache_Backend
      Zend_Auth_Adapter
      Extend Zend_Config for new formats
      Implement new Zend_View_Interface to support template engines




17
When it’s Hard To Extend ...
     •Complain
      File an issue describing the use case
     •Example: Zend_Auth_Adapter_DbTable
      authenticate() went from a rather long method to 6 shorter methods
      each method is responsible for a very discreet task as such each can
       be overridden to suite a new use case
      see revision r7598 of Zend Framework
        •~$ svn diff -c 7598 http://framework.zend.com/svn/framework/standard/
         trunk/library/Zend/Auth/Adapter/DbTable.php




18
Components well suited to extension
     •Adapter based components
      Zend_Auth_Adapter (interface driven)
      Zend_Cache_Frontend (interface driven)
      Zend_Cache_Backend (base class driven)
      Zend_Captcha_Adapter (base class driven)
      Zend_Db_Adapter (base class driven)
      Zend_Filter & Zend_Validate (interface driven)
      Zend_Form: Decorators, Elements (base class driven)
      Zend_Paginator_Adapter (interface driven)
      Zend_Queue_Adapter (interface driven)
      Zend_Service_Abstract (base class driven)
      Zend_Translate_Adapter (base class driven)
      Zend_View_Helper (interface & abstract driven)

19
Extending with ZF
Extending




                    20
Some Are Easier Than Others
     •All stand-alone, low-couple components can be used in any
      PHP5 setting provided ZF is at least in the include_path
     •To make things easy, use Zend_Autoloader, find a place:
      Project configuration area
      OR Project initialization or “bootstrap” area
      Worst case: create a static method you can call prior to using ZF
       components




21
Symfony
     •http://symfony-project.com
      inspired by RoR, features a convention based, tightly coupled set of
       infrastructure features (MVC layer)
     •2 common methods:
      ProjectConfiguration static method
         •Pro: available to all modules at all time
         •Con: must be called before consuming ZF component in actions
      App initialize() method
         •Pro: available on demand when the app is invoked, ZF everywhere, less
          action coding required
         •Con: must be done in each app configuration




22
Symfony: Where do you put ZF?




23
Symfony: ProjectConfiguration method
         config/ProjectConfiguration.class.php




24
Symfony: Using the ProjectConfiguration
      apps/{appName}/modules/{moduleName}/actions/actions.class.php




      apps/{appName}/modules/{moduleName}/templates/indexSuccess.php




25
Symfony: Proof that it works




26
Symfony: App initialization


      apps/{appName}/config/frontendConfiguration.class.php




27
Symfony: Using the App initialize method
      apps/{appName}/modules/{moduleName}/actions/actions.class.php




      apps/{appName}/modules/{moduleName}/templates/indexSuccess.php




28
CodeIgniter and others
     •CodeIgniter & homegrown frameworks
      http://codeigniter.com/
      conventions based, light-weight MVC style framework
     •Best method: register autoloader in correct place




29
CI: Where to put ZF?




30
CI: Register the autoloader

          application/config/autoload.php




31
CI: Just use it
           welcome.php controller




                    welcome view




32
CI: Proof it works




33
Any Frameworks




34
Thank you!
Questions? Comments?




                       35

Mais conteúdo relacionado

Mais procurados

Create a welcoming development environment on IBM i
Create a welcoming development environment on IBM iCreate a welcoming development environment on IBM i
Create a welcoming development environment on IBM iAlan Seiden
 
Organizing Your PHP Projects (2010 ConFoo)
Organizing Your PHP Projects (2010 ConFoo)Organizing Your PHP Projects (2010 ConFoo)
Organizing Your PHP Projects (2010 ConFoo)Paul Jones
 
From Zero to ZF: Your first zend framework project on ibm i
From Zero to ZF: Your first zend framework project on ibm iFrom Zero to ZF: Your first zend framework project on ibm i
From Zero to ZF: Your first zend framework project on ibm iAlan Seiden
 
Organinzing Your PHP Projects (2010 Memphis PHP)
Organinzing Your PHP Projects (2010 Memphis PHP)Organinzing Your PHP Projects (2010 Memphis PHP)
Organinzing Your PHP Projects (2010 Memphis PHP)Paul Jones
 
Web services on IBM i with PHP and Zend Framework
Web services on IBM i with PHP and Zend FrameworkWeb services on IBM i with PHP and Zend Framework
Web services on IBM i with PHP and Zend FrameworkAlan Seiden
 
The Solar Framework for PHP 5 (2010 Confoo)
The Solar Framework for PHP 5 (2010 Confoo)The Solar Framework for PHP 5 (2010 Confoo)
The Solar Framework for PHP 5 (2010 Confoo)Paul Jones
 
PHP on IBM i Tutorial
PHP on IBM i TutorialPHP on IBM i Tutorial
PHP on IBM i TutorialZendCon
 

Mais procurados (9)

Create a welcoming development environment on IBM i
Create a welcoming development environment on IBM iCreate a welcoming development environment on IBM i
Create a welcoming development environment on IBM i
 
Zend Framework
Zend FrameworkZend Framework
Zend Framework
 
Organizing Your PHP Projects (2010 ConFoo)
Organizing Your PHP Projects (2010 ConFoo)Organizing Your PHP Projects (2010 ConFoo)
Organizing Your PHP Projects (2010 ConFoo)
 
From Zero to ZF: Your first zend framework project on ibm i
From Zero to ZF: Your first zend framework project on ibm iFrom Zero to ZF: Your first zend framework project on ibm i
From Zero to ZF: Your first zend framework project on ibm i
 
Organinzing Your PHP Projects (2010 Memphis PHP)
Organinzing Your PHP Projects (2010 Memphis PHP)Organinzing Your PHP Projects (2010 Memphis PHP)
Organinzing Your PHP Projects (2010 Memphis PHP)
 
Web services on IBM i with PHP and Zend Framework
Web services on IBM i with PHP and Zend FrameworkWeb services on IBM i with PHP and Zend Framework
Web services on IBM i with PHP and Zend Framework
 
The Solar Framework for PHP 5 (2010 Confoo)
The Solar Framework for PHP 5 (2010 Confoo)The Solar Framework for PHP 5 (2010 Confoo)
The Solar Framework for PHP 5 (2010 Confoo)
 
Developing better PHP projects
Developing better PHP projectsDeveloping better PHP projects
Developing better PHP projects
 
PHP on IBM i Tutorial
PHP on IBM i TutorialPHP on IBM i Tutorial
PHP on IBM i Tutorial
 

Semelhante a Extending ZF & Extending With ZF

Semelhante a Extending ZF & Extending With ZF (20)

green
greengreen
green
 
Extending Zend_Tool
Extending Zend_ToolExtending Zend_Tool
Extending Zend_Tool
 
Unit Test for ZF SlideShare Component
Unit Test for ZF SlideShare ComponentUnit Test for ZF SlideShare Component
Unit Test for ZF SlideShare Component
 
Zend MVC pattern based Framework – Best for Enterprise web applications
Zend MVC pattern based Framework – Best for Enterprise web applicationsZend MVC pattern based Framework – Best for Enterprise web applications
Zend MVC pattern based Framework – Best for Enterprise web applications
 
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
 
organic
organicorganic
organic
 
first pitch
first pitchfirst pitch
first pitch
 
latest slide
latest slidelatest slide
latest slide
 
345
345345
345
 
before upload
before uploadbefore upload
before upload
 
Unit Test for ZF SlideShare Component
Unit Test for ZF SlideShare ComponentUnit Test for ZF SlideShare Component
Unit Test for ZF SlideShare Component
 
sadasd
sadasdsadasd
sadasd
 

Mais de Ralph Schindler

Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2Ralph Schindler
 
Zend_Tool In ZF 1.8 Webinar
Zend_Tool In ZF 1.8 WebinarZend_Tool In ZF 1.8 Webinar
Zend_Tool In ZF 1.8 WebinarRalph Schindler
 
Zend Framework 1.8 Features Webinar
Zend Framework 1.8 Features WebinarZend Framework 1.8 Features Webinar
Zend Framework 1.8 Features WebinarRalph Schindler
 
Software Engineering In PHP
Software Engineering In PHPSoftware Engineering In PHP
Software Engineering In PHPRalph Schindler
 
Zend_Layout & Zend_View Enhancements
Zend_Layout & Zend_View EnhancementsZend_Layout & Zend_View Enhancements
Zend_Layout & Zend_View EnhancementsRalph Schindler
 
Zend_Tool: Rapid Application Development with Zend Framework
Zend_Tool: Rapid Application Development with Zend FrameworkZend_Tool: Rapid Application Development with Zend Framework
Zend_Tool: Rapid Application Development with Zend FrameworkRalph Schindler
 

Mais de Ralph Schindler (10)

Zend Di in ZF 2.0
Zend Di in ZF 2.0Zend Di in ZF 2.0
Zend Di in ZF 2.0
 
Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2
 
484 Days of PHP 5.3
484 Days of PHP 5.3484 Days of PHP 5.3
484 Days of PHP 5.3
 
Modeling best practices
Modeling best practicesModeling best practices
Modeling best practices
 
What's New in ZF 1.10
What's New in ZF 1.10What's New in ZF 1.10
What's New in ZF 1.10
 
Zend_Tool In ZF 1.8 Webinar
Zend_Tool In ZF 1.8 WebinarZend_Tool In ZF 1.8 Webinar
Zend_Tool In ZF 1.8 Webinar
 
Zend Framework 1.8 Features Webinar
Zend Framework 1.8 Features WebinarZend Framework 1.8 Features Webinar
Zend Framework 1.8 Features Webinar
 
Software Engineering In PHP
Software Engineering In PHPSoftware Engineering In PHP
Software Engineering In PHP
 
Zend_Layout & Zend_View Enhancements
Zend_Layout & Zend_View EnhancementsZend_Layout & Zend_View Enhancements
Zend_Layout & Zend_View Enhancements
 
Zend_Tool: Rapid Application Development with Zend Framework
Zend_Tool: Rapid Application Development with Zend FrameworkZend_Tool: Rapid Application Development with Zend Framework
Zend_Tool: Rapid Application Development with Zend Framework
 

Último

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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
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
 
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
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
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
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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 WorkerThousandEyes
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
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
 

Último (20)

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...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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
 
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...
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
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
 

Extending ZF & Extending With ZF

  • 1. Extending ZF & Extending with ZF By Ralph Schindler Software Engineer, Zend Framework Team
  • 2. Who is this guy? •Ralph Schindler PHP’er since 1998-ish, 3.0 days Software Engineer Zend Framework team since Jan 2008 New Orleans born, currently reside in Austin, TX •Me on the interwebs: IRC: •Freenode - ralphschindler •EFNet - ralphschi / ralphs ralph.schindler@zend.com http://twitter.com/ralphschindler http://ralphschindler.com http://slideshare.com/ralphschindler 2
  • 3. Who is this talk for? •Anyone who has an interest in extending ZF beyond it’s current capabilities •Anyone who has an existing infrastructure / library / framework that wants to enhance it with ZF functionality •People love Getting Things Done! 3
  • 4. Extending ZF Lets explore ZF as an extensible library 4 Insert->Header & Footer
  • 5. What is Zend Framework? •Released in March 2006 •1.0 in July 1, 2007 •Goals Don’t change PHP Use-at-will architecture Best practices •Object oriented / Design patterns High quality •Continuous integration •Proper versioning scheme •Backwards compatible minor releases •Predictable release cycle 5
  • 6. Zend Framework Components •Many components •Different levels of optional coupling Infrastructure components Stand-alone components 6
  • 7. What is an extension? •“Extending software” is the act of taking software and enhancing it with more specific or value added features •Extension is typically based around a pre-existing API •Extension software is typically not useful on its own 7
  • 8. Extending before OO •Patched existing functions Managing .diff or .patch files Worked b/c when consuming a specific version of a library, then patching, typically not concerned with new versions of base library •Extended into an extension or plugin style framework Naming conventions •scripts •functions Registered callbacks •Dynamic code paths example: url name loaded a script with a specific name 8
  • 9. Life in the OO fast lane •PHP5 has a very robust object model, exploit it •Object oriented code is well suited for “extensibility” Principal of polymorphic code •PHP is a single inheritance, multiple interface language •OO Libraries built with best practices in mind should be easy to extend •Patching is NO LONGER OK! Consumed libraries should have adopted a lifecycle Your software (should) have adopted a lifecycle You don’t want to manage a “patching” process •patch -> test -> update, patch -> test -> update •complexity grows exponentially for each patch 9
  • 10. ZF’s Dual Nature API •Public “Consumable” API Public members (properties, methods, constants) Well defined use cases Very strict backwards compatibility rules •Protected “Extension” API Protected members (properties, methods) No private members Use cases include: •Overriding methods •Extending abstract classes or implementing interfaces •As defined as the original author has fore-thought 10
  • 11. Extensibility as an Application Infrastructure •Use “extends” as a feature By extending base classes, they “plug into” a working system •Conventions also help serve the easy by which an extensions infrastructure Examples of extendable elements: •Zend_Controller_Action •Zend_Controller_Plugin, Zend_Controller_Action_Helper •Zend_Controller_View (.phtml files) •Zend_Controller_View_Helper Conventions that aid in ease of use: •ZF’s loader: PEAR naming convention assumed •ZF’s MVC system: placement of controller file, action method 11
  • 12. ZF is coded for extensibility •No private members (unless private is required) •Methods kept as fairly small, discreet responsibilities •Public API fully tested, with very high levels of code coverage •All predictable use cases included in tests •The ultimate balancing act: Interfaces - the signature of the contract, no implementation Abstracts - the contract in a pseudo-implementation form •Low levels of coupling Coupling should be optional Should work in default use case, poke-yoke style 12
  • 13. Examples of Extension as an Infrastructure 13
  • 14. Examples of Extension as an Infrastructure •Zend_Controller class FooController extends Zend_Controller_Action FooController’s public function barAction() Placement of this file in a specific location •Zend_View_Helper My_View_Helper_Foo must implement Zend_View_Helper_Interface Must be placed inside the application/views/helpers/ directory, named as Foo.php •Zend_Controller_Action_Helper (same as above) •Zend_Application’s Resource_Module & Module_Autoloader Assume a particular directory structure, file name, & class name 14
  • 15. Examples of Application Solution Components 15
  • 16. Examples of Stand Alone Components 16
  • 17. Extending Stand-Alone Components •Zend_Auth_Adapter_DbTable is well suited for this Extend any method, and place this adapter in your models folder (or library) •Any Service component that does not implement a feature you need •Components with adapter pattern: Zend_Cache_Frontend & Zend_Cache_Backend Zend_Auth_Adapter Extend Zend_Config for new formats Implement new Zend_View_Interface to support template engines 17
  • 18. When it’s Hard To Extend ... •Complain File an issue describing the use case •Example: Zend_Auth_Adapter_DbTable authenticate() went from a rather long method to 6 shorter methods each method is responsible for a very discreet task as such each can be overridden to suite a new use case see revision r7598 of Zend Framework •~$ svn diff -c 7598 http://framework.zend.com/svn/framework/standard/ trunk/library/Zend/Auth/Adapter/DbTable.php 18
  • 19. Components well suited to extension •Adapter based components Zend_Auth_Adapter (interface driven) Zend_Cache_Frontend (interface driven) Zend_Cache_Backend (base class driven) Zend_Captcha_Adapter (base class driven) Zend_Db_Adapter (base class driven) Zend_Filter & Zend_Validate (interface driven) Zend_Form: Decorators, Elements (base class driven) Zend_Paginator_Adapter (interface driven) Zend_Queue_Adapter (interface driven) Zend_Service_Abstract (base class driven) Zend_Translate_Adapter (base class driven) Zend_View_Helper (interface & abstract driven) 19
  • 21. Some Are Easier Than Others •All stand-alone, low-couple components can be used in any PHP5 setting provided ZF is at least in the include_path •To make things easy, use Zend_Autoloader, find a place: Project configuration area OR Project initialization or “bootstrap” area Worst case: create a static method you can call prior to using ZF components 21
  • 22. Symfony •http://symfony-project.com inspired by RoR, features a convention based, tightly coupled set of infrastructure features (MVC layer) •2 common methods: ProjectConfiguration static method •Pro: available to all modules at all time •Con: must be called before consuming ZF component in actions App initialize() method •Pro: available on demand when the app is invoked, ZF everywhere, less action coding required •Con: must be done in each app configuration 22
  • 23. Symfony: Where do you put ZF? 23
  • 24. Symfony: ProjectConfiguration method config/ProjectConfiguration.class.php 24
  • 25. Symfony: Using the ProjectConfiguration apps/{appName}/modules/{moduleName}/actions/actions.class.php apps/{appName}/modules/{moduleName}/templates/indexSuccess.php 25
  • 26. Symfony: Proof that it works 26
  • 27. Symfony: App initialization apps/{appName}/config/frontendConfiguration.class.php 27
  • 28. Symfony: Using the App initialize method apps/{appName}/modules/{moduleName}/actions/actions.class.php apps/{appName}/modules/{moduleName}/templates/indexSuccess.php 28
  • 29. CodeIgniter and others •CodeIgniter & homegrown frameworks http://codeigniter.com/ conventions based, light-weight MVC style framework •Best method: register autoloader in correct place 29
  • 30. CI: Where to put ZF? 30
  • 31. CI: Register the autoloader application/config/autoload.php 31
  • 32. CI: Just use it welcome.php controller welcome view 32
  • 33. CI: Proof it works 33