Zend_Application_Bootstrap_Bootstrap_Selective

For programming and general questions on Zend Framework

Zend_Application_Bootstrap_Bootstrap_Selective

Postby willf1976 on Wed Jan 16, 2013 9:40 pm

Hi All

I have been going through the classes we have developed over the last few years and sharing back with the community some of them that I think will be useful to others.

Here is: Zend_Application_Bootstrap_Bootstrap_Selective

In developing web applications we found it some times helpful to be able to create more or than 1 index file that allows for bootstrapping of specific resources. This was especially helpful for us when making an api for some of our applications functionality that needed to be as responsive as possible and there for needed to only bootstrap the specific resources need for each call to api and ignore the others -- this sped up the response times of this api significantly while still allowing us to use the same bootstrap class as the rest of our application.

To use this functional do something like the following in your index file:

Code: Select all
require_once 'Zend/Application/Bootstrap/'ResourceBootstrapper.php';
require_once 'Zend/Application/Bootstrap/Bootstrapper.php';
require_once 'Zend/Application/Bootstrap/BootstrapAbstract.php';
require_once 'Zend/Application/Bootstrap/Bootstrap.php';
require_once 'Zend/Application/Bootstrap/Bootstrap/Selective.php';
Zend_Application_Bootstrap_Bootstrap_Selective::setDisabledClassResources(array(
  [resources you would like to not boot strap]
));


Then make sure your bootstrap extends our class -- class Bootstrap extends Zend_Application_Bootstrap_Bootstrap_Selective

Here is the class it's self:

Code: Select all
<?php
/**
* @author Will Ferrer, Ethan Brooks
* @copyright (c) 2012, Intellectual Property Private Equity Group
* @licensee 2012 developed under license for Switchsoft LLC a "Direct response telephony company" as part of it's "VOIP Call distribution, ROI analysis platform, call recording, and IVR for inbound and outbound sales" and Run the Business Systems LLC a "Technology development investment group" as part of it's "PHP, Javascript rapid application development framework and MySQL analysis tools"
* @license licensed under the terms of
* the Open Source LGPL 3.0 license.  Commercial use is permitted to the extent
* that the code/component(s) do NOT become part of another Open
Source or Commercially
* licensed development library or toolkit without explicit permission.
* We are pretty nice just ask. We want to meet our licensees
*/


/**
* A selective bootstrapper that allows users to configure what items will be boot strapped.
* @abstract
* @package Rtb_Default
*/
class Zend_Application_Bootstrap_Bootstrap_Selective extends Zend_Application_Bootstrap_Bootstrap {
   
   
   /**
    * disabled class resources to prevent bootstraping of those resources
    * @var array
    * @access protected
    * @static
     */
   static protected $disabledClassResources = array();


   /**
    * Extended version of method that allows disabling of class resources
     *
     * @return array
     */
    public function getClassResources()
    {
        if (null === $this->_classResources) {
            if (version_compare(PHP_VERSION, '5.2.6') === -1) {
                $class        = new ReflectionObject($this);
                $classMethods = $class->getMethods();
                $methodNames  = array();

                foreach ($classMethods as $method) {
                    $methodNames[] = $method->getName();
                }
            } else {
                $methodNames = get_class_methods($this);
            }

            $this->_classResources = array();
         $disabled = self::getDisabledClassResources();
            foreach ($methodNames as $method) {
                if (5 < strlen($method) && '_init' === substr($method, 0, 5) && (!in_array($method, $disabled))) {
                    $this->_classResources[strtolower(substr($method, 5))] = $method;
                }
            }
        }

        return $this->_classResources;
    }
   
   
   /**
     * getter method for disabledClassResources
     *
     * @return array
    * @static
     */
   static  public function getDisabledClassResources(){
       return self::$disabledClassResources;
    }
   
    /**
     * setter method for disabledClassResources
     * @param array $disabledClassResources 
    * @static   
     */
    static public function setDisabledClassResources($disabledClassResources){
       self::$disabledClassResources = $disabledClassResources;
    }
}


Best regards

Will Ferrer (Run the Business)
willf1976
 
Posts: 1
Joined: Wed Jan 16, 2013 9:18 pm

Return to Zend Framework

Who is online

Users browsing this forum: Google [Bot] and 1 guest