Beispiel #1
0
 /**
  * 实例化调用方法,传递需要的数据到模板
  */
 protected function run()
 {
     $_function_get = 'get_' . $this->class_key;
     #$_class_key = $this->object_code.'_'.$this->class_key;
     #$this->add_data($_class_key,$this->$_function_get());
     #DebugTools::print_r($this->$_function_get());
     if ($this->output == 'html') {
         $dir = Yaf_Registry::get('config')->application->directory . '/widgets/views/';
         $widget_view = new Yaf_View_Simple($dir);
         $widget_view->assign('data', $this->{$_function_get}());
         $widget_view->assign('assist_data', $this->assist_data);
         echo $widget_view->render($this->class_key . '.phtml');
         #DebugTools::print_r($res);
         #Yaf_Loader::getInstance()->import($dir.'/item_condition.phtml');
         #DebugTools::print_r($widget_view);
         /*if (empty($this->view)){$this->view = $this->class_key;}
           $this->render($this->view,array(
               'data'=>$this->$_function_get(),
               'assist_data'=>$this->assist_data
           ));*/
     } else {
         if ($this->output == 'json') {
             $this->output_json($this->{$_function_get}());
         } else {
             if ($this->output == 'array') {
                 $this->output_array($this->{$_function_get}());
             }
         }
     }
 }
Beispiel #2
0
 public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response)
 {
     $config = \Yaf_Registry::get('configarr');
     $dispatcher = Yaf_Dispatcher::getInstance();
     $twig = '';
     // view 放在module 目录里
     if ($request->module == $config['application']['dispatcher']['defaultModule']) {
         $twig = new \Core_Twig(APP_PATH . 'views', $config['twig']);
     } else {
         $twig = new \Core_Twig(APP_PATH . 'modules/' . $request->module . '/views', $config['twig']);
     }
     // url generate
     $twig->twig->addFunction("url", new Twig_Function_Function("Tools_help::url"));
     // 语言对应
     $twig->twig->addFunction("lang", new Twig_Function_Function("Tools_help::lang"));
     // 图片路径
     $twig->twig->addFunction("fbu", new Twig_Function_Function("Tools_help::fbu"));
     // 数字验证
     $twig->twig->addFunction("is_numeric", new Twig_Function_Function("is_numeric"));
     // 处理错误提醒
     $session_key = array('ErrorMessageStop', 'ErrorMessage', 'Message');
     foreach ($session_key as $value) {
         $twig->assign($value, Tools_help::getSession($value));
         Tools_help::setSession($value, '');
     }
     $dispatcher->setView($twig);
 }
Beispiel #3
0
 /**
  * @param array $config 配置参数
  * @param $driver 上传驱动 Local-本地上传驱动,FTP-FTP上传驱动
  */
 public function __construct($config = array(), $driver)
 {
     //获取上传配置
     $options = Yaf_Registry::get('uploadbase');
     /* 获取配置 */
     $this->config = array_merge($this->config, $config);
     //上传驱动名称
     $driver = $driver ? $driver : ($this->driver ? $this->driver : $options['type']);
     //生成上传驱动名
     $class = strpos($driver, '\\') ? $driver : ucfirst(strtolower($driver));
     //设置上传驱动
     $this->setDriver($class);
     /* 调整配置,把字符串配置参数转换为数组 begin */
     if (!empty($this->config['mimes'])) {
         if (is_string($this->mimes)) {
             $this->config['mimes'] = explode(',', $this->mimes);
         }
         $this->config['mimes'] = array_map('strtolower', $this->mimes);
     }
     if (!empty($this->config['exts'])) {
         if (is_string($this->exts)) {
             $this->config['exts'] = explode(',', $this->exts);
         }
         $this->config['exts'] = array_map('strtolower', $this->exts);
     }
     /* 调整配置,把字符串配置参数转换为数组 end */
 }
Beispiel #4
0
 public function __call($func, $args)
 {
     if (false == \Yaf_Registry::has($func)) {
         return $this->loadModule($func, $args[0]);
     }
     return \Yaf_Registry::get($func);
 }
Beispiel #5
0
 public function __construct()
 {
     $this->table = new swoole_table(1024);
     $this->table->column('serverfd', swoole_table::TYPE_INT, 8);
     $this->table->create();
     define('APPLICATION_PATH', dirname(dirname(__DIR__)) . "/application");
     define('MYPATH', dirname(APPLICATION_PATH));
     $this->application = new Yaf_Application(dirname(APPLICATION_PATH) . "/conf/application.ini");
     $this->application->bootstrap();
     $config_obj = Yaf_Registry::get("config");
     $distributed_config = $config_obj->distributed->toArray();
     $server = new swoole_server($distributed_config['ServerIp'], $distributed_config['port'], SWOOLE_PROCESS, SWOOLE_SOCK_TCP);
     if (isset($distributed_config['logfile'])) {
         $server->set(array('worker_num' => 4, 'task_worker_num' => 4, 'dispatch_mode' => 4, 'daemonize' => true, 'log_file' => $distributed_config['logfile']));
     } else {
         $server->set(array('worker_num' => 4, 'task_worker_num' => 4, 'dispatch_mode' => 4, 'daemonize' => true));
     }
     require_once __DIR__ . "/DistributedClient.php";
     $server->on('Start', array(&$this, 'onStart'));
     $server->on('WorkerStart', array(&$this, 'onWorkerStart'));
     $server->on('Connect', array(&$this, 'onConnect'));
     $server->on('Receive', array(&$this, 'onReceive'));
     $server->on('Task', array(&$this, 'onTask'));
     $server->on('Finish', array(&$this, 'onFinish'));
     $server->on('Close', array(&$this, 'onClose'));
     $server->on('ManagerStop', array(&$this, 'onManagerStop'));
     $server->on('WorkerError', array(&$this, 'onWorkerError'));
     $server->start();
 }
Beispiel #6
0
 public function __construct()
 {
     $this->_config = Yaf_Registry::get("config");
     $this->_db = new Db_Mysql($this->_config->database->config->toArray());
     //$this->_redis = new Redis();
     //$this->_redis->connect($this->_config->redis->host);
 }
Beispiel #7
0
 private static function getTransport()
 {
     $_config = Yaf_Registry::get("config");
     self::$_cfg = $_config->mail->smtp->toArray();
     self::$_transport = Swift_SmtpTransport::newInstance(self::$_cfg['service'], 25)->setUsername(self::$_cfg['username'])->setPassword(self::$_cfg['password']);
     self::$_mailer = Swift_Mailer::newInstance(self::$_transport);
 }
Beispiel #8
0
 protected function loadDatabase($name)
 {
     $database = Yaf_Registry::get('_database');
     if (isset($database[$name])) {
         return $database[$name];
     }
     $config = Yaf_Registry::get('_config');
     if (isset($config->database->{$name})) {
         if (is_null($database)) {
             $database = array();
         }
         $dbConfig = $config->database->{$name};
         $pdoParams = array();
         if ($dbConfig->pconnect) {
             $pdoParams[Db::ATTR_PERSISTENT] = TRUE;
         }
         try {
             $conn = new Db($dbConfig->type . ':host=' . $dbConfig->host . '; dbname=' . $dbConfig->database, $dbConfig->username, $dbConfig->password, $pdoParams);
         } catch (PDOException $error) {
             throw new Exception($error->getMessage(), 500);
         }
         $database[$name] = $conn;
         Yaf_Registry::set('_database', $database);
         return $conn;
     } else {
         throw new Exception('Undefined database', 500);
     }
 }
Beispiel #9
0
 /**
  * (non-PHPdoc)
  * @see Yaf_Controller_Abstract::init()
  */
 public function init()
 {
     //判断用户是否登录
     if ($this->_need_login && !Yaf_Registry::get('current_uid')) {
         throw new \Exception\Nologin('no login');
     }
 }
Beispiel #10
0
 public function init()
 {
     parent::init();
     $this->_layout = new LayoutPlugin('layout.html');
     $this->dispatcher = Yaf_Registry::get("dispatcher");
     $this->dispatcher->registerPlugin($this->_layout);
 }
Beispiel #11
0
 public function __construct()
 {
     $tWeixinarr = Yaf_Registry::get("config")->weixin->default->toArray();
     $this->appId = $tWeixinarr['appID'];
     $this->appSecret = $tWeixinarr['appsecret'];
     $this->token = $tWeixinarr['token'];
 }
Beispiel #12
0
 public function startAction()
 {
     $config = Yaf_Registry::get('monitor_config');
     $dataName = $config['loghandle'][$this->logType]['data'];
     $stepTime = intval($config['loghandle'][$this->logType]['step']);
     $modes = explode(',', $config['loghandle'][$this->logType]['mode']);
     $tables = explode(",", trim($config['mongo'][$this->logType]['tables']));
     $logDataService = new Service_Log_Data($this->logType, $dataName);
     $dataResult = $logDataService->getAccessLog($tables, $stepTime);
     if (!$dataResult) {
         return false;
     }
     $firstData = current($dataResult);
     $time = $firstData['time']->sec;
     $modeNum = count($modes);
     $loghandleEtlParserModel = new Model_Loghandle_Etl_Parser();
     $extractData = $loghandleEtlParserModel->extract($dataResult);
     for ($i = 0; $i < $modeNum; $i++) {
         $pid = pcntl_fork();
         $mode = $modes[$i];
         if (!$pid) {
             $etlModel = Model_Loghandle_Etl_Factory::create($this->logType, $mode);
             $transData = $etlModel->transform($extractData);
             $etlModel->load($transData, $time);
             exit;
         }
     }
     return false;
 }
Beispiel #13
0
 public static function loadConfig()
 {
     if (self::$isLoaded) {
         return;
     }
     $globalConfig = Yaf_Registry::get('config');
     if (!isset($globalConfig->log)) {
         self::$enableLog = false;
         return;
     }
     $globalLogConfig = $globalConfig->log;
     if (isset($globalLogConfig->enable)) {
         self::$enableLog = $globalLogConfig->enable;
     }
     if (isset($globalLogConfig->log_level)) {
         self::$logLevel = self::$LOG_LEVELS[$globalLogConfig->log_level];
     }
     if (!is_string($globalLogConfig->target)) {
         $tmpTarget = [];
         foreach ($globalLogConfig->target as $k => $v) {
             $k = strtoupper($k);
             $tmpTarget[$k] = $v;
         }
         self::$target = $tmpTarget;
     } else {
         self::$target = ['DEFAULT' => $globalLogConfig->target];
     }
     self::$isLoaded = true;
 }
 public function indexAction()
 {
     //默认Action
     //test db library
     $dbObj = new Db_Table(SAE_MYSQL_DB, 'user');
     $res = $dbObj->getCount('id=3');
     var_dump($res);
     $field = array();
     $whereArr = array('order' => 'id', 'limit' => '3');
     $res = $dbObj->getAll($field, $whereArr);
     var_dump($res);
     //test smarty library
     $this->getView()->assign("contentaa", "Hello Worldssss");
     //test zendDb library
     $db = Yaf_Registry::get('db');
     $sql = $db->quoteInto('select * from usertest where user_id <?', '3');
     $result = $db->query($sql);
     $res = $result->fetchAll();
     var_dump($res);
     /*
             $adapter = new Zend_Db_Table();
             $adapter->setDefaultAdapter($db);
             $obj = new UserTableModel();
             $data = array(
                 'id' => '1',
                 'name' => 'King',
                 'author' => 'Arthur',
                 'color' => 'blue'
             );
             $obj->insert($data);*/
 }
Beispiel #15
0
 public function startAction()
 {
     $config = Yaf_Registry::get('monitor_config');
     $dataName = $config['loghandle'][$this->logType]['data'];
     $stepTime = intval($config['loghandle'][$this->logType]['step']);
     $logPersistentService = new Service_Log_Persistent();
     $logApp = $logPersistentService->getAppId();
     foreach ($logApp as $table => $appId) {
         $pid = pcntl_fork();
         if (!$pid) {
             $logDataService = new Service_Log_Data($this->logType, $dataName);
             $dataResult = $logDataService->getWeblog($table, $stepTime);
             if (!$dataResult) {
                 return false;
             }
             $etlModel = Model_Loghandle_Etl_Factory::create($this->logType, 'key');
             $extraData = array('logapp' => $logApp, 'data' => $dataResult, 'table' => $table);
             $transData = $etlModel->transform($extraData);
             $firstData = current($dataResult);
             $time = $firstData['time']->sec;
             $etlModel->load($transData, $time);
             exit;
         }
     }
     return false;
 }
Beispiel #16
0
function rpcserver_call(swoole_process $worker)
{
    define('APPLICATION_PATH', dirname(dirname(__DIR__)) . "/application");
    define('THRIFT_DIR_PATH', dirname(APPLICATION_PATH) . "/thrift");
    require_once THRIFT_DIR_PATH . "/Thrift/ClassLoader/ThriftClassLoader.php";
    $loader = new Thrift\ClassLoader\ThriftClassLoader();
    $loader->registerNamespace('Thrift', THRIFT_DIR_PATH);
    $loader->registerNamespace('swoole', THRIFT_DIR_PATH);
    $loader->registerNamespace('Bin', THRIFT_DIR_PATH);
    $loader->registerDefinition('Bin', THRIFT_DIR_PATH);
    $loader->register();
    define('MYPATH', dirname(APPLICATION_PATH));
    $application = new Yaf_Application(dirname(APPLICATION_PATH) . "/conf/application.ini");
    $application->bootstrap();
    $config_obj = Yaf_Registry::get("config");
    $rpc_config = $config_obj->rpc->toArray();
    define('SERVERIP', $rpc_config['ServerIp']);
    define('SERVERPORT', $rpc_config['port']);
    define('SERVERHOST', $rpc_config['host']);
    $service = new Bin\rpc\Handler();
    $processor = new Bin\rpc\rpcProcessor($service);
    $socket_tranport = new Thrift\Server\TServerSocket(SERVERIP, SERVERPORT);
    $out_factory = $in_factory = new Thrift\Factory\TFramedTransportFactory();
    $out_protocol = $in_protocol = new Thrift\Factory\TBinaryProtocolFactory();
    $server = new swoole\RpcServer($processor, $socket_tranport, $in_factory, $out_factory, $in_protocol, $out_protocol);
    $server->serve();
}
 protected function init()
 {
     $this->_config = Yaf_Registry::get('_config')->toArray();
     $this->_request = $this->getRequest();
     $this->getView()->assign(array('_site' => $this->_config['site']));
     // 开始把框架改造成RESTful,并自动加上OPTIONS的返回
     $method = $this->_request->getMethod();
     $action = $this->_request->getActionName();
     if (method_exists($this, $action . 'Action')) {
         // 兼容原方法,如果已经存在xxxAction的时候直接调用,不再进行RESTful,否则ErrorController与forward的时候会出错
         return;
     }
     $allow = array();
     foreach (array('Get', 'Post', 'Put', 'Delete', 'Head', 'Patch') as $v) {
         if (method_exists($this, $action . $v . 'Action')) {
             $allow[] = $v;
         }
     }
     if (empty($allow)) {
         throw new Exception('', 404);
     }
     if ($method == 'OPTIONS') {
         header('allow: ' . strtoupper(implode(' ', $allow)));
         header('content-length: 0');
         exit;
     } else {
         $camelMethod = substr($method, 0, 1) . strtolower(substr($method, 1));
         if (!in_array($camelMethod, $allow)) {
             throw new Exception('', 405);
         }
         // 重新定位到RESTful对应的action上,比如POST方式请求index,则从indexAction变成indexPostAction
         $this->_request->setActionName($action . $camelMethod);
     }
 }
Beispiel #18
0
 public function init()
 {
     $this->_config = Yaf_Registry::get('config');
     $this->_req = $this->getRequest();
     $this->_session = Yaf_Session::getInstance();
     $this->_session->start();
 }
Beispiel #19
0
 public function indexAction()
 {
     $sNewCardID = Yaf_Registry::get('config')->newcardid;
     $sOldCardID = Yaf_Registry::get('config')->oldcardid;
     if (!empty($_GET['ccid'])) {
         $ccid = $_GET['ccid'];
     }
     if (strlen($ccid) == 20) {
         $ccid = substr($ccid, 0, 19);
     } else {
         if (strlen($ccid) != 19) {
             throw new Exception("请检查您的ICCID!");
         }
     }
     $cfArr = TZ_Loader::service('UserFlow', 'Flow')->getFlowProductId($ccid);
     if (empty($cfArr)) {
         $this->_view->display("no_info.html");
         die;
         //throw new Exception("该卡不属于747卡!");
     } else {
         $pid = $cfArr['cpid'];
     }
     if (intval($sNewCardID) != $pid && $pid != $sOldCardID) {
         $this->_view->display("no_info.html");
     } else {
         if ($pid == $sOldCardID) {
             header("location:http://app.747.cn");
         } else {
             $this->_view->display('pay.html');
         }
     }
 }
Beispiel #20
0
 /**
  * @param  string mysql database name
  * @return [type]
  */
 public static function linkDb($dbname = "_default")
 {
     if (isset(self::$link[$dbname])) {
         return self::$link[$dbname];
     }
     $config = Yaf_Registry::get('config');
     if (!$config->database->get($dbname)) {
         return false;
     }
     $host = $config->database->get($dbname)->host;
     $port = $config->database->get($dbname)->port;
     $user = $config->database->get($dbname)->username;
     $password = $config->database->get($dbname)->password;
     $name = $config->database->get($dbname)->dbname;
     $charset = isset($config->database->get($dbname)->charset) ? $config->database->get($dbname)->charset : "UTF8";
     try {
         $link_temp = new PDO('mysql:host=' . $host . ';port=' . $port . ';dbname=' . $name . ';charset=' . $charset, $user, $password, $arrayName = array(PDO::ATTR_PERSISTENT => false));
         $link_temp->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
         //PHP5.3.6以下,需禁用仿真预处理,防止注入
         $link_temp->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         self::$link[$dbname] = new FluentPDO($link_temp);
     } catch (Exception $e) {
         self::$link[$dbname] = null;
     }
     if (!self::$link[$dbname]) {
         return false;
     }
     return self::$link[$dbname];
 }
Beispiel #21
0
 /**
  * 获取一条数据
  * 
  * @param int   $uid  用户UID,默认为当前登录用户UID
  * 
  * @return array
  */
 public static function show($uid = false)
 {
     !$uid && ($uid = \Yaf_Registry::get('current_uid'));
     $result = parent::show($uid);
     isset($result['data']) && ($result['data'] = self::decodeData($result['data']));
     return $result;
 }
Beispiel #22
0
 public function aboutAction()
 {
     $this->getView()->assign('content', 'hello yaf');
     $smarty = Yaf_Registry::get('config')->get('smarty');
     // var_dump($smarty);
     // echo APP_PATH;
 }
Beispiel #23
0
 public function __construct($logType)
 {
     parent::__construct($logType);
     $this->logType = $logType;
     $config = Yaf_Registry::get('monitor_config');
     $cacheName = $config['loghandle'][$this->logType]['cache'];
     $this->cacheModel = Model_Loghandle_Cache_Factory::create($this->logType, $cacheName);
 }
Beispiel #24
0
 /**
  * @param string $which
  *
  * @return DB_Mysql
  */
 public static function db($which = 'master')
 {
     $DB_config = Yaf_Registry::get('config')->get('yaf')->get('db')->{$which};
     $cache_config = Yaf_Registry::get('config')->get('yaf')->get('cache');
     $db = DB_Mysql::getInstance($DB_config, $cache_config);
     return $db;
     //		return ($db instanceof DB_DbInterface) ? $db : false;
 }
Beispiel #25
0
 public function getCache()
 {
     if (self::$__cache === null) {
         self::$__cache = Yaf_Registry::get('cache');
         $this->cache = self::$__cache;
     }
     return self::$__cache;
 }
Beispiel #26
0
 public function getQueue()
 {
     if (self::$__queue === null) {
         self::$__queue = Yaf_Registry::get('queue');
         $this->queue = self::$__queue;
     }
     return self::$__queue;
 }
Beispiel #27
0
 /**
  * 判断用户是否登录
  * @throws \Exception\Nologin
  * 
  * @return \int
  */
 public static function validateLogin()
 {
     $uid = \Yaf_Registry::get('current_uid');
     if (!$uid) {
         throw new \Exception\Nologin();
     }
     return $uid;
 }
Beispiel #28
0
 /**
  *初始化路由
  */
 public function _initRoute(Yaf_Dispatcher $dispatcher)
 {
     $router = Yaf_Dispatcher::getInstance()->getRouter();
     /**
      * 添加配置中的路由
      */
     $router->addConfig(Yaf_Registry::get("config")->routes);
 }
Beispiel #29
0
 public function __construct()
 {
     try {
         self::$dbConfig = Yaf_Registry::get('config')->get('database')->toArray();
         self::$db = new MongoDB\Client(self::$dbConfig['url']);
     } catch (Exception $e) {
         Log::error('数据库连接失败');
     }
 }
 public function _initXhprof(Yaf_Dispatcher $dispatcher)
 {
     $if_xhprof = Yaf_Registry::get("config")->get('xhprof')->get('open');
     $if_xhprof = isset($if_xhprof) && (int) $if_xhprof > 0 ? 'open' : 'close';
     if ($if_xhprof == 'open') {
         $xhprof = new xhprofPlugin();
         $dispatcher->registerPlugin($xhprof);
     }
 }