All pastes #622812 Raw Edit

Anonymous

public php v1 · immutable
·published 2007-07-17 03:20 UTC
rendered paste body
<?php/** * AdaptableCore Application Framework * * @category    AdaptableCore * @package     AdaptableCore * @version     $Id: Bootstrapper.php 54 2007-07-17 02:11:05Z  $ * * @copyright   Copyright (c) 2007 Cameron Cox, AdaptableCode <http://adaptablecode.com> * @license     http://projects.adaptablecode.com/core/license New BSD License *//** * Zend_Loader */include_once 'Zend/Loader.php';/** * Zend_Controller_Front */include_once 'Zend/Controller/Front.php';/** * Zend_Config_Xml */include_once 'Zend/Config/Ini.php';/** * Application Bootstrapper * * @category    AdaptableCore * @package     AdaptableCore * @version     $Id: Bootstrapper.php 54 2007-07-17 02:11:05Z  $ * * @copyright   Copyright (c) 2007 Cameron Cox, AdaptableCode <http://adaptablecode.com> * @license     http://projects.adaptablecode.com/core/license New BSD License */class AdaptableCore_Application_Bootstrapper{    protected $_application;    protected $_environment;    protected $_controller;    protected $_config;    public function __construct()    {    }    public function setEnvironment($environment)    {        $this->_environment = (string) $environment;    }    public function getEnvironment()    {        return $this->_environment;    }    public function setController(Zend_Controller_Front $controller)    {        $this->_controller = $controller;    }    public function getController()    {        return $this->_controller;    }    public function setApplicationPath($application)    {        if (!Zend_Loader::isReadable($application)) {            include_once 'AdaptableCore/Application/Bootstrapper/Exception.php';            throw new AdaptableCore_Application_Bootstrapper_Exception("'$application' is not readable or not found on the system!");        }        $this->_applicationPath = (string) realpath($application);    }    public function getApplicationPath($extra = '')    {        $path = $this->_applicationPath . ('' !== $extra ? $extra : '');        return $path;    }    public function setConfig(Zend_Config $config)    {        $this->_config = $config;    }    public function getConfig()    {        return $this->_config;    }    public function bootstrap($application)    {        $this->setApplicationPath($application);        $controller = $this->initApplication();        $this->loadRoutes();        return $controller->dispatch();    }    public function initApplication()    {        if (null === $this->getEnvironment()) {            $this->setEnvironment('development');   // default to development        }        if (null === $this->getController()) {            $this->setController(Zend_Controller_Front::getInstance());        }        if (null === $this->getConfig()) {            $this->setConfig(new Zend_Config(new Zend_Config_Ini($this->getApplicationPath('/config/environment.ini'), $this->getEnvironment())));        }        foreach ($this->getConfig()->modules as $module => $path)        {            $this->getController()->addControllerDirectory($this->getApplicationPath("$path/controllers"), $module);        }        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');        $viewRenderer->setViewSuffix('html');        if (isset($this->getConfig()->database)) {            include_once 'Zend/Db/Table/Abstract.php';            $dbconfig = $this->getConfig()->database;            Zend_Db_Table_Abstract::setDefaultAdapter(Zend_Db::factory($dbconfig->driver, $dbconfig->options->toArray()));        }        return $this->getController();    }    public function loadRoutes()    {        $routes = $this->getConfig()->routes;        foreach ($routes as $route => $options)        {            $options = $options->toArray();            if ('static' === $options['type']) {                $this->getController()->getRouter()->addRoute($route, new Zend_Controller_Router_Route_Static($options['route'], $options['defaults']));            }            else if ('module' === $options['type'])            {                $this->getController()->getRouter()->addRoute($route, new Zend_Controller_Router_Route_Static($options['route'], $options['defaults'], $options['values']));            }        }    }}