Exemple #1
0
 /**
  * 依据配置文件数组创建一个类
  * array('class'=>'xxxxx','import'=>'lib.go', 'a'=>'b')
  * 其他将被注入到参数中
  *
  * @param $config
  * @return mixed
  * @throws Exception
  */
 public function createComponent($config)
 {
     if (!is_array($config)) {
         return $config;
     }
     if (empty($config['class'])) {
         return $config;
     }
     if (!empty($config['import'])) {
         foreach ($config['import'] as $imt) {
             Flow::import($imt);
         }
     }
     $class_name = $config['class'];
     $comp = new $class_name();
     unset($config['class']);
     unset($config['import']);
     foreach ($config as $key => $val) {
         $comp->{$key} = $this->createComponent($val);
     }
     $comp->init();
     return $comp;
 }
Exemple #2
0
 /**
  * 应用初始化
  * @throws Exception
  */
 public function init()
 {
     if (!defined("DEV_MODE")) {
         define("DEV_MODE", false);
     }
     // 定义路径检测
     if (!defined("APP_PATH")) {
         throw new Exception("No APP_PATH Defined");
     }
     $this->setPathOfAlias('system', __DIR__);
     $this->setPathOfAlias('application', APP_PATH);
     Flow::import("system.core.Loader", true);
     // 初始化class_loader
     $class_loader = new F_Core_Loader();
     $class_loader->registerAutoLoader();
     // 加载所有配置文件
     $this->_loadcfg();
     // 开发模式配置
     $this->initDevMode();
     // import all
     $imports = isset(self::$cfg["import"]) ? self::$cfg["import"] : array();
     foreach ($imports as $import) {
         Flow::import($import);
     }
     // 初始化所有系统底层组件
     $components = isset(self::$cfg["components"]) ? self::$cfg["components"] : array();
     foreach ($components as $name => $config) {
         self::app()->setComponent($name, $config);
     }
 }