/** * @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 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; } } }
/** * 执行提交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; }
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; } }
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'); }
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'; }
/** * @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); } }
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))); } } }
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); } }
function get_config($_scope = NULL) { $_result = Yaf\Registry::get('config'); if ($_scope != NULL) { foreach (explode('.', $_scope) as $scope) { $_result = $_result->get($scope); } } return $_result; }
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()); }
/** * @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!'); } }
/** * 初始化 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 _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; } }
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'); }
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'); }
/** * 获取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; }
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 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); }
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))); } } } }
/** * 账号设置 * */ public function accountAction() { $title = Yaf\Registry::get('lang')->translate('Account'); $this->getView()->assign('title', $title); }
/** * 新用户注册 * */ public function indexAction() { $title = Yaf\Registry::get('lang')->translate('New user register'); $this->getView()->assign('title', $title); }
/** * 分类首页 * * @param integer $id * */ public function indexAction($id = 0) { $id = (int) $id; $title = Yaf\Registry::get('lang')->translate('Category'); $this->getView()->assign('title', $title); }
/** * 从缓存中获取价格 * array( * 'time' => 123123123, * 'buy' => array( * array(2323, 232), 买1 * array(2323, 232), * array(2323, 232), * array(2323, 232), * array(2323, 232), * ), * 'sell' => array( * array(2323, 232), 卖1 * array(2323, 232), * array(2323, 232), * array(2323, 232), * array(2323, 232), * ), * ); * @return array */ public function getCachePrice() { return json_decode(Yaf\Registry::get('redis')->get(get_class($this) . "Price"), true); }
public function getCacheInfo() { // 此方法可能会无限循环占用 CPU,睡半秒 usleep(500000); $cache_info = json_decode(Yaf\Registry::get('redis')->get("AccountInfo_{$this->account_id}"), true); // 1分钟以内的 info if ($cache_info['time'] > 0 && time() - $cache_info['time'] < 60) { $this->info = $cache_info; return $cache_info; } return $this->getInfo(); }
public function __construct() { $this->db = Yaf\Registry::get('db'); }
/** * @param string $group */ public function setGroup($group) { if ($group instanceof GroupsModel) { $this->group = $group; } elseif (is_numeric($group)) { $em = Yaf\Registry::get('entityManager'); $this->setGroup($em->find('GroupsModel', $group)); } else { throw new InvalidArgumentException('$group must be instance of GroupsModel or null!'); } }
<?php define("BASE_PATH", realpath(dirname(__FILE__) . "/../../")); define("APPLICATION_PATH", realpath(dirname(__FILE__) . "/../../application/")); define("LIBRARY_PATH", realpath(dirname(__FILE__) . "/../../library/")); define("PUBLIC_PATH", dirname(__FILE__) . "/../../public/"); define("DS", '/'); require_once LIBRARY_PATH . DS . 'RDS' . DS . 'RDS_Network.php'; $rds_config = new Yaf\Config\Ini(APPLICATION_PATH . DS . 'configs' . DS . 'debug.ini'); $_DEBUGGER = new RDS_Network('doctrine-cli.php', $rds_config->rds->host, $rds_config->rds->port, true, false); $_PROFILER = $_DEBUGGER->newProfiler('GLOBAL_PROFILER'); $app = new \Yaf\Application(APPLICATION_PATH . "/configs/application.ini"); $app->bootstrap(); use Symfony\Component\Console\Helper\HelperSet, Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper, Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper, Doctrine\ORM\Tools\Console\ConsoleRunner; $em = Yaf\Registry::get('entityManager'); $helperSet = new HelperSet(array('em' => new EntityManagerHelper($em), 'conn' => new ConnectionHelper($em->getConnection()))); ConsoleRunner::run($helperSet); $app->run(); $_PROFILER->end();