Exemplo n.º 1
0
Arquivo: Index.php Projeto: airzhe/yaf
 public function indexAction()
 {
     /*print_r($config);
     		return;*/
     $medoo = new Db(Yaf\Registry::get('DbConf')['order']);
     #var_dump($medoo->quote("`id`"));
     #return;
     #print_r($medoo->info());return;
     $row = $medoo->debug()->select("post", ["[>]account" => ["author_id" => "user_id"], "[>]album" => "user_id", "[>]photo" => ["user_id", "avatar_id"], "[>]account (replyer)" => ["replyer_id" => "user_id"], "[>]account" => ["author_id" => "user_id"], "[>]album" => ["account.user_id" => "user_id"], "[>]account" => ["author_id" => "user_id", "album.user_id" => "user_id"]], ["post.post_id", "post.title", "account.user_id", "account.city", "replyer.user_id", "replyer.city"], ["post.user_id" => 100, "ORDER" => "post.post_id DESC", "LIMIT" => 50]);
     print_r($row);
     return var_dump($pdoStatement->fetchColumn());
     var_dump($pdoStatement->fetchColumn(1));
     var_dump($pdoStatement->fetchColumn());
     var_dump($pdoStatement->fetchColumn());
     var_dump($pdoStatement->fetchColumn());
     reset($pdoStatement);
     foreach ($pdoStatement as $v) {
         var_dump($v);
     }
     #var_dump($medoo->log());
     #var_dump($row);
     #print_r(get_class_methods($medoo));
     #$adminModel = new AdminModel();
     return;
     echo 'hello yaf';
 }
Exemplo n.º 2
0
 public function routerShutdown(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response)
 {
     /* 验证是否为命令行方式 */
     if ($request->isCli()) {
         $action = $request->getActionName();
         $locate_param = strpos($request->getRequestUri(), '?');
         $locate = strpos($request->getActionName(), '?');
         /* 验证action是否有传参 */
         if ($locate !== false) {
             $query_list = array();
             //重新设置action
             $request->setActionName(substr($action, 0, $locate));
             //截取query_string
             $query_string = substr($request->getRequestUri(), $locate_param + 1);
             //解析query_string
             parse_str($query_string, $query_list);
             //循环set到param
             foreach ($query_list as $key => $value) {
                 $request->setParam($key, $value);
             }
         }
     }
     $request_uri = strtolower($request->getModuleName() . '/' . $request->getControllerName() . '/' . $request->getActionName());
     $request->setRequestUri($request_uri);
     $request->setModuleName(ucfirst($request->getModuleName()));
     $request->setControllerName(underline_to_camel(ucfirst($request->getControllerName())));
     $request->setActionName(underline_to_camel($request->getActionName()));
     /* 保存请求地址 */
     Yaf\Registry::set('request_uri', $request_uri);
 }
Exemplo n.º 3
0
 public function getAction()
 {
     $params = $this->getRequest()->getParams();
     $params = array_flip($params);
     $script_path = \Yaf\Application::app()->getAppDirectory() . "/../scripts/";
     $return = array();
     if (in_array('cacheprice', $params)) {
         exec("/usr/local/bin/php {$script_path}cache_price.php", $return);
     }
     if (in_array('restart', $params)) {
         exec("/usr/local/bin/php {$script_path}/../public/cli.php 'request_uri=/console/Hedge/run' > {$script_path}/../log/hedge.log 2>&1 &", $return);
     }
     if (in_array('killall', $params)) {
         exec("killall php", $return);
     }
     if (in_array('exchange', $params)) {
         $account_group_id = $this->getRequest()->getParam('account_group_id');
         $to_usd_rate = $this->getRequest()->getParam('to_usd_rate');
         $to_cny_rate = $this->getRequest()->getParam('to_cny_rate');
         $log_path = \Yaf\Application::app()->getConfig()->application->path->log . '/' . $account_group_id . '.log';
         $cli = \Yaf\Application::app()->getConfig()->application->directory . '/../public/cli.php';
         $group_id_pid = Yaf\Registry::get('redis')->get('group_id_' . $account_group_id);
         if (!empty($group_id_pid)) {
             $return[] = "group {$group_id_pid} exchange will restart";
         }
         $param = "account_group_id={$account_group_id}&to_usd_rate={$to_usd_rate}&to_cny_rate={$to_cny_rate}";
         exec('php ' . $cli . ' "request_uri=/console/Transport/exchange?' . $param . '" >> ' . $log_path . ' &');
         $return[] = 'exchange start up';
     }
     $this->getView()->assign('return', $return);
     $this->getView()->display('control.phtml');
 }
Exemplo n.º 4
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();
     }
 }
Exemplo n.º 5
0
 /**
  * 执行提交GIT数据
  *
  */
 public function doAction()
 {
     $data['title'] = $this->getRequest()->getPost('title');
     $data['categoryid'] = (int) $this->getRequest()->getPost('categoryid');
     $data['url'] = $this->getRequest()->getPost('url');
     $data['memo'] = $this->getRequest()->getPost('memo');
     $data['userid'] = Yaf\Registry::get('userInfo')['userid'];
     $data['dateline'] = TIMENOW;
     if (empty($data['title'])) {
         Page::displayError('Project name cannot be empty');
     }
     if (empty($data['categoryid'])) {
         Page::displayError('Please select a category');
     }
     if (empty($data['url'])) {
         Page::displayError('Project URL cannot be empty');
     }
     if (empty($data['memo'])) {
         Page::displayError('Project description cannot be empty');
     }
     $this->models['gitModel']->saveData($data);
     unset($data);
     Page::displayMessage('Successful submission Please wait for audit', '/add');
     return FALSE;
 }
Exemplo n.º 6
0
function g($key, $value = null, $nullSet = false)
{
    $sp = explode('/', $key);
    $nullSet = $nullSet || !is_null($value);
    $_g = Yaf\Registry::get($sp[0]);
    $vals =& $_g;
    if (Yaf\Registry::has($sp[0]) || $nullSet) {
        $i = 1;
        while (isset($sp[$i])) {
            $pos = $sp[$i];
            if (!isset($vals[$pos])) {
                if ($nullSet) {
                    $vals[$pos] = [];
                } else {
                    return null;
                }
            } elseif (!is_array($vals[$pos]) && $nullSet) {
                $vals[$pos] = [];
            }
            $vals =& $vals[$pos];
            $i++;
        }
        if ($nullSet) {
            $vals = $value;
            return Yaf\Registry::set($sp[0], $_g);
        } else {
            return $vals;
        }
    } else {
        return null;
    }
}
Exemplo n.º 7
0
 public function _initTwig(Dispatcher $dispatcher)
 {
     $twig = new TwigAdapter(null, \Yaf\Application::app()->getConfig()->twig->toArray());
     $dispatcher->setView($twig);
     Yaf\Registry::set("twig", $twig);
     // $dispatcher->registerPlugin(new SmartyControllerPlugin());
 }
Exemplo n.º 8
0
 public static function send($subject, $content)
 {
     // 十分钟一次
     $redis = Yaf\Registry::get('redis');
     $hash = $subject . '|' . intval(time() / 600);
     if ($redis->get(self::$redis_latest_mail_key) == $hash) {
         return false;
     } else {
         // send mail
         $mail = new PHPMailer();
         $mail->isSMTP();
         $mail->Host = "smtp.163.com";
         $mail->Port = 25;
         $mail->SMTPAuth = true;
         $mail->Username = "******";
         $mail->Password = "******";
         $mail->setFrom('*****@*****.**', 'AutoTrade');
         // TODO
         $mail->addAddress('', '');
         $mail->Subject = $subject;
         $mail->Body = $content;
         if ($mail->send()) {
             $redis->set(self::$redis_latest_mail_key, $hash);
             return true;
         } else {
             Logger::Log('Send mail failed' . $mail->ErrorInfo, Logger::ERROR_LOG);
             return false;
         }
     }
 }
Exemplo n.º 9
0
 /**
  * @name	import
  * 加载自定义包
  * @version	1.0.0
  * @since	2012-03-26
  * @param	unknown_type $type
  */
 private function _import($file_path)
 {
     $file_path = Yaf\Registry::get('config')->get('application')->library . DIRECTORY_SEPARATOR . $file_path;
     $file_list = glob($file_path . DIRECTORY_SEPARATOR . '*.php');
     foreach ($file_list as $v) {
         Yaf\Loader::import($v);
     }
 }
Exemplo n.º 10
0
 public function routerStartup(Yaf\Request_Abstract $request, Yaf\Response_Abstract $response)
 {
     if (Yaf\Registry::get('config')->application->url_suffix) {
         if (strtolower(substr($_SERVER['REQUEST_URI'], -strlen(Yaf\Registry::get('config')->application->url_suffix))) == strtolower(Yaf\Registry::get('config')->application->url_suffix)) {
             $request->setRequestUri(substr($_SERVER['REQUEST_URI'], 0, -strlen(Yaf\Registry::get('config')->application->url_suffix)));
         }
     }
 }
Exemplo n.º 11
0
 /**
  * Initialize illuminate/database
  *
  * @param Yaf\Dispatcher $dispatcher
  */
 protected function _initORM(Yaf\Dispatcher $dispatcher)
 {
     $dbConfig = Yaf\Application::app()->getConfig()->database->toArray();
     $db = new Capsule();
     $db->addConnection($dbConfig);
     $db->bootEloquent();
     Yaf\Registry::set('db', $db->getConnection());
 }
Exemplo n.º 12
0
 public function _initConfig($dispatcher)
 {
     $config = new Yaf\Config\ini('./conf/db.ini', YAF\ENVIRON);
     $config = $config->toArray();
     #print_r($config);return;
     Yaf\Registry::set('DbConf', $config['data']);
     $dispatcher->autoRender(FALSE);
     #Yaf\Loader::getInstance()->registerLocalNamespace("Db");
 }
Exemplo n.º 13
0
 public function _initRoute(Yaf\Dispatcher $dispatcher)
 {
     //注册路由
     $router = Yaf\Dispatcher::getInstance()->getRouter();
     $config_routes = Yaf\Registry::get("config")->routes;
     if (!empty($config_routes)) {
         $router->addConfig(Yaf\Registry::get("config")->routes);
     }
 }
Exemplo n.º 14
0
function get_config($_scope = NULL)
{
    $_result = Yaf\Registry::get('config');
    if ($_scope != NULL) {
        foreach (explode('.', $_scope) as $scope) {
            $_result = $_result->get($scope);
        }
    }
    return $_result;
}
Exemplo n.º 15
0
 public function _initDatabase()
 {
     $db_config['hostname'] = $this->arrConfig->db->hostname;
     $db_config['username'] = $this->arrConfig->db->username;
     $db_config['password'] = $this->arrConfig->db->password;
     $db_config['database'] = $this->arrConfig->db->database;
     $db_config['log'] = $this->arrConfig->db->log;
     $db_config['logfilepath'] = $this->arrConfig->db->logfilepath;
     Yaf\Registry::set('db', new Db($db_config));
 }
Exemplo n.º 16
0
 /**
  * @param string $permission
  */
 public function setPermission($permission)
 {
     if ($permission instanceof PermissionsModel) {
         $this->permission = $permission;
     } elseif (is_numeric($permission)) {
         $em = Yaf\Registry::get('entityManager');
         $this->setGroup($em->find('PermissionsModel', $permission));
     } else {
         throw new InvalidArgumentException('$permission must be instance of PermissionsModel or null!');
     }
 }
Exemplo n.º 17
0
 public function setUp()
 {
     $this->application = Yaf\Registry::get('Application');
     if ($this->application) {
         return;
     }
     $this->application = new Yaf\Application(APPLICATION_PATH . "/config/application.ini", APPLICATION_ENVIRONMENT);
     $this->application->bootstrap();
     Yaf\Registry::set('Application', $this->application);
     Yaf\Dispatcher::getInstance()->setView(PHPUnit_MockYafView::getInstance());
 }
Exemplo n.º 18
0
 public function _initCookie($dispatcher)
 {
     $config = Yaf\Registry::get('config')->cookie;
     if ($config) {
         Cookie::$salt = (string) $config->salt;
         Cookie::$expiration = (int) $config->expire;
         Cookie::$path = (string) $config->path;
         Cookie::$domain = (string) $config->domain;
         Cookie::$secure = (bool) $config->secure;
         Cookie::$httponly = (bool) $config->httponly;
     }
 }
Exemplo n.º 19
0
 /**
  * 用户注销
  *
  */
 public function indexAction()
 {
     // 清除 Cookies
     Local\Header\Cookies::clearCookie('email');
     Local\Header\Cookies::clearCookie('password');
     Local\Header\Cookies::clearCookie('adminemail');
     Local\Header\Cookies::clearCookie('adminpassword');
     // 删除全局数据
     Yaf\Registry::del('userInfo');
     $this->redirect('/index');
     return FALSE;
 }
Exemplo n.º 20
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);
 }
Exemplo n.º 21
0
 public function getAction()
 {
     $account_group_dao = new AccountGroupDao('account_group');
     $params = $this->getRequest()->getParams();
     $handle = array_search('edit', $params);
     if (!empty($handle) && $params[$handle] === 'edit') {
         $account_group = $account_group_dao->get($handle);
         if (empty($account_group)) {
             $this->redirect('/account-group');
             exit;
         }
         $config_dao = new ConfigDao();
         $config_list = $config_dao->getConfigListByAccountGroupId($account_group['id']);
         $this->getView()->assign('config_list', $config_list);
         $this->getView()->assign('account_group', $account_group);
         $this->getView()->display('account-group-edit.phtml');
         exit;
     }
     if (array_key_exists('new', $params)) {
         $config_list = get_config_keys();
         $this->getView()->assign('config_list', $config_list);
         $this->getView()->display('account-group-new.phtml');
         exit;
     }
     $redis = Yaf\Registry::get('redis');
     if (!empty($params) && count($params) === 1) {
         $id = array_keys($params)[0];
         $config_dao = new ConfigDao();
         $config_list = $config_dao->getConfigListByAccountGroupId($id);
         $account_group_config = array();
         foreach ($config_list as $row) {
             $account_group_config[$row['name']] = $row['value'];
         }
         $account_dao = new AccountDao();
         $account_list = $account_dao->getAccountListByAccountGroupId($id);
         $market_dao = new MarketDao();
         $account_info_list = array();
         foreach ($account_list as $account) {
             $key = 'AccountInfo_' . $account['id'];
             $market = $market_dao->get($account['market_id']);
             $account_info_list[] = array_merge(json_decode($redis->get($key), true), array('market_name' => $market['name']));
         }
         $btc_price = json_decode($redis->get('Market\\HuoLPrice'), true)['buy'][0][0];
         $this->getView()->assign('btc_price', $btc_price);
         $this->getView()->assign('account_group_config', $account_group_config);
         $this->getView()->assign('account_info_list', $account_info_list);
         $this->getView()->display('account-group-view.phtml');
         exit;
     }
     $this->getView()->assign('account_group_list', $account_group_dao->getList());
     $this->getView()->display('account-group.phtml');
 }
Exemplo n.º 22
0
 public function _initRegistry()
 {
     $dsn = "mysql:dbname=" . SysConfig::$db_config['default']['dbname'] . ";host=" . SysConfig::$db_config['default']['host'] . ";port=" . SysConfig::$db_config['default']['port'];
     $username = SysConfig::$db_config['default']['username'];
     $password = SysConfig::$db_config['default']['password'];
     $db = new Db_Database($dsn, $username, $password);
     Yaf\Registry::set('db', $db);
     $dsn = "mysql:dbname=" . SysConfig::$db_config['driver_task_pool']['dbname'] . ";host=" . SysConfig::$db_config['driver_task_pool']['host'] . ";port=" . SysConfig::$db_config['driver_task_pool']['port'];
     $username = SysConfig::$db_config['driver_task_pool']['username'];
     $password = SysConfig::$db_config['driver_task_pool']['password'];
     $driver_task_pool = new Db_Database($dsn, $username, $password);
     Yaf\Registry::set('driver_task_pool', $driver_task_pool);
 }
Exemplo n.º 23
0
 public function init()
 {
     //缓存静态资源版本
     $version = Cache\Cache::ins()->fetch('VERSION');
     if ($version === false) {
         $version = time();
         Cache\Cache::ins()->save('VERSION', $version, 604800);
     }
     $this->_view->staticVersion = $version;
     //ace skin
     $this->_view->aceSkin = htmlspecialchars($this->getRequest()->getCookie('ace_skin', 'no-skin'));
     $this->_view->config = Yaf\Registry::get('config');
 }
Exemplo n.º 24
0
 /**
  * 获取ini配置
  * @param $configName 配置文件名称
  * @param $section 节点名称
  * @param $configPath 配置文件路径
  */
 public static function getConfig($configName, $section = null, $configPath = null)
 {
     if (!$configPath) {
         $configPath = APPLICATION_PATH . '/conf';
     }
     if (!$section) {
         $section = YAF\ENVIRON;
     }
     if (Yaf\Registry::has($configName . $section)) {
         return Yaf\Registry::get($configName . $section);
     }
     $config = new Yaf\Config\Ini($configPath . '/' . $configName . '.ini', $section);
     Yaf\Registry::set($configName . $section, $config);
     return $config;
 }
Exemplo n.º 25
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');
 }
Exemplo n.º 26
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);
     }
 }
Exemplo n.º 27
0
 public function exchangeAction()
 {
     $account_group_id = $this->getRequest()->getParam('account_group_id');
     $to_usd_rate = $this->getRequest()->getParam('to_usd_rate');
     $to_cny_rate = $this->getRequest()->getParam('to_cny_rate');
     if (empty($account_group_id) || empty($to_cny_rate) || empty($to_usd_rate)) {
         echo "param is empty \r\n";
         exit;
     }
     if ($to_cny_rate < 6 || $to_usd_rate > 6.3) {
         echo "error rate \r\n";
         exit;
     }
     $group_id_pid = Yaf\Registry::get('redis')->get('group_id_' . $account_group_id);
     if (!empty($group_id_pid)) {
         echo "kill progress {$group_id_pid}";
         system("kill -9 {$group_id_pid} \r\n");
         Yaf\Registry::get('redis')->del('group_id_' . $account_group_id);
     }
     Yaf\Registry::get('redis')->set('group_id_' . $account_group_id, getmypid());
     $this->exchange($account_group_id, $to_usd_rate, $to_cny_rate);
 }
Exemplo n.º 28
0
 private function restart()
 {
     //暂时做个定时重启策略
     $time = time();
     $pid = getmypid();
     $hedge = json_decode(Yaf\Registry::get('redis')->get('hedge'), true);
     if (empty($hedge)) {
         Yaf\Registry::get('redis')->set('hedge', json_encode(array('time' => $time, 'pid' => $pid)));
     } else {
         if ($time - $hedge['time'] > 500) {
             Logger::Log("restart Hedge");
             $path = APPLICATION_PATH . "/scripts/Hedge";
             Yaf\Registry::get('redis')->del('hedge');
             system("{$path}");
             system("kill -9 {$hedge['pid']}");
             system("kill -9 {$pid}");
         } else {
             if ($hedge['pid'] != $pid) {
                 system("kill -9 {$hedge['pid']}");
                 Yaf\Registry::get('redis')->set('hedge', json_encode(array('time' => $time, 'pid' => $pid)));
             }
         }
     }
 }
Exemplo n.º 29
0
 /**
  * 账号设置
  *
  */
 public function accountAction()
 {
     $title = Yaf\Registry::get('lang')->translate('Account');
     $this->getView()->assign('title', $title);
 }
Exemplo n.º 30
0
 /**
  * 新用户注册
  *
  */
 public function indexAction()
 {
     $title = Yaf\Registry::get('lang')->translate('New user register');
     $this->getView()->assign('title', $title);
 }