Пример #1
0
 public function init($configFile)
 {
     if (!file_exists($configFile) || !is_file($configFile)) {
         die("Missing main configuration file");
     }
     //$x = setlocale(LC_TIME, 'ru_RU.CP1251', 'ru_RU.cp1251', 'Russian_Russia.1251');
     $x = setlocale(LC_ALL, 'rus_RUS.65001', 'rus_RUS.65001', 'Russian_Russia.65001');
     $xml = simplexml_load_file($configFile);
     foreach ($xml->module as $module) {
         $configuration = new ConfigParameter($module->asXML());
         $class = $configuration->get('class');
         if (!$class) {
             die("Module has no class");
         }
         $module_id = $configuration->get('id');
         if (!$module_id) {
             die("Module has no ID");
         }
         if (Project::exists($module_id)) {
             // TODO:: write to log file
             //die("Module id already busy:".$module_id);
         }
         $module = new $class();
         $module->initialize($configuration);
         if ($module->setToRegistry() === true) {
             Project::set($module_id, $module);
         }
         unset($module);
     }
 }
Пример #2
0
 function initialize(IConfigParameter $configuration)
 {
     $dsn = $configuration->get('DSN');
     if (!$dsn) {
         $connection_file = $configuration->get('connection_file');
         if (!$connection_file) {
             throw new DbException("Connection file not defined");
         }
         $p = pathinfo($connection_file);
         $dir = Project::NS()->path($p['dirname']);
         $f = $dir . $p['basename'];
         if (!file_exists($f) || !is_file($f)) {
             throw new DbException("Connection file not exists");
         }
         $config = new ConfigParameter(file_get_contents($f));
         $dsn = $config->get('DSN');
         if (!$dsn) {
             throw new DbException("DSN not exitsts at connection file");
         }
     }
     $this->_caching = $configuration->get('caching');
     if ($configuration->get('cache_prefix')) {
         $this->_cache_prefix = $configuration->get('cache_prefix');
     }
     if ($configuration->get('cache_module_id')) {
         $this->_cache_module_id = $configuration->get('cache_module_id');
     } else {
         // No cache module defined
         // TODO:: write NOTICE to log
         $this->_caching = false;
     }
     $this->_DSN = $dsn;
     $this->_common_config($configuration);
     $this->_driver = DbSimple_Generic::connect($this->_DSN);
     if (!is_object($this->_driver)) {
         throw new DbException("No connection to database");
     }
     $this->_driver->query("SET NAMES utf8");
     $this->_driver->setLogger($configuration->get('native_logger'));
     //$this -> _driver -> setLogger('myLogger');
     Project::setDatabase($this);
 }