loadConfig('../application/configs/SpotSec.xml', 'staging'); date_default_timezone_set('UTC'); /** * Zend Framework Bootstrap */ /** * Get basic configuration */ $basicConfig = new Zend_Config_Xml('../application/configs/config.xml', 'staging'); Zend_Registry::set('conf', $basicConfig); /** * Start Session */ if (!Zend_Session::isStarted()) { $sessionConfig = new Zend_Config_Xml('../application/configs/session.xml', 'staging'); Zend_Session::start($sessionConfig->toArray()); if (Zend_Session::sessionExists()) { /** * Regenerate id */ Zend_Session::regenerateId(); } } /** * Instantiate View object */ $view = new Zend_View(); $view->setScriptPath(array( $basicConfig->paths->templates . '/' . $basicConfig->template->name, // todo: validate template exists and is valid $basicConfig->paths->views )); /** * Action helpers */ Zend_Controller_Action_HelperBroker::addPrefix('Frontend_Controller_Action_Helper'); $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer(); $viewRenderer->setView($view) ->setViewBasePathSpec($basicConfig->paths->views .'/views/:module') ->setViewScriptPathSpec(':controller/:action.:suffix') ->setViewScriptPathNoControllerSpec(':action.:suffix'); Zend_Controller_Action_HelperBroker::addHelper($viewRenderer); /** * Generate list of modules and controllers */ try { /** * Get controller paths and file suffixes */ $controllers = array(); $controllersPath = $basicConfig->paths->controllers; $controllersSuffix = $basicConfig->controllers->fileSuffix; $controllersFolder = new SpotSec_Folder($controllersPath); /** * Default controller dir */ $controllers['default'] = $controllersPath; /** * Push controllers into array */ foreach ($controllersFolder->getListing() as $controllerFolderItem) { /** * Make sure folder item is a folder and does not start with a '.' */ if (substr($controllerFolderItem, -14) != $controllersSuffix && $controllerFolderItem{0} != '.') { $controllers[str_replace($controllersSuffix, '', $controllerFolderItem)] = $controllersPath . '/' . $controllerFolderItem; } } } catch (Exception $e) { /** * Note: Exception is thrown later at the front controller */ } /** * Acls */ if ($backendConf->acl instanceof Zend_Acl) { // Get stored acl object $acl = $backendConf->acl; } else { $acl = new Zend_Acl(); // Default acls $acl->add(new Zend_Acl_Resource('Auth_Login')); $roleGuest = new Zend_Acl_Role('guest'); $roleAdmin = new Zend_Acl_Role('admin'); $acl->addRole($roleGuest) ->addRole($roleAdmin); $acl->allow($roleGuest, 'Auth_Login'); $acl->allow($roleAdmin); $backendConf->acl = $acl; } Zend_Registry::set('acl', $acl); $aclPlugin = new Frontend_Controller_Plugin_Acl_Adapter_Frontend(array( 'module' => 'Auth', 'controller' => 'Login', 'action' => 'index' )); /** * Set up front controller */ $frontController = Zend_Controller_Front::getInstance(); $frontController->setControllerDirectory($controllers) ->addModuleDirectory($controllersPath) ->registerPlugin(new SpotSec_Controller_Plugin_Acl($acl, $aclPlugin)) ->registerPlugin(new SpotSec_Controller_Plugin_NoRoute('', 'httperror', 'code404')) ->throwExceptions(true); /** * Pass on parameters */ $frontController->setParam('useDefaultControllerAlways', false) ->setParam('config', $basicConfig); /** * Dispatch front controller */ $frontController->dispatch(); /** * Get response object */ $response = $frontController->getResponse(); /** * Check for uncaught exceptions caught by the response object */ if ($response->isException()) { foreach ($response->getException() as $e) { /** * Redirect to a 'pretty' error page */ throw $e; } } /** * Check for uncaught errors (and dump them on the user) */ /* $errorQueue = SpotSec_Error_Queue::getInstance(); if ($errorQueue->getAllMessages(false)) { echo "
\n"; foreach ($errorQueue->getAllMessages() as $message) { echo $message . "
\n"; } } */