database.php

Go to the documentation of this file.
00001 <?php
00025 // Initialize layer
00026 $layerInstance = null;
00027 
00028 // Get config instance
00029 $cfg = FrameworkConfiguration::getInstance();
00030 
00031 // Generate FQFN for the database layer
00032 $INC = sprintf("%sinc/database/lib-%s.php",
00033         $cfg->readConfig('base_path'),
00034         $cfg->readConfig('db_type')
00035 );
00036 
00037 // Load the database layer include
00038 if ((file_exists($INC)) && (is_file($INC)) && (is_readable($INC))) {
00039         // Load the layer
00040         require_once($INC);
00041 } else {
00042         // Layer is missing!
00043         ApplicationEntryPoint::app_die(sprintf("[Main:] Database layer is missing! (%s) -&gt; R.I.P.",
00044                 $cfg->readConfig('db_type')
00045         ));
00046 }
00047 
00048 // Clean it up
00049 unset($INC);
00050 
00051 // Prepare database instance
00052 try {
00053         $db = DatabaseConnection::createDatabaseConnection(DebugMiddleware::getInstance(), $layerInstance);
00054 } catch (NullPointerException $e) {
00055         ApplicationEntryPoint::app_die(sprintf("[Main:] Database sub-system not initialized for the follwing reason: <span class=\"exception_reason\">%s</span><br />\n",
00056                 $e->getMessage()
00057         ));
00058 } catch (InvalidDirectoryResourceException $e) {
00059         ApplicationEntryPoint::app_die(sprintf("[Main:] Database sub-system not initialized for the follwing reason: <span class=\"exception_reason\">%s</span><br />\n",
00060                 $e->getMessage()
00061         ));
00062 } catch (PathIsEmptyException $e) {
00063         ApplicationEntryPoint::app_die(sprintf("[Main:] Database sub-system not initialized for the follwing reason: <span class=\"exception_reason\">%s</span><br />\n",
00064                 $e->getMessage()
00065         ));
00066 } catch (PathIsNoDirectoryException $e) {
00067         ApplicationEntryPoint::app_die(sprintf("[Main:] Database sub-system not initialized for the follwing reason: <span class=\"exception_reason\">%s</span><br />\n",
00068                 $e->getMessage()
00069         ));
00070 } catch (PathReadProtectedException $e) {
00071         ApplicationEntryPoint::app_die(sprintf("[Main:] Database sub-system not initialized for the follwing reason: <span class=\"exception_reason\">%s</span><br />\n",
00072                 $e->getMessage()
00073         ));
00074 } catch (DirPointerNotOpenedException $e) {
00075         ApplicationEntryPoint::app_die(sprintf("[Main:] Database sub-system not initialized for the follwing reason: <span class=\"exception_reason\">%s</span><br />\n",
00076                 $e->getMessage()
00077         ));
00078 }
00079 
00080 // Is the app variable there and valid?
00081 if (is_object($app)) $app->setDatabaseInstance($db);
00082 
00083 // Datenbankobjekt debuggen
00084 if (defined('DEBUG_DATABASE_OBJ')) {
00085         DebugMiddleware::getInstance()->output(sprintf("The database sub-system does now look like this:<br />
00086 <pre>%s</pre>\n",
00087                 print_r($db, true)
00088         ));
00089 }
00090 
00091 // [EOF]
00092 ?>

Generated on Mon Dec 8 01:06:46 2008 for Ship-Simulator by  doxygen 1.5.6