SlideShare a Scribd company logo
October 2011




Skynet in ZF 2.0
Or, better put “what one can do with ZendCode”
Who Am I?


    •Ralph Schindler (ralphschindler)
     Software Engineer on the Zend Framework team
      •At Zend for almost 4 years
      •Before that TippingPoint/3Com
    Programming PHP for 13+ years
    Live in New Orleans, LA.
      •Lived in Austin, Tx for 5 years




2
Why Skynet?


    •From wikipedia:

    “ ... an artificially intelligent system which
     became self-aware and revolted against its
     creators.”

    “The strategy behind Skynet's creation was to
     remove the possibility of human error and slow
     reaction time to guarantee fast, efficient response
     to enemy attack.”

3
Why Skynet?

    •So, ... who is the enemy?




4
Why Skynet?


    •Other enemies (without photo’s)
     Unmaintainable applications
     Untestable applications
     Slow applications
     Un-fun / boring code
     Painful code




5
Why Skynet?


    •So, what does Skynet look like?
    •Anything we develop that looks
     too magical
     too-good-to-be-true
     too all-encompassing
     too flexible / too many input types
     requires too much documentation
     is outside our normal understanding of how things
     work


6
Why Skynet?


    •What does Skynet not look like?
     Simple
     Easy to understand
     Finite inputs / outputs
     Easy to get up and running with




7
Why Skynet


    •In a nutshell: PHP
     PHP has no development time compile phase
     On it’s own, it doesn’t know much
     •Hence, the many upon many frameworks
    All decisions are pushed into “request” time
    Single strategy for performance increase
     •caching
     •black-box optimizer




8
Why Skynet?


    •Basically, ZendCode is Skynet (figuratively)
     it can understand your code, sometimes better
     than the developer whom wrote it
     it can expose information about your code that the
     developer was unaware of
     it can generate code faster than you can




9
Why Skynet?


     •Ok, not really
     •ZendCode will not:
      see developers as a threat
      attempt to take over the world
      send the Terminator (a.k.a Matthew Weier
      O’Phinney) after you for writing bad,
      unmaintainable, code




10
Who is the Terminator?




11
What does ZendCode Do?




     •So, what does ZendCode do?




12
Let’s Recap the Humble Beginnings


     •ZF1 users wanted scaffolding & RAD
     •So, ...
      Zend_Tool
       •Zend_Tool_Project / Zend_Tool_Framework
      Zend_CodeGenerator
       •original intention was more than PHP
      Zend_Reflection
       •added docblock parsing functionality



13
ZF1 Problem Area


     •This setup suffered from 2 major problems:
      Runtime dependencies are not always loaded
      Same request changes to structures do not update
      in-memory structures




14
Problem 1




15
Problem 2


     •Workflow (in the same request):
      Require File
      Build ZendCodeGenerator object based off Zend
      Reflection object of a class
       •(For example a controller)
     Add method to class
     Write to disk
     Build ZendCodeGenerator object based off Zend
      Reflection object
       •FAIL! B/c file is already in memory

16
Problem 2 - Temporary Solution


     •Temporary solution was to cache generator
      objects that were built based one particular
      reflection objects, and return those when asked
      for a generator object seeded with a known
      reflection object

     •“We’ll fix this in ZF2”




17
Other Realizations


     •We were not going to get other generator types
     •Generators were closely related to Reflection
      and the new Scanner component
     •ZendCode was a better place for all of this




18
Static vs. Dynamic


     •Runtime
      Static - Fast
      Dynamic - Slow


     •Dev-time
      Static - slower workflow
      Dynamic - workflow resembles runtime




19
Static vs. Dynamic


     •Typical PHP workflow for dynamic applications:



                           initiate request

                            fulfill request

                          return to consumer


20
Static vs. Dynamic


     •Typical PHP workflow for “static” applications
      with compilation built in (dev time):

                           initiate request

      compile (during request, but omitted during production)


                            fulfill request

                          return to consumer
21
Static vs. Dynamic


     •Typical PHP workflow for “static” applications
      with compilation NOT built in (dev time):

                            (change code)
                           (compile code)

                            initiate request
                             fulfill request
                          return to consumer

22
Static vs. Dynamic

     •You’ve probably seen static analysis in some way before:
      Caching
       •If you never intend on expiring the data, it’s not really a cache
      if (!file_exists(..)) { file_put_contents(..., var_export()) }
      Zend Optimizer / APC
      Content Platforms:
       •Drupal
         – development mode
         – non-caching mode
         – module initialization
       •Wordpress
         – installation hooks: plugin initialization




23
What are we compiling?


     •Anything dynamically looked up
      What the valid routes are
      What the valid application assets are
       •classes
       •view scripts
     Where particular classes are located


     More?
       •Which extensions are loaded
       •What the php environment can support
24
So, What Is Our Toolset?


     •ZendCode
      ZendCodeReflection
      ZendCodeGenerator
      ZendCodeScanner
      ZendCodeAnnotation




25
ZendCodeReflection


     •Originally part of ZF1
     •Added features:
      file reflection
      docblock reflection




26
ZendCodeReflection




27
ZendCodeReflection cont’




28
ZendCodeGenerator


     •Originally ZF 1’s ZendCodeGenerator
     •Built OO Classes with an OO API
      Mainly consumed by Zend_Tool




29
ZendCode
     Generator




30
ZendCodeScanner


     •ZendCodeScanner
      Token based “reflection”
      Reflection for files in ZF1 has a similar approach
      Ascertain information in files:
       •what namespaces are inside this file
       •what use statements are inside a particular namespace
       •what classes are in this file’s namespaces
       •what files are required (none, right?)
       •is there a file level docblock


31
ZendCodeScanner Class Hierarchy




32
ZendCode
     Scanner (Sample)




33
ZendCodeAnnotation


     •Annotations
      Why? You asked for it. At least some of you did.
      There’s no native PHP support for it
      Similar to:
       •Java’s Annotation system
       •C#’s Attribute system
       •Doctrine’s Annotation system
       •with a PHP twist of course




34
ZendCodeAnnotation

     •Design:
     Do not force content into a particular DSL
     Build as a simple easy to use framework for easy consumption
     Prototype pattern
     Use ZendCodeScanner
     •Drawbacks
     Slow, very very slow




35
ZendCodeAnnotation

     •Single Interface to implement:
      ZendCodeAnnotationAnnotation




36
ZendCodeAnnotationManager

     •Simple Manager to Populate:




37
Demo 1: ZendCodeScanner

     •Find all dependencies in a directory full of code


     •Demo




38
Demo 2: Built a Micro-framework

     •Goals
     Find on github.com/ralphschindler/middlewarephp
     few classes - the “middleware” is editable
     fast (2ms request for hello world)
     compilation based
       •Routes
       •Classmap autoloader
     annotation based
     utilize include returns, closures, and arrays


     •Demo



39
Philisophical



     •Let’s get philosophical:
      Should we be “compiling” elements?
       •Is this what PHP is all about?
       •Rasmus says yes.
      Can we architect flexible and performant
      applications without some kind of static code
      analysis that affects runtime?
      How do we introduce these tasks into developer
      workflows where they make the most sense, don’t
      impede development?
40
Fin




     •Questions and/or comments, let’s go grab a beer discuss.
     •Remember ZF2 is only beta, if you have opinions on how we
      should go about applying these techniques, get involved NOW!


     •Thank you!




41
Ad

More Related Content

What's hot (20)

PHP Frameworks Review - Mar 19 2015
PHP Frameworks Review - Mar 19 2015PHP Frameworks Review - Mar 19 2015
PHP Frameworks Review - Mar 19 2015
kyphpug
 
Go - A Key Language in Enterprise Application Development?
Go - A Key Language in Enterprise Application Development?Go - A Key Language in Enterprise Application Development?
Go - A Key Language in Enterprise Application Development?
C4Media
 
Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®
Hannes Lowette
 
PHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM iPHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM i
Alan Seiden
 
Getting started with PHP on IBM i
Getting started with PHP on IBM iGetting started with PHP on IBM i
Getting started with PHP on IBM i
Zend by Rogue Wave Software
 
Zend Products and PHP for IBMi
Zend Products and PHP for IBMi  Zend Products and PHP for IBMi
Zend Products and PHP for IBMi
Shlomo Vanunu
 
Extending ZF & Extending With ZF
Extending ZF & Extending With ZFExtending ZF & Extending With ZF
Extending ZF & Extending With ZF
Ralph Schindler
 
Sunshine php practical-zf1-zf2-migration
Sunshine php practical-zf1-zf2-migrationSunshine php practical-zf1-zf2-migration
Sunshine php practical-zf1-zf2-migration
Clark Everetts
 
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Arnaud Bouchez
 
A Lap Around Visual Studio 11
A Lap Around Visual Studio 11A Lap Around Visual Studio 11
A Lap Around Visual Studio 11
Chad Green
 
The Architect Way - JSCamp.asia 2012
The Architect Way - JSCamp.asia 2012The Architect Way - JSCamp.asia 2012
The Architect Way - JSCamp.asia 2012
Jan Jongboom
 
Zend
ZendZend
Zend
marcosTedsys
 
Zend con practical-zf1-zf2-migration
Zend con practical-zf1-zf2-migrationZend con practical-zf1-zf2-migration
Zend con practical-zf1-zf2-migration
Clark Everetts
 
PHP on IBM i Tutorial
PHP on IBM i TutorialPHP on IBM i Tutorial
PHP on IBM i Tutorial
ZendCon
 
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
 
Developing better PHP projects
Developing better PHP projectsDeveloping better PHP projects
Developing better PHP projects
Mohammad Emran Hasan
 
Enterprise PHP
Enterprise PHPEnterprise PHP
Enterprise PHP
Mohammad Emran Hasan
 
Zend Framework
Zend FrameworkZend Framework
Zend Framework
John Coggeshall
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
Ganesh Kondal
 
Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)
Martijn Verburg
 
PHP Frameworks Review - Mar 19 2015
PHP Frameworks Review - Mar 19 2015PHP Frameworks Review - Mar 19 2015
PHP Frameworks Review - Mar 19 2015
kyphpug
 
Go - A Key Language in Enterprise Application Development?
Go - A Key Language in Enterprise Application Development?Go - A Key Language in Enterprise Application Development?
Go - A Key Language in Enterprise Application Development?
C4Media
 
Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®Build software like a bag of marbles, not a castle of LEGO®
Build software like a bag of marbles, not a castle of LEGO®
Hannes Lowette
 
PHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM iPHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM i
Alan Seiden
 
Zend Products and PHP for IBMi
Zend Products and PHP for IBMi  Zend Products and PHP for IBMi
Zend Products and PHP for IBMi
Shlomo Vanunu
 
Extending ZF & Extending With ZF
Extending ZF & Extending With ZFExtending ZF & Extending With ZF
Extending ZF & Extending With ZF
Ralph Schindler
 
Sunshine php practical-zf1-zf2-migration
Sunshine php practical-zf1-zf2-migrationSunshine php practical-zf1-zf2-migration
Sunshine php practical-zf1-zf2-migration
Clark Everetts
 
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Ekon20 mORMot Legacy Code Technical Debt Delphi Conference
Arnaud Bouchez
 
A Lap Around Visual Studio 11
A Lap Around Visual Studio 11A Lap Around Visual Studio 11
A Lap Around Visual Studio 11
Chad Green
 
The Architect Way - JSCamp.asia 2012
The Architect Way - JSCamp.asia 2012The Architect Way - JSCamp.asia 2012
The Architect Way - JSCamp.asia 2012
Jan Jongboom
 
Zend con practical-zf1-zf2-migration
Zend con practical-zf1-zf2-migrationZend con practical-zf1-zf2-migration
Zend con practical-zf1-zf2-migration
Clark Everetts
 
PHP on IBM i Tutorial
PHP on IBM i TutorialPHP on IBM i Tutorial
PHP on IBM i Tutorial
ZendCon
 
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
 
Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5Tech io spa_angularjs_20130814_v0.9.5
Tech io spa_angularjs_20130814_v0.9.5
Ganesh Kondal
 
Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)
Martijn Verburg
 

Similar to Zend Code in ZF 2.0 (20)

Tooling for the JavaScript Era
Tooling for the JavaScript EraTooling for the JavaScript Era
Tooling for the JavaScript Era
martinlippert
 
The Architect Way
The Architect WayThe Architect Way
The Architect Way
Jan Jongboom
 
Devconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developedDevconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developed
Alexander Makarov
 
Zend Di in ZF 2.0
Zend Di in ZF 2.0Zend Di in ZF 2.0
Zend Di in ZF 2.0
Ralph Schindler
 
Zend Framwork configurations
Zend Framwork configurationsZend Framwork configurations
Zend Framwork configurations
Uva Wellassa University
 
Writing Services with ZF2
Writing Services with ZF2Writing Services with ZF2
Writing Services with ZF2
Mike Willbanks
 
Zend Framwork presentation
Zend Framwork presentationZend Framwork presentation
Zend Framwork presentation
Uva Wellassa University
 
August Webinar - Water Cooler Talks: A Look into a Developer's Workbench
August Webinar - Water Cooler Talks: A Look into a Developer's WorkbenchAugust Webinar - Water Cooler Talks: A Look into a Developer's Workbench
August Webinar - Water Cooler Talks: A Look into a Developer's Workbench
Howard Greenberg
 
Talent42 2014 Sam Wholley -
Talent42 2014 Sam Wholley - Talent42 2014 Sam Wholley -
Talent42 2014 Sam Wholley -
Talent42
 
Xcode, Basics and Beyond
Xcode, Basics and BeyondXcode, Basics and Beyond
Xcode, Basics and Beyond
rsebbe
 
130511 stop wasting_your_time
130511 stop wasting_your_time130511 stop wasting_your_time
130511 stop wasting_your_time
Henning Blohm
 
Extending Zend_Tool
Extending Zend_ToolExtending Zend_Tool
Extending Zend_Tool
Ralph Schindler
 
Symfony2 for legacy app rejuvenation: the eZ Publish case study
Symfony2 for legacy app rejuvenation: the eZ Publish case studySymfony2 for legacy app rejuvenation: the eZ Publish case study
Symfony2 for legacy app rejuvenation: the eZ Publish case study
Gaetano Giunta
 
SD PHP Zend Framework
SD PHP Zend FrameworkSD PHP Zend Framework
SD PHP Zend Framework
philipjting
 
Continuous Integration In A PHP World
Continuous Integration In A PHP WorldContinuous Integration In A PHP World
Continuous Integration In A PHP World
Idaf_1er
 
PHP Framework Battle
PHP Framework BattlePHP Framework Battle
PHP Framework Battle
Achievers Tech
 
High performance PHP: Scaling and getting the most out of your infrastructure
High performance PHP: Scaling and getting the most out of your infrastructureHigh performance PHP: Scaling and getting the most out of your infrastructure
High performance PHP: Scaling and getting the most out of your infrastructure
mkherlakian
 
Scaling with Symfony - PHP UK
Scaling with Symfony - PHP UKScaling with Symfony - PHP UK
Scaling with Symfony - PHP UK
Ricard Clau
 
Zend Framework 2, What's new, Confoo 2011
Zend Framework 2, What's new, Confoo 2011Zend Framework 2, What's new, Confoo 2011
Zend Framework 2, What's new, Confoo 2011
Bachkoutou Toutou
 
Get your Project back in Shape!
Get your Project back in Shape!Get your Project back in Shape!
Get your Project back in Shape!
Joachim Tuchel
 
Tooling for the JavaScript Era
Tooling for the JavaScript EraTooling for the JavaScript Era
Tooling for the JavaScript Era
martinlippert
 
Devconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developedDevconf 2011 - PHP - How Yii framework is developed
Devconf 2011 - PHP - How Yii framework is developed
Alexander Makarov
 
Writing Services with ZF2
Writing Services with ZF2Writing Services with ZF2
Writing Services with ZF2
Mike Willbanks
 
August Webinar - Water Cooler Talks: A Look into a Developer's Workbench
August Webinar - Water Cooler Talks: A Look into a Developer's WorkbenchAugust Webinar - Water Cooler Talks: A Look into a Developer's Workbench
August Webinar - Water Cooler Talks: A Look into a Developer's Workbench
Howard Greenberg
 
Talent42 2014 Sam Wholley -
Talent42 2014 Sam Wholley - Talent42 2014 Sam Wholley -
Talent42 2014 Sam Wholley -
Talent42
 
Xcode, Basics and Beyond
Xcode, Basics and BeyondXcode, Basics and Beyond
Xcode, Basics and Beyond
rsebbe
 
130511 stop wasting_your_time
130511 stop wasting_your_time130511 stop wasting_your_time
130511 stop wasting_your_time
Henning Blohm
 
Symfony2 for legacy app rejuvenation: the eZ Publish case study
Symfony2 for legacy app rejuvenation: the eZ Publish case studySymfony2 for legacy app rejuvenation: the eZ Publish case study
Symfony2 for legacy app rejuvenation: the eZ Publish case study
Gaetano Giunta
 
SD PHP Zend Framework
SD PHP Zend FrameworkSD PHP Zend Framework
SD PHP Zend Framework
philipjting
 
Continuous Integration In A PHP World
Continuous Integration In A PHP WorldContinuous Integration In A PHP World
Continuous Integration In A PHP World
Idaf_1er
 
High performance PHP: Scaling and getting the most out of your infrastructure
High performance PHP: Scaling and getting the most out of your infrastructureHigh performance PHP: Scaling and getting the most out of your infrastructure
High performance PHP: Scaling and getting the most out of your infrastructure
mkherlakian
 
Scaling with Symfony - PHP UK
Scaling with Symfony - PHP UKScaling with Symfony - PHP UK
Scaling with Symfony - PHP UK
Ricard Clau
 
Zend Framework 2, What's new, Confoo 2011
Zend Framework 2, What's new, Confoo 2011Zend Framework 2, What's new, Confoo 2011
Zend Framework 2, What's new, Confoo 2011
Bachkoutou Toutou
 
Get your Project back in Shape!
Get your Project back in Shape!Get your Project back in Shape!
Get your Project back in Shape!
Joachim Tuchel
 
Ad

More from Ralph Schindler (9)

Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2
Ralph Schindler
 
Modeling best practices
Modeling best practicesModeling best practices
Modeling best practices
Ralph Schindler
 
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
Ralph 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 Webinar
Ralph Schindler
 
Zend Framework 1.8 Features Webinar
Zend Framework 1.8 Features WebinarZend Framework 1.8 Features Webinar
Zend Framework 1.8 Features Webinar
Ralph Schindler
 
Software Engineering In PHP
Software Engineering In PHPSoftware Engineering In PHP
Software Engineering In PHP
Ralph Schindler
 
Zend_Layout & Zend_View Enhancements
Zend_Layout & Zend_View EnhancementsZend_Layout & Zend_View Enhancements
Zend_Layout & Zend_View Enhancements
Ralph 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 Framework
Ralph Schindler
 
Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2
Ralph 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 Webinar
Ralph Schindler
 
Zend Framework 1.8 Features Webinar
Zend Framework 1.8 Features WebinarZend Framework 1.8 Features Webinar
Zend Framework 1.8 Features Webinar
Ralph Schindler
 
Software Engineering In PHP
Software Engineering In PHPSoftware Engineering In PHP
Software Engineering In PHP
Ralph Schindler
 
Zend_Layout & Zend_View Enhancements
Zend_Layout & Zend_View EnhancementsZend_Layout & Zend_View Enhancements
Zend_Layout & Zend_View Enhancements
Ralph 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 Framework
Ralph Schindler
 
Ad

Recently uploaded (20)

Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
Agentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community MeetupAgentic Automation - Delhi UiPath Community Meetup
Agentic Automation - Delhi UiPath Community Meetup
Manoj Batra (1600 + Connections)
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
IT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information TechnologyIT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information Technology
SHEHABALYAMANI
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Mike Mingos
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à GenèveUiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPathCommunity
 
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
SOFTTECHHUB
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Maarten Verwaest
 
An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient CareAn Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
Cyntexa
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 
Q1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor PresentationQ1 2025 Dropbox Earnings and Investor Presentation
Q1 2025 Dropbox Earnings and Investor Presentation
Dropbox
 
Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)Design pattern talk by Kaya Weers - 2025 (v2)
Design pattern talk by Kaya Weers - 2025 (v2)
Kaya Weers
 
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Everything You Need to Know About Agentforce? (Put AI Agents to Work)
Cyntexa
 
Cybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and MitigationCybersecurity Threat Vectors and Mitigation
Cybersecurity Threat Vectors and Mitigation
VICTOR MAESTRE RAMIREZ
 
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
GDG Cloud Southlake #42: Suresh Mathew: Autonomous Resource Optimization: How...
James Anderson
 
IT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information TechnologyIT484 Cyber Forensics_Information Technology
IT484 Cyber Forensics_Information Technology
SHEHABALYAMANI
 
Viam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdfViam product demo_ Deploying and scaling AI with hardware.pdf
Viam product demo_ Deploying and scaling AI with hardware.pdf
camilalamoratta
 
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptxReimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
Reimagine How You and Your Team Work with Microsoft 365 Copilot.pptx
John Moore
 
Mastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B LandscapeMastering Testing in the Modern F&B Landscape
Mastering Testing in the Modern F&B Landscape
marketing943205
 
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Optima Cyber - Maritime Cyber Security - MSSP Services - Manolis Sfakianakis ...
Mike Mingos
 
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Challenges in Migrating Imperative Deep Learning Programs to Graph Execution:...
Raffi Khatchadourian
 
Developing System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptxDeveloping System Infrastructure Design Plan.pptx
Developing System Infrastructure Design Plan.pptx
wondimagegndesta
 
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Integrating FME with Python: Tips, Demos, and Best Practices for Powerful Aut...
Safe Software
 
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à GenèveUiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPath Automation Suite – Cas d'usage d'une NGO internationale basée à Genève
UiPathCommunity
 
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
The No-Code Way to Build a Marketing Team with One AI Agent (Download the n8n...
SOFTTECHHUB
 
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Enterprise Integration Is Dead! Long Live AI-Driven Integration with Apache C...
Markus Eisele
 
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Limecraft Webinar - 2025.3 release, featuring Content Delivery, Graphic Conte...
Maarten Verwaest
 
An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient CareAn Overview of Salesforce Health Cloud & How is it Transforming Patient Care
An Overview of Salesforce Health Cloud & How is it Transforming Patient Care
Cyntexa
 
AsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API DesignAsyncAPI v3 : Streamlining Event-Driven API Design
AsyncAPI v3 : Streamlining Event-Driven API Design
leonid54
 

Zend Code in ZF 2.0

  • 1. October 2011 Skynet in ZF 2.0 Or, better put “what one can do with ZendCode”
  • 2. Who Am I? •Ralph Schindler (ralphschindler) Software Engineer on the Zend Framework team •At Zend for almost 4 years •Before that TippingPoint/3Com Programming PHP for 13+ years Live in New Orleans, LA. •Lived in Austin, Tx for 5 years 2
  • 3. Why Skynet? •From wikipedia: “ ... an artificially intelligent system which became self-aware and revolted against its creators.” “The strategy behind Skynet's creation was to remove the possibility of human error and slow reaction time to guarantee fast, efficient response to enemy attack.” 3
  • 4. Why Skynet? •So, ... who is the enemy? 4
  • 5. Why Skynet? •Other enemies (without photo’s) Unmaintainable applications Untestable applications Slow applications Un-fun / boring code Painful code 5
  • 6. Why Skynet? •So, what does Skynet look like? •Anything we develop that looks too magical too-good-to-be-true too all-encompassing too flexible / too many input types requires too much documentation is outside our normal understanding of how things work 6
  • 7. Why Skynet? •What does Skynet not look like? Simple Easy to understand Finite inputs / outputs Easy to get up and running with 7
  • 8. Why Skynet •In a nutshell: PHP PHP has no development time compile phase On it’s own, it doesn’t know much •Hence, the many upon many frameworks All decisions are pushed into “request” time Single strategy for performance increase •caching •black-box optimizer 8
  • 9. Why Skynet? •Basically, ZendCode is Skynet (figuratively) it can understand your code, sometimes better than the developer whom wrote it it can expose information about your code that the developer was unaware of it can generate code faster than you can 9
  • 10. Why Skynet? •Ok, not really •ZendCode will not: see developers as a threat attempt to take over the world send the Terminator (a.k.a Matthew Weier O’Phinney) after you for writing bad, unmaintainable, code 10
  • 11. Who is the Terminator? 11
  • 12. What does ZendCode Do? •So, what does ZendCode do? 12
  • 13. Let’s Recap the Humble Beginnings •ZF1 users wanted scaffolding & RAD •So, ... Zend_Tool •Zend_Tool_Project / Zend_Tool_Framework Zend_CodeGenerator •original intention was more than PHP Zend_Reflection •added docblock parsing functionality 13
  • 14. ZF1 Problem Area •This setup suffered from 2 major problems: Runtime dependencies are not always loaded Same request changes to structures do not update in-memory structures 14
  • 16. Problem 2 •Workflow (in the same request): Require File Build ZendCodeGenerator object based off Zend Reflection object of a class •(For example a controller) Add method to class Write to disk Build ZendCodeGenerator object based off Zend Reflection object •FAIL! B/c file is already in memory 16
  • 17. Problem 2 - Temporary Solution •Temporary solution was to cache generator objects that were built based one particular reflection objects, and return those when asked for a generator object seeded with a known reflection object •“We’ll fix this in ZF2” 17
  • 18. Other Realizations •We were not going to get other generator types •Generators were closely related to Reflection and the new Scanner component •ZendCode was a better place for all of this 18
  • 19. Static vs. Dynamic •Runtime Static - Fast Dynamic - Slow •Dev-time Static - slower workflow Dynamic - workflow resembles runtime 19
  • 20. Static vs. Dynamic •Typical PHP workflow for dynamic applications: initiate request fulfill request return to consumer 20
  • 21. Static vs. Dynamic •Typical PHP workflow for “static” applications with compilation built in (dev time): initiate request compile (during request, but omitted during production) fulfill request return to consumer 21
  • 22. Static vs. Dynamic •Typical PHP workflow for “static” applications with compilation NOT built in (dev time): (change code) (compile code) initiate request fulfill request return to consumer 22
  • 23. Static vs. Dynamic •You’ve probably seen static analysis in some way before: Caching •If you never intend on expiring the data, it’s not really a cache if (!file_exists(..)) { file_put_contents(..., var_export()) } Zend Optimizer / APC Content Platforms: •Drupal – development mode – non-caching mode – module initialization •Wordpress – installation hooks: plugin initialization 23
  • 24. What are we compiling? •Anything dynamically looked up What the valid routes are What the valid application assets are •classes •view scripts Where particular classes are located More? •Which extensions are loaded •What the php environment can support 24
  • 25. So, What Is Our Toolset? •ZendCode ZendCodeReflection ZendCodeGenerator ZendCodeScanner ZendCodeAnnotation 25
  • 26. ZendCodeReflection •Originally part of ZF1 •Added features: file reflection docblock reflection 26
  • 29. ZendCodeGenerator •Originally ZF 1’s ZendCodeGenerator •Built OO Classes with an OO API Mainly consumed by Zend_Tool 29
  • 30. ZendCode Generator 30
  • 31. ZendCodeScanner •ZendCodeScanner Token based “reflection” Reflection for files in ZF1 has a similar approach Ascertain information in files: •what namespaces are inside this file •what use statements are inside a particular namespace •what classes are in this file’s namespaces •what files are required (none, right?) •is there a file level docblock 31
  • 33. ZendCode Scanner (Sample) 33
  • 34. ZendCodeAnnotation •Annotations Why? You asked for it. At least some of you did. There’s no native PHP support for it Similar to: •Java’s Annotation system •C#’s Attribute system •Doctrine’s Annotation system •with a PHP twist of course 34
  • 35. ZendCodeAnnotation •Design: Do not force content into a particular DSL Build as a simple easy to use framework for easy consumption Prototype pattern Use ZendCodeScanner •Drawbacks Slow, very very slow 35
  • 36. ZendCodeAnnotation •Single Interface to implement: ZendCodeAnnotationAnnotation 36
  • 37. ZendCodeAnnotationManager •Simple Manager to Populate: 37
  • 38. Demo 1: ZendCodeScanner •Find all dependencies in a directory full of code •Demo 38
  • 39. Demo 2: Built a Micro-framework •Goals Find on github.com/ralphschindler/middlewarephp few classes - the “middleware” is editable fast (2ms request for hello world) compilation based •Routes •Classmap autoloader annotation based utilize include returns, closures, and arrays •Demo 39
  • 40. Philisophical •Let’s get philosophical: Should we be “compiling” elements? •Is this what PHP is all about? •Rasmus says yes. Can we architect flexible and performant applications without some kind of static code analysis that affects runtime? How do we introduce these tasks into developer workflows where they make the most sense, don’t impede development? 40
  • 41. Fin •Questions and/or comments, let’s go grab a beer discuss. •Remember ZF2 is only beta, if you have opinions on how we should go about applying these techniques, get involved NOW! •Thank you! 41

Editor's Notes

  翻译: