1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
<?php /** * Zend Framework Forum Demo Application * @category Bootstrap * @package Default * @version $Id: index.php 91 2008-03-15 17:38:46Z budcha $ */ /** * Index.php wird allgemein als Bootstrap Datei bezeichnet. Die Funktion dieser * Bootstrap Datei besteht darin sämtliche Konfigurations Parameter, welche zum * starten des Programms benötigt werden, zu setzen. * * @todo Bootstrap Datei konfigurieren * * @category Bootstrap * @package Default */ /** * Error Reporting einstellen. * * Die default Einstellung, welche wir hier vorgeben, ist dafür gedacht das alle * Fehler mitgeteilt werden. Wenn die Anwendung für alle freigegeben wird, also * in den Produktionsmodus wechselt, sollte das Error Reporting auf ein minimum * wenn nicht sogar ganz ausgeschaltet werden. Siehe hierzu das PHP Manual. */ error_reporting(E_ALL | E_STRICT); /** * Starten des Output Bufferings. * * Ob man nun standart mäsig das Output Buffering aktivieren sollte oder nicht, * ist jedem selbst überlassen. Es kann Design Fehler unterdrücken (z.b. Ausgabe * von Inhalt bevor eine Session gestartet wird). */ ob_start('ob_gzhandler'); /** * Pfade festlegen. * * Das festlegen der Pfade wird z.b. für die Library benötigt. */ $ds = DIRECTORY_SEPARATOR; $ps = PATH_SEPARATOR; define('PATH_TO_LIBRARY', $ps . realpath('..' . $ds . 'library')); define('PATH_TO_APPLICATION', realpath('..' . $ds . 'application')); define('PATH_TO_CONFIG', realpath(PATH_TO_APPLICATION . $ds . 'configurations')); define('PATH_TO_LOG', realpath('..' .$ds. 'logs')); /** * IncludePath um Library erweitern. */ ini_set('include_path', ini_get('include_path') . PATH_TO_LIBRARY); /** * ErrorLog konfigurieren. * * Dies muß man nicht tun, hilft aber bei manchen Fehlern. */ ini_set('error_log', PATH_TO_LOG . $ds . 'php.log'); /** * Der Zend_Loader wird benötigt um später Klassen per Autoload Funktion * nachzuladen. * @see Zend_Loader */ require_once 'Zend/Loader.php'; /** * Registrieren des Zend_Loader als Autoload Methode. */ Zend_Loader::registerAutoload(); /** * Definieren der Config Files. */ $CONFIG_FILES = array( 'boot' => PATH_TO_CONFIG . $ds . 'bootstrap.ini', 'db' => PATH_TO_CONFIG . $ds . 'database.ini', 'routes' => PATH_TO_CONFIG . $ds . 'routes.ini', 'adapter' => PATH_TO_CONFIG . $ds . 'auth.ini' ); /** * Laden der Bootstrap Konfigurations Datei * * Zu beachten ist, das beim verwenden der Zend_Config_Ini Klassen, die zu * ladende Ini Datei eine sogenannte "Section" enthält, beispiel: * * <code> * [boot] * </code> * * @see Zend_Config_Ini */ try { $confBoot = new Zend_Config_Ini($CONFIG_FILES['boot'], 'boot'); $confDb = new Zend_Config_Ini($CONFIG_FILES['db'], 'db'); $confRoutes = new Zend_Config_Ini($CONFIG_FILES['routes'], 'routes'); $confAuth = new Zend_Config_Ini($CONFIG_FILES['adapter'], 'adapter'); } catch (Exception $exception) { echo $exception; Zend_Debug::dump(PATH_TO_CONFIG, 'PATH_TO_CONFIG: '); Zend_Debug::dump($CONFIG_FILES, 'CONFIG_FILES: '); die(); } /** * Default TimeZone setzen. * * PHP5 gibt eine Notice aus, wenn keine default Timezone gesetzt wird. * * Wir hohlen uns die Default Timezone aus der Bootstrap Ini bzw. aus dem * generierte Zend_Config Objekt. */ date_default_timezone_set($confBoot->date->timezone); /** * Starten der Session * * Default wird eine neue Session gestartet, bzw eine alte "wiederbelebt". * * @todo Session Start in die Bootstrap? */ try { /** * @see Zend_Session */ require_once 'Zend/Session.php'; Zend_Session::start(); } catch (Exception $exception) { echo $exception; } /** * Hauptsächlich für die Models starten wir eine Datenbankverbindung. * * Die Benötigten Parameter werden hierfür aus dem Zend_Config Objekt geholt. */ try { /** * @see Zend_Db */ require_once 'Zend/Db.php'; $db = Zend_Db::factory($confDb->type, $confDb->params->toArray()); } catch (Exception $exception) { echo $exception; } /** * Setzen der erstellten Verbindung als Standart für Zend_Db_Table Objekte. * * @todo Db Initialisierung und setzen der Verbindung in die Bootstrap? */ try { /** * @see Zend_Db_Table_Abstract */ require_once 'Zend/Db/Table/Abstract.php'; Zend_Db_Table_Abstract::setDefaultAdapter($db); } catch (Exception $exception) { echo $exception; } /** * Setzen der jeweiligen Objekte mit standart Namen in die Zend_registry. * */ try { /** * @see Zend_Registry */ require_once 'Zend/Registry.php'; Zend_Registry::set('Zend_Db', $db); } catch (Exception $exception) { echo $exception; } /** * Konfiguration des FrontControllers. * * Da wir mit Modulen arbeiten, sagen wir dem FrontController in welchem Ordner * die Module liegen. * * In der bootstrap.ini liegen Konfogurationsparameter für den FrontController. * Diese übergeben wir hier. */ try { /** * @see Zend_Controller_Front */ require_once 'Zend/Controller/Front.php'; $frontController = Zend_Controller_Front::getInstance(); $frontController->addModuleDirectory(realpath(PATH_TO_APPLICATION . $ds . 'modules')); $frontController->setParams($confBoot->controller->params->toArray()); $frontController->returnResponse((bool) $confBoot->controller->returnResponse); $frontController->throwExceptions((bool) $confBoot->controller->throwExceptions); } catch (Exception $exception) { echo $exception; } /** * Hier übergeben wir dem FrontController unsere definierten Routen. */ try { $router = $frontController->getRouter(); $router->addConfig($confRoutes, 'routes'); } catch (Exception $exception) { echo $exception; } /** * Hier startet das Programm im eigentlichem sinne. Unsere Arbeitsumgebung ist * jetzt fertig Konfiguriert, der FrontController weis wo er was zu finden hat. */ try { $response = $frontController->dispatch(); if ($response !== null) { if ($response->isException()) { $exception = $response->getException(); throw $exception [0]; } $response->outputBody(); } } catch (Exception $exception) { echo $exception; } |
bootstrap datei - zend framework forum