/** * @desc 获取价格Action * @param string market */ public function getPriceAction() { Yaf\Registry::get('redis')->lPush('get_price_pids', getmypid()); $market_name = $this->getRequest()->getParam('market'); $market_name = "Market\\{$market_name}"; $market = new $market_name(); while (true) { if ($market_name == 'Market\\Btce') { $account_config = array(); $account_config_model = new AccountConfigDao(); foreach ($account_config_model->getConfigListByAccountId(9) as $config) { $account_config[$config['name']] = format_val($config['value']); } $market = new $market_name($account_config); } if ($market_name == 'Market\\Bitfinex') { $account_config = array(); $account_config_model = new AccountConfigDao(); foreach ($account_config_model->getConfigListByAccountId(10) as $config) { $account_config[$config['name']] = format_val($config['value']); } $market = new $market_name($account_config); } usleep(Yaf\Application::app()->getConfig()->console->price_sleep_delay); $market->getPrice(); } }
public function _initConfig() { $this->__config = Yaf\Application::app()->getConfig(); //注册本地类前缀 $namespace = $this->__config['application']['library']['localnamespace']; Yaf\Loader::getInstance()->registerLocalNamespace(explode(',', $namespace)); }
public function errorAction($exception) { $this->getView()->setLayout(null); // 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()); eYaf\Logger::getLogger()->logException($exception); 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"); break; } eYaf\Logger::stopLogging(); }
/** * 加载插件 * @param \Yaf\Dispatcher $dispatcher */ public function _initPlugins(Yaf\Dispatcher $dispatcher) { $config = Yaf\Application::app()->getConfig(); if ($config->get('application.log.status')) { $dispatcher->registerPlugin(new LogPlugin()); } }
public function _initConfig(Yaf\Dispatcher $dispatcher) { //把配置保存起来 $this->config = Yaf\Application::app()->getConfig(); Yaf\Registry::set('config', $this->config); define('REQUEST_METHOD', strtoupper($dispatcher->getRequest()->getMethod())); }
/** * 处理已读消息 */ public function setReadAction() { echo date('Y-m-d H:i:s') . ' setRead is started!' . PHP_EOL; $queueKey = Yaf\Application::app()->getConfig()->redisKeys->setReadQueue; $readKeyPrefix = Yaf\Application::app()->getConfig()->redisKeys->readKeyPrefix; $redis = RedisFactory::instance('ims', true); while (true) { while ($userId = $redis->lPop($queueKey)) { $key = $readKeyPrefix . '_' . $userId; while ($messageId = $redis->lpop($key)) { $messageModel = new MessageModel($userId); $messageModel->setIsRead($messageId); } //推送未读消息变动通知 $userModel = new UserModel(); pushModel::unreadMessageNotice($userModel->getUnreadMessageList(true)); } try { // 闲置时检查Redis连接 $redis->ping(); } catch (\Exception $e) { $redis = RedisFactory::instance('ims', true, true); //重连 } sleep(1); } exit; }
protected function getResponseBody($controller, $action, array $params = []) { $request = new Yaf\Request\Simple('CLI', 'Index', $controller, $action, $params); $dispatcher = Yaf\Application::app()->getDispatcher(); $response = $dispatcher->returnResponse(true)->dispatch($request); return $response->getBody(); }
/** * 初始化配置文件 **/ public function _initConfig() { $this->_config = Yaf\Application::app()->getConfig(); //把配置保存起来 Yaf\Registry::set('config', $this->_config); $charset = $this->_config->application->common->charset; header("Content-Type: text/html; charset={$charset}"); }
/** * 单进程运行检查 * @param $action */ protected function oneProcessCheck() { $requestUri = Yaf\Application::app()->getDispatcher()->getRequest()->getRequestUri(); $processCount = `ps -ef | grep '{$requestUri}' | grep -v grep | grep -v '/bin/sh' |wc -l `; if ($processCount > 1) { die("已经有正在运行的程序:{$requestUri}\n"); } }
public function init() { $config = Yaf\Application::app()->getConfig(); $this->mailApi = $config->api['mail']; $this->curPage = $this->getParam('page', 1); $this->pagesize = 20; $this->httpRequest = new \GuzzleHttp\Client(); }
/** * @param array $definedConnections * @return DatabaseManager */ public static function getInstance() { if (!isset(self::$instance)) { $definedConnections = Yaf\Application::app()->getConfig()->get('db.connections')->toArray(); self::$instance = new self($definedConnections); register_shutdown_function(array(self::$instance, 'resetInstance')); } return self::$instance; }
public function _initDto() { $file_path = Yaf\Application::app()->getConfig()->application->path->dao; $file_list = scandir($file_path); foreach ($file_list as $file_name) { if (strpos($file_name, '.php') !== false) { Yaf\Loader::import("{$file_path}/{$file_name}"); } } }
protected function verify_auth_token($request) { $config = Yaf\Application::app()->getConfig(); if ($config['application']['protect_from_csrf'] && $request->isPost()) { $post = $request->getPost(); if (!isset($post['auth_token']) || $post['auth_token'] !== $this->auth_token()) { throw new \Exception('Invalid authenticity token!'); } } }
/** * 初始化 yaf config * @param \Yaf\Dispatcher $dispatcher */ public function _initConfig(Yaf\Dispatcher $dispatcher) { $app = (array) \TheFairLib\Config\Config::load("App"); $config = Yaf\Application::app()->getConfig(); $config = new Yaf\Config\Simple($config->toArray(), false); foreach ($app as $key => $val) { $config->set($key, $val); } Yaf\Registry::set("config", $config); $router = $dispatcher::getInstance()->getRouter(); $router->addConfig(Yaf\Registry::get("config")->routes); }
public function _initConfig(Yaf\Dispatcher $dispatcher) { //把配置保存起来 $this->config = Yaf\Application::app()->getConfig(); Yaf\Registry::set('config', $this->config); define('REQUEST_METHOD', strtoupper($dispatcher->getRequest()->getMethod())); $this->lib = ini_get("yaf.library"); Yaf\Registry::set('yafpath', $this->lib); Yaf\Registry::set('localLibrary', $this->config->application->library); Yaf\Loader::import($this->lib . "/SlatePF/Function.php"); L("vendor/autoload.php"); }
/** * 存储一条消息 * @param Array $message */ public function save($data) { $message = $this->filter($data); if (!$this->check($message)) { $this->setErrCode(Error::PARAMS_ERROR); return false; } $messageId = Dao\MessageIdModel::getId(); $message['messageId'] = $messageId; $message['sendTime'] = date('Y-m-d H:i:s'); $message['isRead'] = 0; if ($this->userModel->getTalkId($message['sender']) == $message['receiver']) { $message['isRead'] = 1; } //消息关系数据 $relationData = array('catId' => $message['catId'], 'sender' => $message['sender'], 'receiver' => $message['receiver'], 'messageId' => $message['messageId'], 'sendTime' => $message['sendTime']); //Cli模式下开启长连接 if (Yaf\Application::app()->getDispatcher()->getRequest()->isCli()) { $pdo = PdoFactory::instance('messageMaster', true); } else { $pdo = PdoFactory::instance('messageMaster'); } try { $pdo->beginTransaction(); $messageDao = new Dao\MessageModel($pdo, Table::message($messageId)); $relationSenderDao = new Dao\RelationModel($pdo, Table::relation(intval($message['sender']))); $relationReceiverDao = new Dao\RelationModel($pdo, Table::relation(intval($message['receiver']))); $messageDao->save($message); if (!$relationSenderDao->has($message['messageId'])) { $relationSenderDao->save($relationData); } if (!$relationReceiverDao->has($message['messageId'])) { $relationReceiverDao->save($relationData); } $pdo->commit(); } catch (\PDOException $e) { if ($pdo->errorCode() === 2006) { $this->setErrCode(Error::MYSQL_GONE_AWAY); } else { $this->setErrCode(Error::SAVE_MESSAGE_ERROR); } Log::fatal(self::LOG_DIR . '/save', $e->getMessage()); $pdo->rollBack(); return false; } $this->contactModel->addContact($message); $this->cacheModel->cache($message); if ($message['isRead'] == 0) { $this->userModel->appendUnreadMessage($message); } return $message; }
public function _initConfig(Yaf\Dispatcher $dispatcher) { //把配置保存起来 $this->config = Yaf\Application::app()->getConfig(); Yaf\Registry::set('config', $this->config); session_start(); define('REQUEST_METHOD', strtoupper($dispatcher->getRequest()->getMethod())); define('IS_GET', REQUEST_METHOD == 'GET' ? true : false); define('IS_POST', REQUEST_METHOD == 'POST' ? true : false); define('IS_PUT', REQUEST_METHOD == 'PUT' ? true : false); define('IS_DELETE', REQUEST_METHOD == 'DELETE' ? true : false); define('IS_AJAX', isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest' ? true : false); }
/** * Initialize layout and session. * * In this method can be initialized anything that could be usefull for * the controller. * * @return void */ public function init() { // Set the layout. $this->getView()->setLayout($this->layout); //Set session. $this->session = Yaf\Session::getInstance(); // Assign session to views too. $this->getView()->session = $this->session; // Assign application config file to this controller $this->config = Yaf\Application::app()->getConfig(); // Assign config file to views $this->getView()->config = $this->config; }
public function init() { // Set the layout. $this->getView()->setLayout($this->layout); //Set session. $this->session = Yaf\Session::getInstance(); // Assign session to views too. $this->getView()->session = $this->session; // Assign application config file to this controller $this->_config = Yaf\Application::app()->getConfig(); // Assign config file to views $this->getView()->config = $this->_config; $this->getView()->module = $this->getRequest()->getModuleName(); $this->getView()->controller = $this->getRequest()->getControllerName(); $this->getView()->action = $this->getRequest()->getActionName(); $this->_entity = Yaf\Registry::get('entityManager'); }
public function init() { // Set the layout. 判断是否ajax请求 /* * 原生js 发送ajax请求时加上header * var xmlhttp=new XMLHttpRequest(); xmlhttp.open("GET","test.php",true); xmlhttp.setRequestHeader("X-Requested-With","XMLHttpRequest"); xmlhttp.send(); */ if (isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"]) == "xmlhttprequest") { // ajax 请求的处理方式 } else { // 正常请求的处理方式 $this->getView()->setLayout($this->layout); } //Set session. $this->session = Yaf\Session::getInstance(); // Assign session to views too. $this->getView()->session = $this->session; // Assign application config file to this controller $this->_config = Yaf\Application::app()->getConfig(); self::$_widget_config = Yaf\Application::app()->getConfig(); // Assign config file to views $this->getView()->config = $this->_config; $this->getView()->module = $this->getRequest()->getModuleName(); $this->getView()->controller = $this->getRequest()->getControllerName(); $this->getView()->action = $this->getRequest()->getActionName(); self::$module = $this->getRequest()->getModuleName(); self::$controller = $this->getRequest()->getControllerName(); self::$action = $this->getRequest()->getActionName(); //title $this->getView()->title = $this->_config['application']['title'] . ' - ' . $this->getRequest()->getControllerName(); //伪静态后缀 $this->getView()->url_suffix = $this->_config['application']['url_suffix']; self::$widgetView = Yaf\Registry::get("widgetView"); // Set the template_url 设置模版 //如果默认的module为nomodule 即无module状态,设置theme url if (strtolower($this->getRequest()->getModuleName()) == $this->_config->application->dispatcher->defaultModule) { $this->getView()->setScriptPath($this->_config->application->view->path); } }
public function __construct() { $this->_config = Yaf\Application::app()->getConfig(); }
public function _initConfig(Yaf\Dispatcher $dispatcher) { $event = $this->profiler->startEvent('Init config'); $this->config = Yaf\Application::app()->getConfig(); $this->profiler->endEvent($event); }
public function _initConfig() { /** @var Yaf\Application::getConfig config */ $this->config = Yaf\Application::app()->getConfig(); }
public function _initConfig(Yaf\Dispatcher $dispatcher) { $this->config = Yaf\Application::app()->getConfig(); }
public function __construct($package = array()) { $this->_config = Yaf\Application::app()->getConfig(); $package = array('common', 'show', 'error'); $this->set_goLang($package); }
protected function _initLogger(Yaf\Dispatcher $dispatcher) { $logConfig = Yaf\Application::app()->getConfig()->logger->toArray(); }
/** * Get full layout path with filename and extension. * * @return string */ public function getLayoutPath() { $config = Yaf\Application::app()->getConfig()->get('application'); return $this->layout_path . "/" . $this->layout . ".{$config->view->ext}"; }
public function init() { $this->session = Session::getInstance(); $this->config = Yaf\Application::app()->getConfig(); $this->input = $this->getRequest()->getPost(); }
public function _initConfig($dispatcher) { $config = Yaf\Application::app()->getConfig(); Yaf\Registry::set('config', $config); }
public function __construct() { $this->_config = Yaf\Application::app()->getConfig(); $this->_db = new Db_Mysql($this->_config->database->toArray()); }