• Save
Using Zend_Tool to Establish Your Project's Skeleton
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share

Using Zend_Tool to Establish Your Project's Skeleton

  • 4,990 views
Uploaded on

User Group presentation titled "Using Zend_Tool to Establish Your Project's Skeleton"...

User Group presentation titled "Using Zend_Tool to Establish Your Project's Skeleton"

Event information can be found at: http://www.meetup.com/DFW-Apache-LAMP/calendar/11819226/

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
4,990
On Slideshare
4,922
From Embeds
68
Number of Embeds
5

Actions

Shares
Downloads
0
Comments
0
Likes
9

Embeds 68

http://www.notmessenger.com 28
http://www.scoop.it 20
http://www.slideshare.net 17
http://www.linkedin.com 2
https://www.linkedin.com 1

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Using Zend_Tool to Establish Your Project's Skeleton DFW Apache LAMP Group presented by Jeremy Brown, ZCE 1 Feb 2010
  • 2. Housekeeping
  • 3. Who Am I?
    • Jeremy Brown, Zend Certified Engineer (ZCE)
    • Have been using PHP since 1999 (PHP 3)
    • Have been using Zend Framework since 2008 (version 1.0.4)
    • Software Architect / Team Lead at Spear One (spearone.com)
  • 4. Contact Information
    • Blog: notmessenger.com
    • Twitter: twitter.com/notmessenger
    • Email: jeremy@notmessenger.com
    • IRC: #zftalk and #dallasphp (irc.freenode.net)
  • 5. Where to find this presentation
    • On my blog
      • notmessenger.com/presentations
    • Slideshare.net
      • <insert link here>
  • 6. How to provide feedback
    • Via Joind.in
      • http://joind.in/event/view/136
  • 7. Your turn – who are you?
    • How many of you have heard of Zend Framework before?
  • 8. Your turn – who are you?
    • How many of you have heard of Zend Framework before?
    • How many of you have played with it a little bit?
  • 9. Your turn – who are you?
    • How many of you have heard of Zend Framework before?
    • How many of you have played with it a little bit?
    • How many of you use it in a project or on a regular basis?
  • 10. Groundwork
  • 11. What is Zend Framework
    • An open source, object-oriented web application framework implemented in PHP 5
    • All components are fully object-oriented PHP 5 and are E_STRICT compliant
    • Use-at-will architecture with loosely-coupled components and minimal interdependencies
    • Provides individual components for many common requirements in web application development
  • 12. So what is Zend_Tool?
    • Zend_Tool is both rapid application development (RAD) tools as well as a framework for exposing your own set of tooling needs to the Zend_Tool user interface.
  • 13. So what is Zend_Tool?
    • Zend_Tool is both rapid application development (RAD) tools as well as a framework for exposing your own set of tooling needs to the Zend_Tool user interface.
    • No, really, what is Zend_Tool?
  • 14. Basic structure of a ZF application … OR…
  • 15. Where’s the beef?
    • Main Classes & APIs:
      • Zend_Tool_Framework
        • The component responsible for dispatching tooling requests
      • Zend_Tool_Project
        • The component responsible for exposing the “project specific” tooling capabilities
    Inspired by talk by Ralph Schindler of Zend, at ZendCon 2009 http://www.slideshare.net/ZendCon/zendtool-practical-use-and-extending
  • 16. Where’s the beef?
    • Main Classes & APIs:
      • Zend_Tool_Framework
        • The component responsible for dispatching tooling requests
      • Zend_Tool_Project
        • The component responsible for exposing the “project specific” tooling capabilities
    • And the gravy…
    • Supporting Classes & APIs:
      • Zend_CodeGenerator
      • Zend_Reflection
    Inspired by talk by Ralph Schindler of Zend, at ZendCon 2009 http://www.slideshare.net/ZendCon/zendtool-practical-use-and-extending
  • 17. Zend_Tool_Framework
  • 18. Zend_Tool_Framework sub-parts
    • Zend_Tool_Framework
      • Dispatch-style framework, designed to abstract enough system internals to make extensibility easy
        • “ Flexibility of the tooling dispatch over speed of tooling dispatch”
      • Broken down into logical sub-parts:
        • Client
        • Client storage & configuration
        • Loader
        • Provider & Provider Repository
        • Manifest, Manifest Repository & Metadata
        • System (Built-in) Providers
    From talk by Ralph Schindler of Zend, at ZendCon 2009 http://www.slideshare.net/ZendCon/zendtool-practical-use-and-extending
  • 19. Zend_Tool_Framework sub-parts
    • Zend_Tool_Framework_Client
      • Responsibilities:
        • Request Object
        • Response Object
        • Interactivity support
        • Setting up the system registry containing all required objects
        • The actual dispatch()-ing
      • First implementation of Zend_Tool_Framework_Client_Console
    From talk by Ralph Schindler of Zend, at ZendCon 2009 http://www.slideshare.net/ZendCon/zendtool-practical-use-and-extending
  • 20. Zend_Tool_Framework sub-parts
    • Zend_Tool_Framework_Client_Storage & Zend_Tool_Framework_Client_Config
      • Responsibilities:
        • Allowing clients to specify configuration values for the system and providers to use
        • Allowing clients to store artifacts on the filesystem that the system and providers can consume
          • Custom profile files
          • Provider-specific file formats and metadata
    From talk by Ralph Schindler of Zend, at ZendCon 2009 http://www.slideshare.net/ZendCon/zendtool-practical-use-and-extending
  • 21. Zend_Tool_Framework sub-parts
    • Zend_Tool_Framework_Loader
      • Responsibilities:
        • Load files provided
        • Search for classes defined that implement:
          • Zend_Tool_Framework_Manifest_Interface
          • Zend_Tool_Framework_Provider_Interface
    From talk by Ralph Schindler of Zend, at ZendCon 2009 http://www.slideshare.net/ZendCon/zendtool-practical-use-and-extending
  • 22. Zend_Tool_Framework sub-parts
    • Zend_Tool_Framework_Provider & Provider Registry
      • Responsibilities:
        • An interface for defining via a class, dispatch-able actions and “specialties”
          • (Similar to how Action Controllers define actions)
        • Registry to maintain instances of all providers available
        • Parsing of provider classes for dispatch-able “signatures”
    From talk by Ralph Schindler of Zend, at ZendCon 2009 http://www.slideshare.net/ZendCon/zendtool-practical-use-and-extending
  • 23. Zend_Tool_Framework sub-parts
    • Zend_Tool_Framework_Manifest & Manifest Repository
      • Responsibilities:
        • Manifest can supply a collection of providers, actions and/or metadata
        • Registry provides a way to search for metadata in the manifest
    • Zend_Tool_Framework_Metadata
      • Responsibilities:
        • Primary use case is to attach “data about data” to instance of a specific client, provider, or action
          • ex: alternate names for each provider based on the command line naming scheme, OR short names (p for profile)
    From talk by Ralph Schindler of Zend, at ZendCon 2009 http://www.slideshare.net/ZendCon/zendtool-practical-use-and-extending
  • 24. Zend_Tool_Project
  • 25. Zend_Tool_Project sub-parts
    • Zend_Tool_Project_Profile
      • Responsibilities:
        • loading, parsing, serializing and storing a profile file
        • Top most node in a “resource tree”
    • Zend_Tool_Project_Profile_Resource
      • Responsibilities:
        • The class most responsible for the “where” question of project modeling
        • The class most responsible for implementing a node in a “resource tree”
        • Extends Resource_Container which is a RecursiveIterator (tree fundamentals)
        • Can create new Resources at specific locations
        • Can find resources by name and attribute sets
        • Each contains a Zend_Project_Context object
    From talk by Ralph Schindler of Zend, at ZendCon 2009 http://www.slideshare.net/ZendCon/zendtool-practical-use-and-extending
  • 26. Zend_Tool_Project sub-parts
    • Zend_Tool_Project_Context
      • Responsibilities:
        • The class most responsible for the “what” part of project modeling
        • It is assigned to a Zend_Tool_Project_Profile_Resource object
        • Example contexts:
          • Controller file
          • View script directory
          • View script file
          • Model file
          • Action method
    From talk by Ralph Schindler of Zend, at ZendCon 2009 http://www.slideshare.net/ZendCon/zendtool-practical-use-and-extending
  • 27. Putting it all together
  • 28. Putting it all together
    • Zend_Tool_Framework looks for providers, by default, on the include_path
      • It recursivly iterates all include path directories and opens all files that end with “Manifest.php” or “Provider.php”
      • All classes in these files are inspected if they implement either Zend_Tool_Framework_Provider_Interface or Zend_Tool_Framework_Manifest_ProviderManifestable
    • Zend_Tool_Project is consumed by Zend_Tool_Framework
      • This allows Zend_Tool_Project to be only concerned with “project” problems
      • This also allows Zend_Tool_Framework to focus on the problem of knowing which requests are good, and knowing how to dispatch said request
    • Zend_Tool_Framework provides a client to the user
  • 29. Additional Resources
    • In relation to the information presented in this section
    • http://framework.zend.com
    • http://framework.zend.com/manual/en
    • http://framework.zend.com/manual/1.10/en/zend.tool.html
    • http://framework.zend.com/manual/1.10/en/zend.tool.framework.html
    • http://framework.zend.com/manual/1.10/en/zend.tool.project.html
    • http://framework.zend.com/manual/1.10/en/zend.codegenerator.html
    • http://framework.zend.com/manual/1.10/en/zend.reflection.html
    • http://www.slideshare.net/ZendCon/zendtool-practical-use-and-extending
  • 30. Setting things up
  • 31. Install Zend Framework
    • Download Zend Framework
      • From website (http://framework.zend.com)
      • SVN
      • Zend Server
      • From PEAR channel (http://pear.zfcampus.org/)
    • Install it
      • How?
      • Where?
        • For purpose of this presentation, have installed it at C:endFramework-1.9.7
  • 32. Prepare Zend_Tool
  • 33. Understanding the CLI Tool
    • /bin/zf.sh and /bin/zf.bat
      • Operating system specific client wrappers
        • Responsible for finding the proper php.exe, finding the zf.php file, and passing on the client request
    • /bin/zf.php
      • Responsible for:
        • handling the understanding of your environment
        • construction of proper include path
        • passing what is provided on the command line to the proper library component for dispatching
  • 34. Accessing the CLI Tool
    • Two things have to be true:
      • zf.sh/zf.bat is reachable from your system path.
        • This is the ability to call ‘zf’ from anywhere on your command line, regardless of what your current working directory is.
      • ZendFramework/library is in your include path
    • So how do we === true?
  • 35. Make zf.sh/zf.bat reachable from system path
    • Manual’s recommendation:
      • Copy zf.sh/zf.bat and zf.php into the same directory as your PHP binary
        • For *nix, usually:
          • /usr/bin/
          • /usr/local/bin/
          • /usr/local/ZendServer/bin/
          • /Applications/ZendServer/bin
        • For Windows, usually:
          • C:PHP
          • C:Program FilesendServerin
          • C:WAMPPHPin
  • 36. Make zf.sh/zf.bat reachable from system path
    • My recommendation:
      • Create an Alias to zf.sh/zf.bat
        • For *nix:
          • alias zf &quot;/usr/local/Zend/ZendFramework-1.9.7/bin/zf.sh&quot;
          • alias zf &quot;/YOUR_PATH_HERE/bin/zf.sh&quot;
        • For Windows:
          • doskey zf=C:ENDFR~1.7inzf.bat
      • However….
        • On Windows, I could not get the arguments passed to ‘zf’ to be passed along, so….
        • Ended up modifying the environment variable PATH to include C:endFramework-1.9.7in
  • 37. Add ZendFramework/library to include_path
    • Manual’s recommendation:
      • Determine what your current include_path value is and add the contents of ZendFramework/library to one of these locations
      • Alternative option to above:
        • For *nix:
          • In a location included in your current include_path, create a symbolic link to the location of ZendFramework/library
        • For Windows:
          • Modify the environment variable PATH to include C:PATH_TO_ZENDFRAMEWORKin
          • Alter your php.ini file and modify include_path directive to include C:PATH_TO_ZENDFRAMEWORKlibrary
  • 38. Add ZendFramework/library to include_path
    • My recommendation:
      • Use special environment variable(s) to tell zf.php the location of ZendFramework/library
      • They are:
        • ZEND_TOOL_INCLUDE_PATH_PREPEND
          • Will prepend the value of this environment variable to the system (php.ini) include_path before loading the client
        • ZEND_TOOL_INCLUDE_PATH
          • Completely replaces the system include_path with the one specified
      • How to do this:
        • For *nix:
          • setenv ZEND_TOOL_INCLUDE_PATH_PREPEND /usr/local/Zend/ZendFramework-1.9.7/library/
        • For Windows:
          • set ZEND_TOOL_INCLUDE_PATH_PREPEND=C:ENDFR~1.7library
  • 39. Other settable environment variables
    • ZF_HOME
    • ZF_STORAGE_DIR
    • ZF_CONFIG_FILE
    • ZF_INCLUDE_PATH
    • ZF_INCLUDE_PATH_PREPEND
    • Can be found at http://framework.zend.com/manual/en/zend.tool.usage.cli.html
  • 40. Did I set it up correctly?
    • To verify that the previous steps worked correctly, enter ‘zf’ at the command line. Should expect to see something similar to:
  • 41. Additional Resources
    • In relation to the information presented in this section
    • http://framework.zend.com/manual/1.10/en/zend.tool.framework.html
    • http://framework.zend.com/manual/1.10/en/zend.tool.usage.cli.html
    • http://framework.zend.com/manual/1.10/en/zend.tool.extending.html
    • http://en.wikipedia.org/wiki/Alias_%28command%29
    • http://www.unix.com/windows-dos-issues-discussions/74664-what-dos-equivalent-alias-command.html
  • 42. Enough with the setup – I’m here for some coding!
  • 43. Few basic things
    • zf --help
    • zf show version
    • zf show version
    • zf show version -n 0
    • zf show version.major-part
    • zf show version -m minor -n 0
  • 44. Create project
    • Provide a path:
      • zf create project demo
    • Be prompted for path:
      • zf create project
  • 45. Create project
    • Provide a path:
      • zf create project demo
    • Be prompted for path:
      • zf create project
    • Can now run:
      • zf show project
      • zf show profile
  • 46. Create Controller
    • Provide a controller name:
      • zf create controller <controllername>
    • Be prompted for a controller name:
      • zf create controller
  • 47. Create Controller Actions
    • zf create action <actioname> <controllername>
      • Will throw a Fatal Error if <controllername> does not exist
  • 48. Create views
    • zf create view <controllername> <actionname>
      • <actionname> is really only for the name of the View Script – a new action is NOT created in the controller
  • 49. Additional Resources
    • In relation to the information presented in this section
    • http://framework.zend.com/manual/en/zend.tool.project.create-a-project.html
    • http://framework.zend.com/manual/en/zend.tool.project.providers.html
    • http://ralphschindler.com/wiki/index.php/Using_Zend_Tool
  • 50. Extending Zend_Tool
  • 51. How Zend_Tool finds your Providers
    • Remember that:
    • Zend_Tool_Framework looks for providers, by default, on the include_path
      • It recursivly iterates all include path directories and opens all files that end with “Manifest.php” or “Provider.php”
      • All classes in these files are inspected if they implement either Zend_Tool_Framework_Provider_Interface or Zend_Tool_Framework_Manifest_ProviderManifestable
  • 52. How Zend_Tool finds your Providers
    • The following naming rules apply on how you can access the providers that were found by the IncludePathLoader:
      • The last part of your classname split by underscore is used for the provider name, e.g. “My_Provider_Hello” leads to your provider being accessible by the name “hello”
      • If your provider has a method getName() it will be used instead of the previous method to determine the name
      • If your provider has “Provider” as suffix, e.g. it is called “My_HelloProvider”, it will be stripped from the name so that the provider will be called “hello”.
    • Note: The IncludePathLoader does not follow symlinks. This means you cannot link provider functionality into your include paths, they have to be physically present in the include paths.
  • 53. Example Custom Provider
  • 54. Minimum code needed… /My/Provider/Slide54Provider.php
  • 55. …but we really need some more The previous example illustrates being able to make your newly-created custom provider to be seen by Zend_Tool_Framework, but it really isn’t able to expose any Provider capabilities. What you need instead is: /My/Provider/Slide55Provider.php
  • 56. Provide alternate name for Provider /My/Provider/Slide56Provider.php
  • 57. Example Custom Manifest
  • 58. Minimum code needed /My/Manifest/Slide58Manifest.php
  • 59. Let’s do more with Providers
  • 60. Passing variables to a Provider /My/Provider/Slide60.php
    • Examples of how to call this provider:
      • zf say slide60
      • zf say slide60 Jason
      • zf say slide60 --name Jason
  • 61. Prompt user for input /My/Provider/Slide61.php
  • 62. Pretendability /My/Provider/Slide62.php
    • Examples of how to call this provider:
      • zf say slide62
      • zf --pretend say slide62
  • 63. Verbose /My/Provider/Slide63.php
    • Examples of how to call this provider:
      • zf say slide63
      • zf --verbose say slide63
  • 64. Debug /My/Provider/Slide64.php
    • Examples of how to call this provider:
      • zf say slide64
      • zf --debug say slide64
  • 65. Multiple arguments /My/Provider/Slide65.php
  • 66. Additional Resources
    • In relation to the information presented in this section
    • http://framework.zend.com/manual/en/zend.tool.extending.html
    • http://framework.zend.com/manual/en/zend.tool.framework.writing-providers.html
  • 67. Customizing Zend_Tool Console Client
  • 68. Customizing Zend_Tool Console Client
    • Zend_Tool_Framework allows developers to store information, provider-specific configuration values, and custom files in a special location on the developers machine.
    • Items of discussion:
      • Home Directory
      • Local Storage
      • User Configuration
  • 69. Additional Resources
    • In relation to the information presented in this section
    • http://framework.zend.com/manual/1.10/en/zend.tool.framework.extending.html
    • http://framework.zend.com/manual/en/zend.tool.framework.writing-providers.html
  • 70. Putting our Providers to work
  • 71. Keep profile up-to-date $this->_loadProfile(); $this->_storeProfile();
  • 72. Context Can extend Zend_Tool_Project_Context_Filesystem_File and Zend_Tool_Project_Context_Filesystem_Directory to create context classes. $profile = $this->_loadProfile(); $modelsDirectory = $profile->search('ModelsDirectory'); $modelFile = $modelsDirectory->createResource('ModelFile'); $modelFile->getContext()->setModelName($name); Excerpts from Zend Webinar presented by Ralph Schindler of Zend http://www.zend.com/en/webinar/framework/webinar-zend-tool-20090630.flv
  • 73. Zend_CodeGenerator Excerpts from Zend Webinar presented by Ralph Schindler of Zend http://www.zend.com/en/webinar/framework/webinar-zend-tool-20090630.flv
  • 74. Integration with Zend_Application Excerpts from Zend Webinar presented by Ralph Schindler of Zend http://www.zend.com/en/webinar/framework/webinar-zend-tool-20090630.flv
  • 75. Additional Resources
    • In relation to the information presented in this section
    • http://framework.zend.com/manual/en/zend.tool.extending.html
    • http://www.zend.com/en/webinar/framework/webinar-zend-tool-20090630.flv
  • 76. Where do things go from here?
  • 77. Known plans
  • 78. Roadmap
    • Zend Framework 1.10 offers
      • Model Provider
      • Form Provider
      • DbTable Provider
      • DbAdapter configuration
      • Layout enabling and creation
      • Custom Profiles
      • Improved Module Provider
      • … and more!
    • In the works
      • Web interface
      • Better documentation
    • Have hopes for
      • Apache configuration code generator
  • 79. Using for your own needs
  • 80. The sky’s the limit
    • Don’t have to use it for just a “project”
    • How Spear One has begun, and plans, on using Zend_Tool
  • 81. Improving Zend_Tool
  • 82. Public Service Announcement
    • Play with it and use it
    • Submit bugs and feature requests
      • http://framework.zend.com/issues/browse/ZF/component/10380
    • Get involved in the community
      • Write a blog post
      • Visit #zftalk on irc.freenode.net
      • Become a contributor
        • Fix bugs
        • Implement new feature set
        • Improve documentation
  • 83. Additional Resources
    • In relation to the information presented in this section
    • http://framework.zend.com/issues/browse/ZF/component/10380
    • http://framework.zend.com/issues/browse/ZF-7940
    • http://ralphschindler.com/wiki/index.php/Using_Zend_Tool
  • 84. Thank you!
  • 85. Contact Information
    • Blog: notmessenger.com
    • Twitter: twitter.com/notmessenger
    • Email: jeremy@notmessenger.com
    • IRC: #zftalk and #dallasphp
    • Where to find presentation
      • notmessenger.com/presentations
      • <insert slideshare.net link here>
    • Please rate this talk on Joind.in
      • http://joind.in/event/view/136