/** * 初始化APP的数据 * * @param string $app 启用的app的名称,如:test */ private static function initApp($app) { if (empty($app)) { return FALSE; } Ym_Timer::startRecord(); define('YPP_APP', $app); define('YPP_APP_ROOT', YPP_DIR_APP . '/' . YPP_APP); define('YPP_APP_LIB', YPP_APP_ROOT . '/library'); define('YPP_APP_LOG', YPP_DIR_LOG . '/' . YPP_APP); // 声明loader,加载APP类文件 Yaf_Loader::getInstance(YPP_APP_LIB); // 初始化配置 Ym_Config::init(); $env = Ym_Config::getAppItem('env:monitor.env'); if ($env) { define('YPP_APP_ENV', $env); } else { define('YPP_APP_ENV', 'dev'); } // 初始化日志 if (YPP_APP_ENV == 'pro') { $logConf['levels'] = array('debug' => 1, 'warning' => 4, 'error' => 5, 'fatal' => 6, 'alert' => 7, 'emergency' => 8); } $logConf['logPath'] = YPP_APP_LOG; $logConf['logFile'] = YPP_APP; Ym_Logger::init($logConf); //Ym_Logger::info('test'); // 加载application.ini self::$app = new Yaf_Application(YPP_DIR_CONF . '/app/' . YPP_APP . '/application.ini'); }
/** * 设置连接字符串 */ private function setConnectionString($name) { Ym_Config::init(); $config = Ym_Config::getAppItem('monitor'); $this->host = trim($config['mongo'][$name]['host']); $this->port = trim($config['mongo'][$name]['port']); $this->user = trim($config['mongo'][$name]['user']); $this->pass = trim($config['mongo'][$name]['pass']); $this->dbName = trim($config['mongo'][$name]['dbname']); $this->querySafety = trim($config['mongo'][$name]['query_safety']); $connectionString = "mongodb://"; if (empty($this->host)) { Sys_Common::showError("The Host must be set to connect to MongoDB", 'MongoDB'); } if (empty($this->dbName)) { Sys_Common::showError("The Database must be set to connect to MongoDB", 'MongoDB'); } if (!empty($this->user) && !empty($this->pass)) { $connectionString .= "{$this->user}:{$this->pass}"; } if (isset($this->port) && !empty($this->port)) { $connectionString .= "{$this->host}:{$this->port}"; } else { $connectionString .= "{$this->host}"; } $this->connectionString = trim($connectionString); }
/** * Yaf client command * * @author Xuexb<*****@*****.**> * @package xiaobo/sh * @since Version 1.0.1 @20140423 * @copyright Copyright (c) 2014, Yeahmobi, Inc. */ date_default_timezone_set('Asia/Shanghai'); define('YPP_APP', 'yeahmonitor'); define('YPP_APP_ROOT', YPP_DIR_APP . '/' . YPP_APP); define('YPP_APP_LIB', YPP_APP_ROOT . '/library'); // 声明loader Yaf_Loader::getInstance(YPP_APP_LIB, YPP_ROOT_PHPLIB); // 初始化配置和日志类 Ym_Config::init(); $logConf['logPath'] = YPP_DIR_LOG . '/app/' . YPP_APP; $logConf['logFile'] = YPP_APP; Ym_Logger::init($logConf); // 加载application.ini $app = new Yaf_Application(YPP_DIR_CONF . '/app/' . YPP_APP . '/application.ini'); $app->bootstrap(); $app->getDispatcher()->dispatch(new Yaf_Request_Simple()); //方法2:不试用带module的模式 //$controller = isset($argv[1]) ? $argv[1] : ''; //$action = isset($argv[2]) ? $argv[2] : ''; //if (!$controller || !$action) { // die('Please Use like this: /dianyi/app/ypp/bin/php yafClient.php controller action [argv]' . PHP_EOL); //} //$argv = isset($argv[3]) ? $argv[3] : ''; //$res = $app->execute(array('Controller_' . $controller, $action . 'Action'), $argv);