Esempio n. 1
0
 public function _init(Yaf_Dispatcher $dispatcher)
 {
     // auto start session
     Yaf_Session::getInstance()->start();
     // auto load config data
     $this->config = Yaf_Application::app()->getConfig();
     Yaf_Registry::set('Config', $this->config);
     //auto load redis
     $redis = new Redis();
     $redis->connect($this->config->redis->host, $this->config->redis->port, $this->config->redis->timeout, $this->config->redis->reserved, $this->config->redis->interval);
     Yaf_Registry::set('Redis', $redis);
     //auto load mysql
     Yaf_Registry::set('DbRead', new Db('mysql:host=' . $this->config->mysql->read->host . ';dbname=' . $this->config->mysql->read->dbname . ';charset=' . $this->config->mysql->read->charset . ';port=' . $this->config->mysql->read->port . '', $this->config->mysql->read->username, $this->config->mysql->read->password));
     Yaf_Registry::set('DbWrite', new Db('mysql:host=' . $this->config->mysql->write->host . ';dbname=' . $this->config->mysql->write->dbname . ';charset=' . $this->config->mysql->write->charset . ';port=' . $this->config->mysql->write->port . '', $this->config->mysql->write->username, $this->config->mysql->write->password));
     // auto load model
     Yaf_Registry::set('I18n', new I18nModel($redis, $this->config->application->name, 'cn'));
     Yaf_Registry::set('Cache', new CacheModel($redis, $this->config->application->name));
     // auto load plugin
     $dispatcher->registerPlugin(new GlobalPlugin());
     // auto save request
     $request = $dispatcher->getRequest();
     // auto set ajax is no render
     if ($request->isXmlHttpRequest()) {
         $dispatcher->autoRender(false);
     }
     // auto set http protocol to action except http get protocol
     if (!$request->isGet()) {
         $dispatcher->setDefaultAction($request->getMethod());
     }
 }
Esempio n. 2
0
 function errorAction($exception)
 {
     // fallback views path to global when error occured in modules.
     $config = Yaf_Application::app()->getConfig();
     $this->getView()->setScriptPath($config->application->directory . "/views");
     $this->getView()->e = $exception;
     $this->getView()->e_class = get_class($exception);
     $this->getView()->e_string_trace = $exception->getTraceAsString();
     $params = $this->getRequest()->getParams();
     unset($params['exception']);
     $this->getView()->params = array_merge(array(), $params, $this->getRequest()->getPost(), $this->getRequest()->getQuery());
     switch ($exception->getCode()) {
         case YAF_ERR_AUTOLOAD_FAILED:
         case YAF_ERR_NOTFOUND_MODULE:
         case YAF_ERR_NOTFOUND_CONTROLLER:
         case YAF_ERR_NOTFOUND_ACTION:
             header('HTTP/1.1 404 Not Found');
             break;
         case 401:
             $this->forward('Index', 'application', 'accessDenied');
             header('HTTP/1.1 401 Unauthorized');
             Yaf_Dispatcher::getInstance()->disableView();
             echo $this->render('accessdenied');
             break;
         default:
             //header("HTTP/1.1 500 Internal Server Error");
             core::dump($exception);
             break;
     }
 }
Esempio n. 3
0
 /**
  * 把配置存到注册表
  */
 function _initConfig()
 {
     Yaf_Registry::set("config", $config = Yaf_Application::app()->getConfig());
     define('PATH_APP', $config->application->directory);
     define('PATH_TPL', PATH_APP . '/views');
     define('USER_IP', Tool_Fnc::realip());
 }
Esempio n. 4
0
 /**
  * Connect to MySQL [Support read/write splitting]
  *
  * @param string => use default DB if parameter is not specified !
  * @return NULL
  */
 private function connect($type = 'WRITE')
 {
     $config = Yaf_Application::app()->getConfig();
     $db = $config['Default'];
     $driver = $config['TYPE'];
     $host = $config[$type . '_HOST'];
     $port = $config[$type . '_PORT'];
     $user = $config[$type . '_USER'];
     $pswd = $config[$type . '_PSWD'];
     if (!$port) {
         $port = 3306;
     }
     $dsn = $driver . ':host=' . $host . ';port=' . $port . ';dbname=' . $db;
     try {
         if (!self::$obj[$type]) {
             self::$conn = self::$obj[$type] = new PDO($dsn, $user, $pswd);
             self::$conn->query('SET NAMES utf8');
             unset($db, $driver, $host, $port, $user, $pswd, $dsn);
         }
     } catch (PDOException $e) {
         if (ENV == 'DEV') {
             Helper::raiseError(debug_backtrace(), $e->getMessage());
         } else {
             file_put_contents($this->logFile, $e->getMessage() . PHP_EOL, FILE_APPEND);
         }
     }
 }
Esempio n. 5
0
 private function _generateShare($url)
 {
     $config = Yaf_Application::app()->getConfig();
     $appID = $config['wx_appID'];
     $appSecret = $config['wx_appSecret'];
     $share['appID'] = $appID;
     $share['timestamp'] = CUR_TIMESTAMP;
     $share['nonceStr'] = 'Wu5WZYThz1wzccnX';
     $share['link'] = $url;
     // 验证 ticket 是否失效
     $m_ticket = $this->load('Ticket');
     $ticket = $m_ticket->SelectOne();
     $gap = CUR_TIMESTAMP - $ticket['addTime'];
     if (!$ticket['ticket'] || $gap > 7200) {
         // Get token
         $token = $this->_getToken($appID, $appSecret);
         // Get ticket
         $ticket = $this->_getTicket($token);
         if ($ticket) {
             $jsapi_ticket = $m['ticket'] = $ticket;
             $m['addTime'] = CUR_TIMESTAMP;
             $where = 1;
             $m_ticket->Delete($where);
             $m_ticket->Insert($m);
         }
     } else {
         $jsapi_ticket = $ticket['ticket'];
     }
     // Get signature
     $string1 = 'jsapi_ticket=' . $jsapi_ticket . '&noncestr=' . $share['nonceStr'];
     $string1 .= '&timestamp=' . $share['timestamp'] . '&url=' . $url;
     $share['signature'] = sha1($string1);
     return $share;
 }
Esempio n. 6
0
 public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
 {
     //pr($request);
     $modules = Yaf_Application::app()->getModules();
     $uri = $request->getRequestUri();
     $uriInfo = explode('/', $uri);
     $module = ucfirst($uriInfo[1]);
     $controller = $uriInfo[2];
     $action = $uriInfo[3];
     if (!in_array($module, $modules)) {
         $module = 'index';
         $controller = $uriInfo[1];
         $action = $uriInfo[2];
     }
     $request->setModuleName(ucfirst($module));
     if (!$controller) {
         $controller = 'index';
     }
     $request->setControllerName(ucfirst($controller));
     if (!$action) {
         $action = 'index';
     }
     $request->setActionName($action);
     //pr($request);
 }
Esempio n. 7
0
 public function __construct()
 {
     $config = Yaf_Application::app()->getConfig();
     Yaf_Loader::import('L_Wechat');
     $options = array('token' => self::WX_TOKEN, 'appid' => $config['wx_appID'], 'appsecret' => $config['wx_appsecret'], 'access_token' => $config['wx_access_token'], 'expires' => $config['wx_expires']);
     $this->wxSDK = new L_Wechat($options);
 }
Esempio n. 8
0
 public function _initPlugin(Yaf_Dispatcher $dispatcher)
 {
     // set include paths of the system.
     set_include_path(get_include_path() . PATH_SEPARATOR . Yaf_Loader::getInstance()->getLibraryPath());
     /* register a billrun plugin system from config */
     $config = Yaf_Application::app()->getConfig();
     if (isset($config->plugins)) {
         $plugins = $config->plugins->toArray();
         $dispatcher = Billrun_Dispatcher::getInstance();
         foreach ($plugins as $plugin) {
             Billrun_Log::getInstance()->log("Load plugin " . $plugin, Zend_log::DEBUG);
             $dispatcher->attach(new $plugin());
         }
     }
     if (isset($config->chains)) {
         $chains = $config->chains->toArray();
         $dispatcherChain = Billrun_Dispatcher::getInstance(array('type' => 'chain'));
         foreach ($chains as $chain) {
             Billrun_Log::getInstance()->log("Load plugin " . $chain, Zend_log::DEBUG);
             $dispatcherChain->attach(new $chain());
         }
     }
     // make the base action auto load (required by controllers actions)
     Yaf_Loader::getInstance(APPLICATION_PATH . '/application/helpers')->registerLocalNamespace('Action');
 }
Esempio n. 9
0
 public function __construct()
 {
     $config = Yaf_Application::app()->getConfig();
     Yaf_Loader::import('L_Wechat.class.php');
     $options = array('token' => $config['wx_token'], 'appid' => $config['wx_appID'], 'appsecret' => $config['wx_appSecret']);
     $this->wxSDK = new L_Wechat($options);
 }
Esempio n. 10
0
 public function callbackAction()
 {
     $mediaqqmodel = new Media_QQModel($this->_basemodel, $this->_qqparam);
     $app_id = isset($_REQUEST['app_id']) ? trim($_REQUEST['app_id']) : '69948denMVMoBujYGLSFGUHbkvP7E3';
     $mediaqq = $mediaqqmodel->getApp($app_id);
     $APPID = $mediaqq['APPID'] && $mediaqq['APPKEY'] ? $mediaqq['APPID'] : $mediaqq['def_APPID'];
     $APPKEY = $mediaqq['APPID'] && $mediaqq['APPKEY'] ? $mediaqq['APPKEY'] : $mediaqq['def_APPKEY'];
     $redirect_uri = $this->_qqparam['redirect_uri'] . '?app_id=' . $mediaqq['app_id'];
     $state = md5($mediaqq['app_key']);
     $qcinit = new QQAPI_YafQQConnetAPI();
     $qc = new QC();
     $access_token = $qc->qq_callback($APPID, $redirect_uri, $APPKEY);
     echo $access_token . '----------';
     $openid = $qc->get_openid($access_token);
     echo $openid . '---------';
     $qqUser = $qc->my_get_userinfo($access_token, $openid, $APPID);
     if ($qqUser && $qqUser->nickname) {
         $media_user_id = $mediaqqmodel->saveUser($openid, $qqUser, $APPID);
         if ($media_user_id) {
             $usertokentime = date('Y-m-d H:i:s', time() + Yaf_Application::app()->getConfig()->application->usertokentime);
             $login_token = $mediaqqmodel->saveAccessToken($app_id, $access_token, $openid, $media_user_id, $usertokentime);
             if ($login_token) {
                 $url = $mediaqq['token_url'];
                 $concat = '&';
                 if (strpos($url, '?') === false) {
                     $concat = '?';
                 }
                 $url .= $concat . "token={$login_token}";
                 header("Location:{$url}");
             }
         }
     }
     exit;
 }
Esempio n. 11
0
 public function _initSmarty(Yaf_Dispatcher $dispatcher)
 {
     /* init smarty view engine */
     Yaf_Loader::import("Smarty/Adapter.php");
     $smarty = new Smarty_Adapter(null, Yaf_Application::app()->getConfig()->smarty);
     $dispatcher->setView($smarty);
 }
Esempio n. 12
0
 public function _initDefaultDbAdapter()
 {
     //新建对象
     $dbAdapter = new Zend\Db\Adapter\Adapter(Yaf_Application::app()->getConfig()->mysql->write->toArray());
     //设为全局变量
     Yaf_Registry::set("db", $dbAdapter);
 }
Esempio n. 13
0
 public function _initConfig()
 {
     //把配置保存起来
     $this->arrConfig = Yaf_Application::app()->getConfig();
     $arrConfig = Yaf_Application::app()->getConfig();
     Yaf_Registry::set('config', $arrConfig);
 }
Esempio n. 14
0
 public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
 {
     $modules = Yaf_Application::app()->getModules();
     $uri = $request->getRequestUri();
     $uriInfo = explode('/', $uri);
     $module = ucfirst($uriInfo[1]);
     if (!in_array($module, $modules)) {
         $module = 'index';
         // 由于 YAF 源码只不支持大小写混写的控制器和 Action名, 这里来满足
         if ($request->controller) {
             if (strtoupper($request->controller) == strtoupper($uriInfo[1])) {
                 $controller = ucfirst($uriInfo[1]);
                 $request->setControllerName($controller);
             }
         }
         if ($request->action) {
             if (strtoupper($request->action) == strtoupper($uriInfo[2])) {
                 $request->setActionName($uriInfo[2]);
             }
         }
     } else {
         $request->setModuleName($module);
         $request->setControllerName(ucfirst($uriInfo[2]));
         $action = $uriInfo[3];
         if (!$action) {
             $action = 'index';
         }
         $request->setActionName($action);
     }
     //pr($request);
 }
Esempio n. 15
0
 /**
  * 初始化函数
  * 1、时区设置
  * 2、数据库连接配置
  */
 public function init()
 {
     header("Content-type: application/json; charset=utf-8");
     ini_set('date.timezone', 'Asia/Shanghai');
     //获取数据库连接信息
     $this->_db = Base_Db::getInstance(Yaf_Application::app()->getConfig()->application->db->toArray());
     $this->_basemodel = new BasedbModel($this->_db);
 }
Esempio n. 16
0
 public static function site_url($a)
 {
     $config = Yaf_Application::app()->getConfig();
     $ext = $config->pro->ext;
     $site = $config->pro->site;
     $site = !empty($site) ? $site : 'http://' . $_SERVER['HTTP_HOST'] . '/';
     return $site . $a . $ext;
 }
Esempio n. 17
0
 public function getApp()
 {
     if (self::$__app === null) {
         self::$__app = Yaf_Application::app();
         $this->app = self::$__app;
     }
     return self::$__app;
 }
Esempio n. 18
0
File: Config.php Progetto: wuxw/YYF
 private static function getConfig()
 {
     if (null === self::$_config) {
         $config = Yaf_Application::app()->getConfig()->toArray();
         self::$_config = new Yaf_Config_Simple($config, false);
     }
     return self::$_config;
 }
Esempio n. 19
0
 public function getConfig()
 {
     if (self::$__config === null) {
         self::$__config = Yaf_Application::app()->getConfig();
         $this->config = self::$__config;
     }
     return self::$__config;
 }
Esempio n. 20
0
 public function _initZendDb(Yaf_Dispatcher $dispatcher)
 {
     $arrConfig = Yaf_Application::app()->getConfig();
     $zendDb = new Zend_Db();
     $params = array('host' => $arrConfig->mysql->read->host, 'username' => $arrConfig->mysql->read->username, 'password' => $arrConfig->mysql->read->password, 'dbname' => $arrConfig->mysql->read->dbname, 'port' => $arrConfig->mysql->read->port);
     $db = $zendDb->factory('PDO_MYSQL', $params);
     Yaf_Registry::set('db', $db);
 }
Esempio n. 21
0
 public function _initConfig(Yaf_Dispatcher $dispatcher)
 {
     $this->config = Yaf_Application::app()->getConfig();
     Yaf_Registry::set('config', $this->config);
     //判断请求方式,命令行请求应跳过一些HTTP请求使用的初始化操作,如模板引擎初始化
     define('REQUEST_METHOD', strtoupper($dispatcher->getRequest()->getMethod()));
     Yaf_Loader::import(APPLICATION_PATH . '/conf/defines.inc.php');
 }
Esempio n. 22
0
 /**
  * method to get the instance of the class (singleton)
  */
 public static function getInstance()
 {
     if (is_null(self::$instance)) {
         $config = Yaf_Application::app()->getConfig();
         self::$instance = new self($config);
     }
     return self::$instance;
 }
Esempio n. 23
0
function error_handlerTestCase020($errno, $errstr, $errfile, $errline)
{
    $GLOBALS['errNoTestCase020BeforeClear'] = Yaf_Application::app()->getLastErrorNo();
    $GLOBALS['errMessageTestCase020BeforeClear'] = Yaf_Application::app()->getLastErrorMsg();
    Yaf_Application::app()->clearLastError();
    $GLOBALS['errNoTestCase020AfterClear'] = Yaf_Application::app()->getLastErrorNo();
    $GLOBALS['errMessageTestCase020AfterClear'] = Yaf_Application::app()->getLastErrorMsg();
}
 public function _initConfig()
 {
     Yaf_Dispatcher::getInstance()->autoRender(FALSE);
     // 关闭自动加载模板
     //把配置保存起来
     $arrConfig = Yaf_Application::app()->getConfig();
     Yaf_Registry::set('config', $arrConfig);
 }
Esempio n. 25
0
 /**
  * Init Redis
  */
 public function _initRedis(Yaf_Dispatcher $dispatcher)
 {
     $config = Yaf_Application::app()->getConfig();
     $redis = new Redis();
     $redis->connect($config['redis_host'], $config['redis_port']);
     Yaf_Registry::set('redis', $redis);
     // TODO sms Redis queue
     //Yaf_Registry::set('redis_queue_sms', $config['redis_queue_sms']);
 }
Esempio n. 26
0
 public function _initConfig(Yaf_Dispatcher $dispatcher)
 {
     $config = Yaf_Application::app()->getConfig();
     Yaf_Registry::set("config", $config);
     $sysConfig = (include APP_PATH . "/conf/config.php");
     Yaf_Registry::set("sysConfig", $sysConfig);
     $dispatcher->autoRender(FALSE);
     //全局关闭渲染
 }
 public function insertCardFlowAction()
 {
     $host = Yaf_Application::app()->getConfig()->crontab->flow->host;
     //获取接口域名
     $date = date("Y-m-d");
     //同步当天时间
     //查看当天是否已有成功执行的记录,有则不在同步(一天同步一次)
     //        $re = TZ_Loader::model('Crontablog', 'Crontab')->select(array("status:eq" => 1, "type:eq" => 1, "created_at:eq" => $date), "id", "ROW");
     //        if (!empty($re)) {
     //            echo "今天已经同步过数据";
     //            die;
     //        }
     //查询最后一个手机号添加时间
     $url = $host . "/traffic_find_web/getLastCardTime";
     $cardLastTime = TZ_Loader::service("Data", "Crontab")->getData($url);
     //var_dump($cardLastTime);die;
     if ($cardLastTime == "fail") {
         //处理  插入错误原因为”查询最后一个手机号添加时间失败“
         $arError = array("data" => "查询最后一个手机号添加时间失败", "status" => 0, "created_at" => $date, "updated_at" => $date);
         TZ_Loader::model('Crontablog', 'Crontab')->insert($arError);
         echo "查询最后一个手机号添加时间失败";
         die;
     } else {
         $condition['created_at:gt'] = $cardLastTime;
         //$condition['limit'] = 1;
         $data = TZ_Loader::model('CardFlow', 'Flow')->select($condition, "id,pid,pname,ctelephone,cpid,ccid,operate_name as operateName,start_date as startDate,end_date as endDate,status,updated_at as updatedAt,created_at as createdAt", "ALL");
         //var_dump($data);
         if (empty($data)) {
             //处理成功 插入一条数据
             $arOk = array("data" => "无任何数据更新", "status" => 1, "created_at" => $date, "updated_at" => $date);
             TZ_Loader::model('Crontablog', 'Crontab')->insert($arOk);
             echo "没有最新数据";
             die;
         } else {
             $data = array("card" => $data);
             $json = json_encode($data);
         }
     }
     //var_dump($json);die;
     //调取插入数据接口
     $url1 = $host . "/traffic_find_web/insertCardFlow";
     $dataNew["cards"] = $json;
     $result = TZ_Loader::service("Data", "Crontab")->postData($dataNew, $url1);
     if ($result == "fail") {
         //处理失败  插入错误原因为”批量插入手机号失败“
         $arError = array("data" => "批量插入手机号失败", "status" => 0, "created_at" => $date, "updated_at" => $date);
         TZ_Loader::model('Crontablog', 'Crontab')->insert($arError);
         echo "插入数据失败";
         die;
     } elseif ($result == "success") {
         //处理成功 插入一条数据
         $arOk = array("data" => "数据同步成功", "status" => 1, "created_at" => $date, "updated_at" => $date);
         TZ_Loader::model('Crontablog', 'Crontab')->insert($arOk);
         echo "同步成功";
         die;
     }
 }
Esempio n. 28
0
 function __construct()
 {
     Yaf_Loader::import('qiniu/io.php');
     Yaf_Loader::import('qiniu/rs.php');
     $config = Yaf_Application::app()->getConfig();
     $this->bucket = $config['qiniu_bucket'];
     $this->accessKey = $config['qiniu_accessKey'];
     $this->secretKey = $config['qiniu_secretKey'];
 }
Esempio n. 29
0
 public function __construct($dbpath = "gamedb")
 {
     try {
         $config = Yaf_Application::app()->getConfig();
         $this->database = new XapianWritableDatabase($config->search->db->dir . $dbpath, Xapian::DB_CREATE_OR_OPEN);
     } catch (Exception $e) {
         print $e->getMessage() . "\n";
     }
 }
Esempio n. 30
0
 function __construct($mobile = '', $msg = '')
 {
     $config = Yaf_Application::app()->getConfig();
     $this->username = $config['sms_username'];
     $this->password = $config['sms_password'];
     $this->mobile = $mobile;
     $this->msg = $msg;
     $this->url = $config['sms_url'];
 }