/** * 路由配置 */ public function __construct() { $config = \H2O::getAppConfigs('request'); //请求配置信息 $this->_routeTable = isset($config['route']) ? $config['route'] : []; self::$getParams = $_GET; self::$postData = isset($_POST) ? $_POST : []; unset($_GET, $_POST); }
/** * 初始化 */ public function __construct() { $config = \H2O::getAppConfigs(); //获取应用配置信息 if (isset($config['basePath'])) { //应用程序主目录 $this->setBasePath($config['basePath']); } $this->init(); }
/** * 初始化sphinx服务 * @param string $tag 配置标识 默认为sphinx */ public function __construct($tag = 'sphinx') { $cnfp = \H2O::getAppConfigs('sphinx'); $this->connection = new \Foolz\SphinxQL\Connection(); if (isset($cnfp[$tag])) { $conf = $cnfp[$tag]; $this->connection->setParam(['host' => $conf['host'], 'port' => $conf['port']]); //设置连接参数 } }
/** * 初始化 */ public function __construct() { $class = strtolower(get_called_class()); $lastsp = strrpos($class, '\\'); $this->_namespace = substr($class, 0, $lastsp); $config = \H2O::getAppConfigs(); //获取应用配置信息 if (isset($config['defaultLayout'])) { //默认布局 $this->setLayout($config['defaultLayout']); } }
/** * 初始化应用 * @param string $tag 邮箱配置标识 * config example [ 'mailer' => [ 'default' => [ 'host' => 'smtp.163.com', 'port' => 25, 'from' => ['*****@*****.**'=>'测试公司'], 'username' => '*****@*****.**', 'password' => 'password' ], 'test' => [ 'host' => 'smtp.163.com', 'port' => 25, 'from' => ['*****@*****.**'=>'测试公司'], 'username' => '*****@*****.**', 'password' => 'password' ] ] ] */ public function __construct($tag = 'default') { $mailconf = \H2O::getAppConfigs('mailer'); if (empty($mailconf)) { throw new \Exception('Mailer config params is error'); } else { if (isset($mailconf[$tag])) { $this->_config = $mailconf[$tag]; $this->_transport = $this->_getTransport($this->_config); } else { throw new \Exception('Mailer config params is error: ' . $tag); } } }
/** * 初始化连接数据库句柄 * @param string $dsntag 数据库配置标识 方便多库调用 默认为db */ private function __construct($dsntag = 'db') { $db = \H2O::getAppConfigs('db'); $this->dsntag = $dsntag; if (isset($db[$dsntag])) { //配置参数存在 $config = $db[$dsntag]; //获取数据配置信息 $this->_checkconfig($config); $this->_open(); } else { //如果配置参数存在,则直接抛弃异常 throw new \Exception('Connect failure config is not found"' . $this->dsntag); } }
/** * 初始化 */ public function __construct() { $version = \H2O::getAppConfigs('version'); if (empty($version)) { throw new \Exception("Config set error: lost version param!"); } $nv = 'v' . str_replace('.', '', $version); $this->_migratedir = \H2O::getAppRootPath() . DS . 'migrate' . DS . $nv; $this->_namespace = \H2O::APP_ROOT_NAME . '\\migrate\\' . $nv; //命名空间 $this->_tpldir = H2O_PATH . DS . 'tpls' . DS . 'migrate' . DS; //迁移模块路径 file::createDirectory($this->_migratedir); //创建目录 $this->_runenv = \H2O::getRunEnv(); }
/** * 运行实例 */ public function run() { $configs = \H2O::getAppConfigs(); if (isset($configs['boot']) && !empty($configs['boot']) && is_array($configs['boot'])) { //加载引导程序 $this->_boot($configs['boot']); } $res = $this->handleRequest(); $debug = $configs['debug']; if ($debug === true) { //debug $logger = \H2O::getContainer('logger'); $logger->debugger($this->runExpend()); //记录运行状态 } echo $res; }
/** * 短信发送 * @param array $tag 配置信息模板标识 ['default','test'] 配置信息 [ 'alisms' => [ 'default' => [ 'appkey' => '23268950', //密钥 'secretKey' => '09003ad8710387cfd0742c9b7fd6aab2', //密钥 'tags' => [ 'test'=>'750_737' //短信模板标识 ] ] ] ] * @param string $m 多手机号 以逗号分隔 * @param array $data 替换变量 */ function AliSmsSend($tag, $m, $data) { $c = new \TopClient(); $smsconf = \H2O::getAppConfigs('alisms'); if (empty($smsconf)) { throw new \Exception('Ali SMS config params is error'); } else { if (isset($smsconf[$tag[0]])) { $config = $smsconf[$tag[0]]; } else { throw new \Exception('Ali SMS config params is error: ' . $tag[0]); } } $c->appkey = $config['appkey']; $c->secretKey = $config['secretKey']; $req = new \OpenSmsSendmsgRequest(); $smrequest = new \SendMessageRequest(); $em = explode(',', $m); $ids = explode('_', $config['tags'][$tag[1]]); $smrequest->template_id = $ids[0]; //模板ID $smrequest->signature_id = $ids[1]; //签名ID $smrequest->context = json_decode(json_encode($data)); //模板变量替换 foreach ($em as $v) { // $smrequest->external_id="demo"; // $smrequest->mobile="18610638306,13520839197"; $smrequest->mobile = $v; // $smrequest->device_limit="123"; // $smrequest->session_limit="123"; // $smrequest->device_limit_in_time="123"; // $smrequest->mobile_limit="123"; // $smrequest->session_limit_in_time="123"; // $smrequest->mobile_limit_in_time="123"; // $smrequest->session_id="demo"; // $smrequest->domain="demo"; // $smrequest->device_id="demo"; $req->setSendMessageRequest(json_encode($smrequest)); $resp = $c->execute($req); return $resp->result->successful; } }
/** * 根据队列配置启动队列 只支持单个子进程任务 */ private function _startProc() { $adaemons = \H2O::getAppConfigs('daemon'); $tasks = $this->_getTasksName(); foreach ($adaemons['route'] as $route) { $tmpdir = $this->_logpath . 'daemon' . DS . strtolower($route); //当前任务日志目录 file::createDirectory($tmpdir); //如果目录不存在,则创建 $_logFile = $tmpdir . DS . date('Ymd') . '.log'; //根据路由规则按天记录 if (!in_array($route, $tasks)) { //每个任务只充许一个进程在执行 $_cmd = "{$this->_daemonson} @service.daemon --c={$route} >>{$_logFile} 2>&1 &" . PHP_EOL; $_pp = popen($_cmd, 'r'); pclose($_pp); } } }
/** * @return array 开发者信息 */ private function _devauthor() { $config = \H2O::getAppConfigs('devauthor'); //读取开发者配置信息 return ['T_PROGRAM' => isset($config['program']) ? $config['program'] : '', 'T_AUTHOR' => isset($config['author']) ? $config['author'] : '', 'T_DEVTIME' => date('Y-m-d H:i:s')]; }