Exemple #1
0
 /**
  * Create a database handle
  * Factory method
  * @param array params
  */
 public static function get(array $config)
 {
     $engine = $config['engine'];
     if (isset(self::$dbs[$engine])) {
         return self::$dbs[$engine];
     }
     $engine_script = loader::get_root() . loader::DIR_MODULES . 'core/dbal/' . $engine . loader::DOT_PHP;
     core::dprint('[db] ' . $engine_script);
     fs::req($engine_script, true);
     if (!isset($config['server'])) {
         $config['server'] = 'localhost';
     }
     // create instance
     $class = "{$engine}_db";
     try {
         return self::$dbs[$engine] = new $class($config['server'], $config['login'], $config['password'], $config['database'], $config['prefix']);
     } catch (dbal_exception $e) {
         return false;
     }
 }
Exemple #2
0
 /**
  * Create a database handle
  * Factory method
  * @param array params
  *  engine - pdo
  *      type - mysql
  */
 public static function get(array $config)
 {
     require_once 'modules/core/dbal/dbal.php';
     $engine = $config['engine'];
     $type = @$config['type'];
     $key = $engine . $type;
     if (isset(self::$dbs[$key])) {
         return self::$dbs[$key];
     }
     $engine_script = loader::DIR_MODULES . 'core/dbal/' . $engine . loader::DOT_PHP;
     core::dprint('[db] ' . $engine_script);
     fs::req($engine_script, true);
     // create instance
     $class = "{$engine}_db";
     try {
         return self::$dbs[$key] = new $class($config);
     } catch (dbal_exception $e) {
         core::dprint($e->getMessage());
         return false;
     }
 }
Exemple #3
0
 /**
  * @return abs_control
  */
 protected function create_control($type)
 {
     $class = 'control_' . $type;
     if (!class_exists($class, 0)) {
         fs::req('modules/core/abstract/controls/' . $type . '.php');
     }
     return new $class();
 }
Exemple #4
0
 /**
  * @param null $key
  * @param array $config
  * @return bool
  */
 public static function set($key = null, array $config = array())
 {
     if (!isset($key)) {
         $key = self::DEFAULT_CONNECTION;
     }
     // $engine . $type;
     $engine = $config['engine'];
     $type = @$config['type'];
     $engine_script = loader::DIR_MODULES . 'core/dbal/' . $engine . loader::DOT_PHP;
     core::dprint('[db] ' . $engine_script);
     fs::req($engine_script, true);
     // create instance
     $class = "{$engine}_db";
     try {
         return self::$dbs[$key] = new $class($config);
     } catch (dbal_exception $e) {
         core::dprint($e->getMessage());
         return false;
     }
 }
Exemple #5
0
 /**
  * первичная инициализация модуля (core::init(0) -> core::init0() >- this::init0())
  * 
  * {@see core_c::modules_init}
  * @throws tf_exception
  */
 function init0()
 {
     $this->get_core()->import_langwords($this->tag);
     // autoload classes
     if (!empty($this->preload_classes)) {
         foreach ($this->preload_classes as $class => $params) {
             if (!is_array($params)) {
                 $params = array();
             }
             $this->class_register($class, $params);
         }
     }
     // include exception  for module
     // do not load core exception twice (when compressed core used)
     $inc = $this->root_dir . 'exception' . loader::DOT_PHP;
     if (fs::file_exists($inc) && !class_exists($this->get_tag() . '_exception')) {
         require_once $inc;
     }
     //
     // try to allocate router
     $router_class = '';
     $router_inc = $this->root_dir . 'router' . loader::DOT_PHP;
     if (fs::file_exists($router_inc)) {
         fs::req($router_inc);
         // class must be named {module}_router
         $router_class = $this->tag . '_router';
     } else {
         // use generic router
         $router_class = 'module_router';
     }
     if (!empty($router_class) && class_exists($router_class)) {
         $this->assign_router(new $router_class($this));
     }
     //
     // controller
     $controller_inc = $this->root_dir . 'controller' . loader::DOT_PHP;
     if (fs::file_exists($controller_inc)) {
         fs::req($controller_inc);
         // class must be named {module}_router
         $controller_class = $this->tag . '_controller';
     }
     if (!empty($controller_class) && class_exists($controller_class)) {
         $this->assign_controller(new $controller_class($this, $this->get_core()->lib('renderer')));
     }
     //
     // blocks
     $blocks_inc = $this->root_dir . 'blocks' . loader::DOT_PHP;
     if (fs::file_exists($blocks_inc)) {
         fs::req($blocks_inc);
         // class must be named {module}_router
         $blocks_class = $this->tag . '_blocks';
     } else {
         $blocks_class = 'module_blocks';
     }
     if (!empty($blocks_class) && class_exists($blocks_class)) {
         $this->assign_blocks(new $blocks_class($this));
     }
     /**
     // where is router?
     if (!$this->router)
     throw new tf_exception('wrong router');
     */
 }
Exemple #6
0
 /**
  * Load system lib
  * Used @see core::$system_libs
  */
 private static function load_system_lib($name)
 {
     if (!array_key_exists($name, self::$system_libs) || self::$libs->is_registered($name)) {
         return false;
     }
     $filename = '';
     $config = self::$system_libs[$name];
     $cl_name = $name;
     $params = null;
     if (is_array(self::$system_libs[$name])) {
         if (isset($config['file'])) {
             $filename = $config['file'];
         }
         if (isset($config['class'])) {
             $cl_name = $config['class'];
         }
         $params = @$config['params'];
     } else {
         $filename = $config;
     }
     // autoload
     if (!class_exists($cl_name)) {
         if (!$filename) {
             throw new core_exception('Error load system lib ' . $name . ' / ' . $cl_name);
         }
         try {
             fs::req(fs::get_full_path($filename . loader::DOT_PHP), true);
         } catch (fs_exception $fs_e) {
             throw new core_exception('Error load system lib ' . $name . '. ' . $fs_e->getMessage());
         }
     }
     // try with prefix
     if (!class_exists($cl_name, 0)) {
         $cl_name = loader::CLASS_PREFIX . $cl_name;
     }
     if (!class_exists($cl_name, 0)) {
         throw new core_exception('Class doesnt exists ' . $cl_name);
     }
     $plib = new $cl_name($params);
     return self::register_lib($name, $plib);
 }
Exemple #7
0
 /**
  * Load system lib
  * Used @see core::$system_libs
  */
 private static function load_system_lib($name)
 {
     if (!array_key_exists($name, self::$system_libs) || self::$libs->is_registered($name)) {
         return false;
     }
     try {
         fs::req(fs::get_full_path(self::$system_libs[$name] . loader::DOT_PHP), true);
     } catch (fs_exception $fs_e) {
         throw new core_exception('Error load system lib ' . $name . '. ' . $fs_e->getMessage());
     }
     $cl_name = $name;
     // try with prefix
     if (!class_exists($cl_name)) {
         $cl_name = loader::CLASS_PREFIX . $cl_name;
     }
     if (!class_exists($cl_name)) {
         throw new core_exception('Class doesnt exists ' . $cl_name);
     }
     self::register_lib($name, new $cl_name());
 }
 /**
  * Run action from file    
  * @param array|string array('action', 'file')
  * @param mixed for testing, otherwise controller params used
  */
 function run_file_action($name, $params = null)
 {
     $action = '';
     $file = '';
     $is_raw_file = false;
     if (is_array($name)) {
         $action = $name['action'];
         $file = $name['file'];
         if (isset($name['_file'])) {
             $file = $name['_file'];
             $is_raw_file = true;
         }
     } else {
         $file = $action = $name;
     }
     /*
     if (!empty($name['section'])) {
         $action = $name['section'] . '/' . $action;
     }
     */
     $action = str_replace('/', '_', $action);
     $fname = $file;
     //$is_raw_file ? $file : str_replace('_', '/', $file);
     $file = $this->get_context()->get_root() . 'actions/' . $fname . '.php';
     if (!file_exists($file)) {
         throw new controller_exception('Action file not found ' . $file);
     }
     fs::req($file);
     $class = $action . '_action';
     $class = core::get_instance()->modules()->ns($this->context->get_name(), $class);
     core::dprint(array("[CONTROLLER::RUN_FILE] %s from %s", $class, $file));
     if (!class_exists($class, 0)) {
         throw new router_exception('Action class not exists ' . $class);
     }
     if (empty($params)) {
         $params = $this->_params;
     }
     $action = new $class($this, $params);
     $action->run();
 }