Loading…

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

Like this presentation? Why not share!

Reusable bootstrap resources zend con 2010

on

  • 5,775 views

ZendCon 2010...

ZendCon 2010
This session demonstrates how to build configurable and reusable bootstrap resources powered entirely by application.ini. Covers basic and advanced bootstrapping techniques, sharing bootstrap resources between applications, and accessing resources from within your applications.

Statistics

Views

Total Views
5,775
Views on SlideShare
5,601
Embed Views
174

Actions

Likes
6
Downloads
126
Comments
3

5 Embeds 174

http://www.virgentech.com 111
http://www.berejeb.com 50
http://www.devetdesign.com 7
http://www.ofelio.com 5
http://localhost 1

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Reusable bootstrap resources   zend con 2010 Reusable bootstrap resources zend con 2010 Presentation Transcript

  • Reusable Bootstrap Resources
    Hector Virgen
    ZendCon 2010
  • About Me
    Average, everyday PHP developer.
    Zend PHP5 Certified Engineer
    Used ZF since 1.0.2 (December 2007)
    Developed web applications for
    RealTown 2004-2008
    Houghton Mifflin 2008-2010
    Disney 2010-current
  • What is Bootstrapping?
    Or “What does footwear have to do with the interwebs?”
  • Typical Bootstrap Tasks
    Define constants
    Set up include path
    Set up autoloader
    Initialize resources
    Database connections
    Session
    Web service clients
  • Welcome Zend_Application
    Or “Bootstrapping with Style”
  • Start with Zend_Tool
    $ zf create project quickstart
    Creating project at /Users/hevirgen/Web/projects/quickstart
    Note: This command created a web project, for more information setting up your VHOST, please see docs/README
  • Your App’s Configuration
    [production]
    phpSettings.display_startup_errors = 0
    phpSettings.display_errors = 0
    includePaths.library = APPLICATION_PATH "/../library"
    bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
    bootstrap.class = "Bootstrap"
    appnamespace = "Application"
    resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
    resources.frontController.params.displayExceptions = 0
    [staging : production]
    [testing : production]
    phpSettings.display_startup_errors = 1
    phpSettings.display_errors = 1
    [development : production]
    phpSettings.display_startup_errors = 1
    phpSettings.display_errors = 1
    resources.frontController.params.displayExceptions = 1
  • Bootstrap
    <?php
    class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
    {
    }
  • Initializing Resources
    Or “Loading up your application’s dependencies”
  • Choose Your Path Wisely, Grasshopper
    Bootstrap resources by:
    Providing protected _init*()methods.
    Using resource plugins.
  • _init*() Methods
    Coded directly in the application’s Bootstrap class.
    Return value is stored in bootstrap registry.
  • _init*() Methods
    class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
    {
    protected function _initFoo()
    {
    $foo = new Foo();
    return $foo;
    }
    }
  • Resource Plugin
    Each resource is initialized in its own class.
    Plugins are loaded in LIFO order.
    Return value is stored in bootstrap registry.
  • Resource Plugin
    class MyResource_Foo extends Zend_Application_Resource_Abstract
    {
    public function init()
    {
    $foo = new Foo();
    return $foo;
    }
    }
  • Ensure Resource Plugin is Loaded
    [production]
    pluginPaths.My_Resource = APPLICATION_PATH “/resources”
    resources.foo[] =
    ; or
    resources.foo.key = “value”
  • Accessing Resources
    Or “Gimmegimmegimme!”
  • Within an Action Controller
    $bootstrap = $this->getInvokeArg(‘bootstrap’);
    $foo = $bootstrap->getResource(‘foo’);
  • Within a Bootstrap Resource
    $bootstrap = $this->getBootstrap();
    $bootstrap->init(‘bar’);
    $bar = $bootstrap->getResource(‘bar’);
  • Statically AKA “Globally”
    $front = Zend_Controller_Front::getInstance();
    $bootstrap = $front->getParam(‘bootstrap’);
    $foo = $bootstrap->getResource(‘foo’);
  • _init*() or Plugin?
    Which is better?
  • The Most Perfectest Bootstrap
    class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
    {
    // Empty!!
    }
  • Or Use ZF Bootstrap
    [production]
    bootstrap.path= APPLICATION_PATH "/../library/Zend/Application/Bootstrap/Bootstrap.php"
    bootstrap.class = ”Zend_Application_Bootstrap_Bootstrap”
  • Configuring Resources
    Or “How to avoid hard-coding values”
  • _init*()
    [production]
    foo.bar = “bar”
    [development : production]
    foo.bar = “derp”
  • _init*()
    protected function _initFoo()
    {
    $options = $this->getOptions();
    assert($options[‘foo’][‘bar’] == ‘derp’); // true
    }
  • Resource Plugin
    [production]
    resources.foo.bar= “bar”
    [development : production]
    resources.foo.bar= “derp”
  • Resource Plugin
    Class MyResource_Foo extends Zend_Application_Resource_Abstract
    {
    public function init()
    {
    $options = $this->getOptions();
    assert($options[‘bar’] == ‘derp’); // true
    }
    }
  • Resource Plugin
    Class MyResource_Foo extends Zend_Application_Resource_Abstract
    {
    protected $_bar;
    public function setBar($bar)
    {
    $this->_bar = $bar;
    }
    public function init()
    {
    assert($this->_bar == ‘derp’); // true
    }
    }
  • Why Plugins Are Awesomesauce
    Reusable between projects
    Easily unit-tested
    Can be packaged with resource libraries
    Can provide sane defaults
    Loaded in LIFO order allows for extending plugins
  • When Plugins Can Be Weaksauce
    Performance concerns with loading a class file for each resource plugin
    Some editors (Notepad.exe) don’t support opening multiple files
  • print(“all done!”);http://www.virgentech.comdjvirgen@gmail.com