Ejemplo n.º 1
0
 public static function loadConfiguration()
 {
     $config = self::$config = simplexml_load_file('app/etc/local.xml');
     $nodeFound = false;
     foreach ($config->children() as $child) {
         if ($child->getName() == 'lightspeed') {
             $nodeFound = true;
             foreach ($child->children() as $child2) {
                 switch ($child2->getName()) {
                     case 'global':
                         self::report("found the global db node");
                         if (self::useMySqli()) {
                             //mysqli
                             self::$mysqlidatabase = mysqli_connect((string) $child2->connection->host, (string) $child2->connection->username, (string) $child2->connection->password);
                             mysqli_select_db(self::$mysqlidatabase, (string) $child2->connection->dbname);
                         } else {
                             //pdo
                             try {
                                 self::$pdodatabase = new PDO('mysql:host=' . (string) $child2->connection->host . ';dbname=' . (string) $child2->connection->dbname, (string) $child2->connection->username, (string) $child2->connection->password);
                             } catch (PDOException $e) {
                             }
                         }
                         self::$request_path = (string) $child2->request_path;
                         self::$request_path = rtrim(trim(self::$request_path), '/');
                         if ($child2->multi_currency) {
                             self::$multiCurrency = (int) $child2->multi_currency;
                         }
                         break;
                     case 'session':
                         switch ((string) $child2->type) {
                             case 'memcached':
                                 // self::report("Session store is memcached");
                                 if (!class_exists('Memcache')) {
                                     throw new Exception('Memcache extension not installed, but configured for use in local.xml');
                                 }
                                 self::$sessionType = 'memcached';
                                 self::$sessionConfig['server'] = new Memcache();
                                 foreach ($child2->servers->children() as $server) {
                                     self::$sessionConfig['server']->addServer((string) $server->host, (int) $server->port, (bool) $server->persistant);
                                 }
                                 break;
                             case 'db':
                                 // self::report("session store is db");
                                 self::$sessionType = 'db';
                                 self::$sessionConfig['connection'] = mysqli_connect((string) $child2->connection->host, (string) $child2->connection->username, (string) $child2->connection->password);
                                 mysqli_select_db(self::$sessionConfig['connection'], (string) $child2->connection->dbname);
                                 break;
                             case 'files':
                             default:
                                 // self::report("session store is files");
                                 self::$sessionType = 'files';
                                 self::$sessionConfig['path'] = (string) $child2->path;
                                 if (!self::$sessionConfig['path']) {
                                     self::$sessionConfig['path'] = 'var/session';
                                 }
                                 break;
                         }
                         break;
                     case 'cache':
                         switch ((string) $child2->type) {
                             case 'memcached':
                                 // self::report("cache engine is memcached");
                                 if (!class_exists('Memcache')) {
                                     throw new Exception('Memcache extension not installed, but configured for use in local.xml');
                                 }
                                 self::$cacheEngine = 'memcached';
                                 self::$cacheData['server'] = new Memcache();
                                 foreach ($child2->servers->children() as $server) {
                                     self::$cacheData['server']->addServer((string) $server->host, (int) $server->port, (bool) $server->persistant);
                                 }
                                 break;
                             case 'files':
                             default:
                                 // self::report("cache engine is files");
                                 self::$cacheEngine = 'files';
                                 self::$cacheData['path'] = (string) $child2->path;
                                 if (!self::$cacheData['path']) {
                                     self::$cacheData['path'] = 'var/lightspeed';
                                 }
                                 break;
                         }
                         break;
                 }
             }
         }
     }
     if (!$nodeFound) {
         //node not found, install for them
         self::report("local.xml does not contain <lightspeed> node, here let us setup lightspeed for you...", true);
         self::createLocalConfig();
         self::loadConfiguration();
     }
 }