Esempio n. 1
0
 /**
  *
  * @param ZcAction $action
  * @param ZcAction $error
  */
 private function execute($action, $error)
 {
     if (file_exists($action->getFile())) {
         //加载语言
         ZcFactory::getLanguageObject()->loadControllerLanguageByRoute($action->getRoute());
         //实例化类
         require_once $action->getFile();
         $class = $action->getClass();
         $controller = new $class($action->getRoute());
         if (is_callable(array($controller, $action->getMethod()))) {
             if (is_callable(array($controller, 'beforeAction'))) {
                 call_user_func_array(array($controller, 'beforeAction'), array());
             }
             $action = call_user_func_array(array($controller, $action->getMethod()), $action->getArgs());
             if (is_callable(array($controller, 'afterAction'))) {
                 call_user_func_array(array($controller, 'afterAction'), array());
             }
         } else {
             $action = $error;
         }
     } else {
         $action = $error;
     }
     return $action;
 }
Esempio n. 2
0
 public function __construct()
 {
     $urlHandlerConfig = ZcFactory::getConfig()->get(ZcConfigConst::UrlHandler);
     if (!empty($urlHandlerConfig['file'])) {
         require_once Zc::C(ZcConfigConst::DirFsApp) . $urlHandlerConfig['file'];
     }
     $this->urlHandler = new $urlHandlerConfig['class']();
 }
 protected function getDbLink()
 {
     if ($this->dbLink) {
         return $this->dbLink;
     }
     $config = ZcFactory::getConfig();
     $this->dbLink = new ZcDbSimpleMysql($config->get(ZcConfigConst::MonitorDbServer), $config->get(ZcConfigConst::MonitorDbUsername), $config->get(ZcConfigConst::MonitorDbPassword), $config->get(ZcConfigConst::MonitorDbDatabase));
     return $this->dbLink;
 }
Esempio n. 4
0
 private static function initConfig()
 {
     $config = ZcFactory::getConfig();
     //获取绝对路径的自动加载目录
     $dirsFs = $config->get(ZcConfigConst::AutoloadDirsFs);
     if (!empty($dirsFs)) {
         foreach ($dirsFs as $dir) {
             self::$autoloadDirs[] = rtrim(trim($dir), '/') . '/';
         }
     }
     //获取应用路径的自动加载目录
     $dirsWs = $config->get(ZcConfigConst::AutoloadDirsWs);
     $dirApp = $config->get(ZcConfigConst::DirFsApp);
     if (!empty($dirsWs)) {
         foreach ($dirsWs as $dir) {
             self::$autoloadDirs[] = $dirApp . trim(trim($dir), '/') . '/';
         }
     }
     self::$autoloadClassFileMapping = $config->get(ZcConfigConst::AutoloadClassFileMapping);
     //自动加载文件
     self::$includeFiles = $config->get(ZcConfigConst::AutoloadIncludeFiles);
 }
Esempio n. 5
0
 /**
  * Zc框架执行Web MVC的入口函数。
  *
  * 我考虑是否把init方法作为私有,而然runMVC来得到rootdir和appdir,调用init来完成初始化框架和应用工作。
  * 这样其实隐含的一个逻辑,整个Zc框架,可以随着runMVC的参数不同,可以去跑不同的app应用。这个时候还需要把所有的Factory的对象池都清空掉。
  * 总之,需要把Zc的对象池都清空。
  */
 public static function runMVC($route = '')
 {
     //Zc::dump(ZcFactory::getConfig());
     //确保关闭魔术引号
     self::cleanQuotes();
     //URL rewrite
     $zcUrl = ZcFactory::getUrl();
     $zcUrl->parse();
     if (empty($route)) {
         $route = isset($_GET['route']) ? $_GET['route'] : Zc::C(ZcConfigConst::DefaultRoute);
     }
     $action = new ZcAction($route);
     $dispatcher = new ZcDispatcher();
     $dispatcher->dispatch($action);
 }
Esempio n. 6
0
 public function __construct($currentLanguage, $defaultLanguage)
 {
     $this->currentLanguage = $currentLanguage;
     $this->defaultLanguage = $defaultLanguage;
     $this->baseDir = ZcFactory::getConfig()->get(ZcConfigConst::DirFsApp) . 'languages/';
 }