Beispiel #1
0
 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 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();
 }
Beispiel #3
0
 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();
 }
Beispiel #4
0
 /**
  * 处理已读消息
  */
 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;
 }
Beispiel #5
0
 /**
  * 加载插件
  * @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());
     }
 }
Beispiel #6
0
 public function _initConfig()
 {
     $this->__config = Yaf\Application::app()->getConfig();
     //注册本地类前缀
     $namespace = $this->__config['application']['library']['localnamespace'];
     Yaf\Loader::getInstance()->registerLocalNamespace(explode(',', $namespace));
 }
Beispiel #7
0
 /**
  * @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();
     }
 }
Beispiel #8
0
 /**
  * 单进程运行检查
  * @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");
     }
 }
Beispiel #9
0
 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();
 }
Beispiel #10
0
 /**
  * 初始化配置文件
  **/
 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 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;
 }
Beispiel #12
0
 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}");
         }
     }
 }
Beispiel #13
0
 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!');
         }
     }
 }
Beispiel #14
0
 public function onWorkerStart($serv, $worker_id)
 {
     $this->application = new Yaf\Application(CONF_PATH . 'app.ini', 'product');
     $this->application->bootstrap();
     if ($worker_id >= $serv->setting['worker_num']) {
         cli_set_process_title("swoolehttp:task_worker");
     } else {
         cli_set_process_title("swoolehttp:worker");
     }
     //$serv->addtimer(300000);
 }
Beispiel #15
0
 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");
 }
Beispiel #16
0
 /**
  * 初始化 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);
 }
Beispiel #17
0
 /**
  * 存储一条消息
  * @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;
 }
Beispiel #18
0
 /**
  * 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;
 }
Beispiel #19
0
 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);
 }
Beispiel #20
0
 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');
 }
Beispiel #21
0
 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);
     }
 }
Beispiel #22
0
<?php

/*
  +----------------------------------------------------------------------+
  | Boom                                                                  |
  +----------------------------------------------------------------------+
  | This source file is subject to version 2.0 of the Apache license,    |
  | that is bundled with this package in the file LICENSE, and is        |
  | available through the world-wide-web at the following url:           |
  | http://www.apache.org/licenses/LICENSE-2.0.html                      |
  | If you did not receive a copy of the Apache2.0 license and are unable|
  | to obtain it through the world-wide-web, please send a note to       |
  | yiming_6weijun@163.com so we can mail you a copy immediately.        |
  +----------------------------------------------------------------------+
  | Author: Weijun Lu  <*****@*****.**>                          |
  +----------------------------------------------------------------------+
*/
define('DS', DIRECTORY_SEPARATOR);
define('APPLICATION_PATH', dirname(__DIR__) . DS . 'application');
$application = new \Yaf\Application(APPLICATION_PATH . '/conf/application.ini');
$application->bootstrap()->run();
Beispiel #23
0
 public function _initConfig($dispatcher)
 {
     $config = Yaf\Application::app()->getConfig();
     Yaf\Registry::set('config', $config);
 }
Beispiel #24
0
<?php

define("APP_PATH", realpath(dirname(__FILE__) . "/../"));
define("PUBLIC_PATH", dirname(__FILE__));
$app = new \Yaf\Application(APP_PATH . "/config/application.ini");
$app->bootstrap()->run();
Beispiel #25
0
 public function __construct()
 {
     $this->_config = Yaf\Application::app()->getConfig();
 }
Beispiel #26
0
<?php

defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
// Define application environment
defined('APPLICATION_ENV') || define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production');
use Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper, Symfony\Component\Console\Helper\HelperSet, Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
// Starting application
$app = new \Yaf\Application(APPLICATION_PATH . "/configs/application.ini");
$app->bootstrap();
// obtaining the entity manager
$entityManager = \Yaf\Registry::get('EntityManager');
$helperSet = new HelperSet(array('db' => new ConnectionHelper($entityManager->getConnection()), 'em' => new EntityManagerHelper($entityManager)));
Beispiel #27
0
 /**
  * 设置application
  */
 public function setApplication()
 {
     $application = new \Yaf\Application(APPLICATION_PATH . "/conf/application.ini");
     $application->bootstrap();
     \Yaf\Registry::set('application', $application);
 }
 public function _initConfig(Yaf\Dispatcher $dispatcher)
 {
     $this->config = Yaf\Application::app()->getConfig();
 }
Beispiel #29
0
<?php

/*
 * 命令行工具入口  用法:
 * php /path/to/root/bus.php require_uri=/job/index
 * 
 */
// 设置对路径
define('ROOT_PATH', __DIR__);
define('APPLICATION_PATH', ROOT_PATH . '/application');
// 跳过SESSION
define("RUN_IN_CLI", true);
// 设置请求
// 1 运行模式    2 模块(非多模块请指定Index)  3 控制器名称   4 控制器方法  5 参数(数组)
// $request = new Yaf\Request\Simple("CLI", "Index", "Job", "Index", array());
$request = new Yaf\Request\Simple();
// 应用配置
$application = new Yaf\Application(require ROOT_PATH . "/conf/global.php");
// 启动资源
$application->bootstrap();
// 分发请求
$application->getDispatcher()->dispatch($request);
Beispiel #30
0
<?php

/* example: php cli.php "request_uri=/command/account/index" */
define("APPLICATION_PATH", realpath(dirname(__FILE__) . '/../'));
$app = new Yaf\Application(APPLICATION_PATH . '/conf/application.ini');
$app->bootstrap()->getDispatcher()->dispatch(new Yaf\Request\Simple());