Exemple #1
0
 /**
  * 
  * @param \Yaf_Dispatcher $dispatcher
  * @param  string $jqueryVer 使用的jquery文件,默认值:jquery-1.11.2.min.js
  * @return view
  */
 public static function initYafBySooh($dispatcher, $jqueryVer = 'jquery-1.11.2.min.js')
 {
     $router = $dispatcher->getRouter();
     $router->addRoute("byVar", new \Yaf_Route_Supervar(SOOH_ROUTE_VAR));
     \Yaf_Loader::getInstance()->registerLocalNameSpace($GLOBALS['CONF']['localLibs']);
     $req = $dispatcher->getRequest();
     $tmp = $req->get('__ONLY__');
     if ($tmp == 'body') {
         \SoohYaf\Viewext::$bodyonly = true;
     }
     $tmp = trim($req->get('__VIEW__'));
     //html(default),wap,  json
     define('VIW_INC_PATH', APP_PATH . '/application/views/_inc/');
     \SoohYaf\Viewext::$jqueryVer = $jqueryVer;
     if (!empty($tmp)) {
         $tmp = strtolower($tmp);
         \Sooh\Base\Ini::getInstance()->viewRenderType($tmp);
         if ($tmp == 'jsonp') {
             \Sooh\Base\Ini::getInstance()->initGobal(array('nameJsonP' => $req->get('jsonp', 'jsonp')));
         }
     }
     //		$tmp = $dispatcher->getRequest()->get('__GZIP__');
     //		if(!empty($tmp)){
     //			$tmp = strtolower ($tmp);
     //			if($tmp=='gzip')define("ZIP_OUTPUT",$tmp);
     //		}
     $view = new \SoohYaf\Viewext(null);
     $dispatcher->setView($view);
     $dispatcher->registerPlugin(new SoohPlugin());
     return $view;
 }
Exemple #2
0
 public function errorAction($exception)
 {
     $ini = \Sooh\Base\Ini::getInstance();
     $render = $ini->viewRenderType();
     switch ($render) {
         case "json":
             header('Content-type: application/json');
             break;
         case 'jsonp':
             break;
         default:
             $ini->viewRenderType('json');
             header('Content-type: application/json');
             break;
     }
     if (is_a($exception, '\\Sooh\\DB\\Acl\\ErrNeedsLogin')) {
         \Sooh\Base\Log\Data::getInstance()->ret = 'needs login';
         //		}elseif(is_a($exception,'\Prj\ErrCode')){
         //			$this->_view->assign('code',$exception->getCode());
         //			$this->_view->assign('msg',$exception->getMessage());
         //			\Sooh\Base\Log\Data::getInstance()->ret = $exception->getMessage();
         //		}elseif(is_a($exception,'\Prj\RetCode')){
         //			$this->_view->assign('code',200);
         //			$this->_view->assign('msg',$exception->getMessage());
     } else {
         var_log($exception);
         $this->_view->assign('code', $exception->getCode());
         $this->_view->assign('msg', $exception->getMessage());
         \Sooh\Base\Log\Data::getInstance()->ret = $exception->getMessage();
     }
 }
Exemple #3
0
 protected static function numToSplit()
 {
     if (\Sooh\Base\Ini::getInstance()->get('deploymentCode') <= 20) {
         return 1;
     } else {
         return 1;
     }
 }
Exemple #4
0
 /**
  * 测试用
  */
 public function resetdayAction()
 {
     if (\Sooh\Base\Ini::getInstance()->get('deploymentCode') < 40) {
         $this->book->doDebugReset($this->_request->get('ymd') - 0, $this->_request->get('num', -1) - 0, $this->userOrAccountId);
         $this->_view->assign('userIdentifier', $this->user->getAccountId());
         $this->_view->assign('now', date('Ymd H:i:s'));
     }
 }
Exemple #5
0
 /**
  * 检查,必须是通过crond.php执行的
  */
 public function init()
 {
     $this->ini = \Sooh\Base\Ini::getInstance();
     if ($this->ini->get('released')) {
         if (SOOH_INDEX_FILE !== 'crond.php') {
             die('not start with crond');
         }
     }
 }
Exemple #6
0
 public function fetchini($service)
 {
     if ($this->rpc === null) {
         $ini = \Sooh\Base\Ini::getInstance()->get('RpcConfig');
         unset($ini['force']);
         return $ini;
     } else {
         \Sooh\Base\Log\Data::error('Rpcservices should never be called by rpc');
         throw new \Sooh\Base\ErrException('Rpcservices should never be called by rpc');
         //return $this->rpc->initArgs(array('arg1'=>$arg1))->send();//call('CheckinBook/'.__FUNCTION__, array($withBonus,$userOrAccountId));
     }
 }
Exemple #7
0
 /**
  * $guidtype 在构造时使用一次
  *   a 180组服务器,30几年后溢出,(每个请求需要一个进程处理至少1个毫秒,)
  *   b 18组服务器, 300年后溢出, (每个请求需要一个进程处理至少1个毫秒,)
  *   c 18组服务器, 30年后溢出,  (每个请求需要一个进程处理至少0.1个毫秒,)
  * @param string $guidtype 
  * @return \Sooh\Base\Log\Data
  */
 public static function getInstance($guidtype = 'c')
 {
     if (self::$_instance == null) {
         self::$_instance = new Data();
         $dt = \Sooh\Base\Time::getInstance();
         self::$_instance->ymd = $dt->YmdFull;
         self::$_instance->hhiiss = $dt->his;
         self::$_instance->ip = \Sooh\Base\Tools::remoteIP();
         self::$_instance->logGuid = self::$_instance->newLogId($guidtype);
         \Sooh\Base\Ini::registerShutdown(get_called_class() . '::onShutdown', 'logOnShutdown');
     }
     return self::$_instance;
 }
Exemple #8
0
 protected function fixTplPath($strTpl)
 {
     $renderType = \Sooh\Base\Ini::getInstance()->viewRenderType();
     switch ($renderType) {
         case 'html':
             return str_replace('.phtml', '.www.phtml', $strTpl);
         case 'wap':
             return str_replace('.phtml', '.wap.phtml', $strTpl);
         case 'echo':
             return;
         case 'json':
             return;
     }
 }
Exemple #9
0
 /**
  * 获取PRC配置参数
  * @param string $serviceName 
  * @return array array(key=>sss,urls=>array(),protocol=>默认HttpGet)
  * @throws \Sooh\Base\ErrException
  */
 public static function getRpcIni($serviceName)
 {
     if (self::$_rpcServices !== null) {
         return self::$_rpcServices->fetchini($serviceName);
     }
     $ini = \Sooh\Base\Ini::getInstance();
     if (empty(self::$_instances['_RPC_ROUTE_'])) {
         self::$_instances['_RPC_ROUTE_'] = new Broker();
         self::$_instances['_RPC_ROUTE_']->final_service = 'rpcservices';
         //self::$_instances['_RPC_ROUTE_']->final_cmd='fetchini';
         self::$_instances['_RPC_ROUTE_']->final_protocol = $ini->get('RpcConfig.protocol');
         self::$_instances['_RPC_ROUTE_']->final_key = $ini->get('RpcConfig.key');
         self::$_instances['_RPC_ROUTE_']->final_hosts = $ini->get('RpcConfig.urls');
     }
     return self::$_instances['_RPC_ROUTE_']->initArgs(array('service' => $serviceName))->send('fetchini');
 }
Exemple #10
0
 public function indexAction()
 {
     \Lib\Services\SessionStorage::setStorageIni();
     \Sooh\Base\Session\Data::getInstance(\Lib\Services\SessionStorage::getInstance($this->getRpcDefault('SessionStorage')));
     \Sooh\Base\Ini::getInstance()->viewRenderType('json');
     $this->_view->assign('normal', true);
     $this->_view->assign('sessionId', \Sooh\Base\Session\Data::getSessId());
     $this->_view->assign('accountId', \Sooh\Base\Session\Data::getInstance()->get('accountId'));
     $today = \Sooh\Base\Time::getInstance()->YmdFull;
     $uri0 = 'http://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . '' . $_SERVER["SCRIPT_NAME"];
     $this->_view->assign('urls', array('login' => $uri0 . '?__=passport/login&loginname=qq01&passwd=123456', 'register' => $uri0 . '?__=passport/register&loginname=qq01&passwd=123456&contractId=34562342523534', 'checkin-checkin' => $uri0 . '?__=checkin/checkin&with_bonus=1', 'checkin-today' => $uri0 . '?__=checkin/today&with_bonus=1', 'checkin-reset' => $uri0 . '?__=checkin/resetday&ymd=' . $today, 'checkin-resetAll' => $uri0 . '?__=checkin/resetday&ymd=' . $today . '&num=0'));
     //$this->_view->assign('code1',\Lib\Subdir\Abc::run());
     throw new \ErrorException('msg append by exception');
     //$this->_view->assign('code2',  \Subdir\Test::run());
     //$this->_view->assign('code3',\Subdir_Type1::run());
 }
Exemple #11
0
 public function init()
 {
     $this->ini = \Sooh\Base\Ini::getInstance();
     if ($this->_request->isPost()) {
         $this->onInit_chkMaintainTime();
     }
     list($deviceId, $uid) = $this->initSession();
     \Sooh\Base\Log\Data::addWriter(new \Sooh\Base\Log\Writers\TextAll(), 'trace');
     \Sooh\Base\Log\Data::addWriter(new \Sooh\Base\Log\Writers\TextAll(), 'error');
     \Sooh\Base\Log\Data::addWriter(new \Sooh\Base\Log\Writers\Database('dbgrpForLog', 2), 'evt');
     $log = \Sooh\Base\Log\Data::getInstance('c');
     $log->clientType = 0;
     $log->deviceId = $deviceId;
     $log->contractId = '0';
     $log->evt = $this->_request->getModuleName() . '/' . $this->_request->getControllerName() . '/' . $this->_request->getActionName();
     $log->isLogined = 0;
     $log->userId = $uid;
 }
Exemple #12
0
 protected function setUpReal($driver)
 {
     $this->driver = $driver;
     $lines = file(__DIR__ . '/../sqls/connect.ini');
     foreach ($lines as $line) {
         $tmp = explode('=', $line);
         if ($tmp[0] == $driver) {
             array_shift($tmp);
             $tmp = json_decode(implode('=', $tmp), true);
             $ini = \Sooh\Base\Ini::getInstance();
             $old = $ini->get('dbConf');
             $old[$this->driver] = $tmp;
             $ini->initGobal(array('dbConf' => $old));
             $this->dbDefault = $tmp['dbEnums']['default'] . '.';
             break;
         }
     }
     $this->getDB()->delRecords('tb_0', array('autoid' => 100));
 }
Exemple #13
0
 protected function setUpReal($driver)
 {
     $ini = \Sooh\Base\Ini::getInstance();
     $old = $ini->get('dbConf');
     $this->driver = $driver;
     $db_0 = $driver . '0';
     $db_1 = $driver . '1';
     $lines = file(__DIR__ . '/../sqls/connect.ini');
     foreach ($lines as $line) {
         $tmp = explode('=', $line);
         if ($tmp[0] == $db_0 || $db_1 == $tmp[0]) {
             $id = array_shift($tmp);
             $tmp = json_decode(implode('=', $tmp), true);
             $old[$id] = $tmp;
         }
     }
     $ini->initGobal(array('dbConf' => $old));
     $old = $ini->get('dbByObj');
     $old['TstKVObj'] = array($db_0, $db_1);
     $ini->initGobal(array('dbByObj' => $old));
     $this->getDB($db_1)->delRecords('tb_1', array('autoid' => 99));
 }
Exemple #14
0
 protected function onLogin($accountInfo)
 {
     $sess = \Sooh\Base\Session\Data::getInstance();
     $sess->set('accountId', $accountInfo['accountId']);
     $sess->set('nickname', $accountInfo['nickname']);
     $this->_view->assign('account', array('accountId' => $accountInfo['accountId'], 'nickname' => $accountInfo['nickname']));
     /**
     		$userOrAccountId = $this->user;
     		$checkinBook = \Lib\Services\CheckinBook::getInstance();
     */
     $userOrAccountId = $accountInfo['accountId'];
     $checkinBook = \Lib\Services\CheckinBook::getInstance($this->getRpcDefault('CheckinBook'));
     $this->_view->assign('checkinBook', $checkinBook->doGetTodayStatus(1, $userOrAccountId)['data']);
     $this->_view->assign('shopPoints', array('nleft' => 'todo', 'history' => array('todo')));
     $user = \Prj\Data\User::getCopy($userOrAccountId);
     setcookie('nickname', $accountInfo['nickname'], 0, '/', \Sooh\Base\Ini::getInstance()->cookieDomain());
     $user->load();
     $dt = \Sooh\Base\Time::getInstance();
     if ($user->exists() === false) {
         $user->setField('nickname', $accountInfo['nickname']);
         $user->setField('contractId', $accountInfo['contractId']);
         $user->setField('regYmd', $dt->YmdFull);
         $user->setField('regHHiiss', $dt->his);
         $user->setField('regClient', self::tmp_clientType);
         $user->setField('regIP', \Sooh\Base\Tools::remoteIP());
         //$user->setField(self::fieldUser, array());
         $user->update();
     } else {
         $user->setField('nickname', $accountInfo['nickname']);
         $user->setField('lastDt', $dt->timestamp());
         $user->setField('lastIP', \Sooh\Base\Tools::remoteIP());
         $user->update();
     }
     $sess->shutdown();
     $this->returnOK();
 }
Exemple #15
0
 /**
  * start session if session not init
  */
 protected function start()
 {
     if ($this->sessionArr === null) {
         $this->timestamp = \Sooh\Base\Time::getInstance()->timestamp();
         $tmp = $this->storage->load($this->sessionId);
         if (empty($tmp) || empty($tmp['trans'])) {
             $this->record = array('sessionId' => $this->sessionId);
             $this->sessionArr = array();
             //error_log("[TRACE-session ".$_COOKIE['SoohSessId']." data] skip init");
         } else {
             $this->record = $tmp['trans'];
             $this->sessionArr = $tmp['data'];
             if ($this->get('accountId')) {
                 $secLast = $this->sessionArr['__dTaCcOuNt__'] - 0;
                 $secPast = $this->timestamp - $secLast;
                 if ($secPast > 300) {
                     $this->sessionArr['__eXpIrE__']['accountId'] += min([$secPast, 900]);
                     $this->sessionArr['__dTaCcOuNt__'] = $this->timestamp;
                     $this->changed = true;
                     //error_log("[TRACE-session ".$_COOKIE['SoohSessId']." data] update expire as secPast=$secPast");
                 } else {
                     //error_log("[TRACE-session ".$_COOKIE['SoohSessId']." data] skip secPast=$secPast");
                 }
             } else {
                 //error_log("[TRACE-session ".$_COOKIE['SoohSessId']." data] skip not login");
             }
         }
         \Sooh\Base\Ini::registerShutdown(array($this, 'shutdown'), 'sessionOnShutdown');
     }
 }
Exemple #16
0
 protected function checkSign($service, $appKey = null)
 {
     $dt = $this->_request->get('dt');
     $sign = $this->_request->get('sign');
     if ($appKey === null) {
         $arr = \Sooh\Base\Rpc\Broker::getRpcIni($service);
         $appKey = $arr['key'];
     }
     if (\Sooh\Base\Ini::getInstance()->get('released')) {
         $dur = abs($dt - time());
         if ($dur > 60) {
             $this->error('sign error');
             return false;
         }
         if ($sign != md5($dt . $appKey)) {
             $this->error('sign error');
             return false;
         }
     } else {
         if (empty($sign)) {
             error_log('trace:sign of serviceCtrl skipped');
         } elseif ($sign != md5($dt . $appKey)) {
             $this->error('sign error');
             return false;
         }
     }
     return true;
 }
Exemple #17
0
 public static function runBackground($strArgs)
 {
     $ini = \Sooh\Base\Ini::getInstance();
     if (DIRECTORY_SEPARATOR == '/') {
         //unix
         $cmd = $ini->get('path_php') . ' ' . $ini->get('path_console') . " \"{$strArgs}\" &";
     } else {
         //win
         $cmd = 'start /b ' . $ini->get('path_php') . ' ' . $ini->get('path_console') . " \"{$strArgs}\"";
     }
     pclose(popen($cmd, 'r'));
     return $cmd;
 }
Exemple #18
0
define("APP_PATH", dirname(__DIR__));
/* 指向public的上一级 */
if (!defined('SOOH_INDEX_FILE')) {
    define('SOOH_INDEX_FILE', 'index.php');
}
define('SOOH_ROUTE_VAR', '__');
error_log("-------------------------------------------------------tart:route=" . $_GET['__'] . " cmd=" . $_GET['cmd'] . " pid=" . getmypid());
include dirname(__DIR__) . '/conf/globals.php';
$ini = \Sooh\Base\Ini::getInstance();
$app = new Yaf_Application(APP_PATH . "/conf/application.ini");
$dispatcher = $app->getDispatcher();
if (!empty($reqeustReal)) {
    $dispatcher->setRequest($reqeustReal);
}
$view = \SoohYaf\SoohPlugin::initYafBySooh($dispatcher);
$dispatcher->returnResponse(TRUE);
try {
    $response = $app->run();
} catch (\ErrorException $e) {
    $view->assign('code', $e->getCode());
    $view->assign('msg', $e->getMessage());
    error_log("Error Caught at index.php:" . $e->getMessage() . "\n" . \Sooh\DB\Broker::lastCmd() . "\n" . $e->getTraceAsString() . "\n");
    $response = new Yaf_Response_Http();
    $response->setBody($view->render('ctrl/action.phtml'));
}
if ($ini->viewRenderType() === 'json') {
    header('Content-type: application/json');
}
$response->response();
\Sooh\Base\Ini::registerShutdown(null, null);
error_log("====================================================================end:route=" . $_GET['__'] . " cmd=" . $_GET['cmd'] . " pid=" . getmypid());
Exemple #19
0
 /**
  * 设置数据库相关配置
  * @param \Sooh\Base\Ini $ini
  * @param array $tmp
  * @param int $disk_cache 0:disk 1:cache
  */
 protected function initdb($ini, $tmp, $disk_cache)
 {
     $this->numToSplit[$disk_cache] = $tmp[0];
     $db = $ini->get('dbConf.' . $tmp[1] . '.dbEnums');
     $this->dbname[$disk_cache] = isset($db[$this->objIdentifier]) ? $db[$this->objIdentifier] : $db['default'];
     array_shift($tmp);
     $this->_allHosts[$disk_cache] = $tmp;
 }
Exemple #20
0
 public static function free($arrConf_or_strModName = null, $subid = null)
 {
     if ($arrConf_or_strModName == null) {
         $ks = array_keys(self::$_instances);
     } elseif (is_array($arrConf_or_strModName)) {
         $ks = array(self::idOfConnection($arrConf_or_strModName));
     } else {
         $ini = sooh_ini::getInstance();
         $dbid = $ini->get('dbByObj.' . $arrConf_or_strModName);
         if ($dbid === null) {
             $dbid = $ini->get('dbByObj.default');
         }
         if (is_array($dbid)) {
             if ($subid === null) {
                 $ks = array();
                 foreach ($dbid as $subid) {
                     $ks[] = self::idOfConnection(self::confOfMod($arrConf_or_strModName, $subid));
                 }
             } else {
                 $ks = array(self::idOfConnection(self::confOfMod($arrConf_or_strModName, $subid)));
             }
         } else {
             $ks = array(self::idOfConnection(self::confOfMod($arrConf_or_strModName, null)));
         }
     }
     if (sooh_trace::needsWrite(__CLASS__)) {
         sooh_trace::obj('final free these db(s):', $ks);
     }
     foreach ($ks as $id) {
         if (isset(self::$_instances[$id])) {
             self::$_instances[$id]->free();
             unset(self::$_instances[$id]);
         }
     }
 }
Exemple #21
0
 public function runCrond($task = null, $ymdh = null)
 {
     //$this->_log->writeCrondLog(null, __FUNCTION__."($task=null, crond)");
     clearstatcache();
     $ini = \Sooh\Base\Ini::getInstance();
     $this->_isManual = false;
     $dt = \Sooh\Base\Time::getInstance();
     if ($dt->hour == 3) {
         $this->_log->remoreCrondLogExpired();
     }
     if (empty($task)) {
         // loop and check all new paths in a hour
         $subdirs0 = array();
         for ($i = 0; $i < 6; $i++) {
             $subdirs = $this->getTaskDirs();
             //$this->_log->writeCrondLog(null, __FUNCTION__." scan subdirs,".sizeof($subdirs).' found');
             foreach ($subdirs as $subdir) {
                 if (!in_array($subdir, $subdirs0)) {
                     $this->forkTask($subdir . '.*');
                     $subdirs0[] = $subdir;
                 }
             }
             if ($i < 5) {
                 sleep(600);
                 clearstatcache();
             }
         }
     } elseif (substr($task, -1) == '*') {
         // loop and check all new class in specify path in a hour
         $dir = substr($task, 0, -2);
         $task0 = array();
         if ($dir == 'Standalone') {
             for ($i = 0; $i < 6; $i++) {
                 $tasks = $this->getTasks($dir);
                 //$this->_log->writeCrondLog(null, __FUNCTION__." scan Standalone,".sizeof($tasks).' tasks found');
                 foreach ($tasks as $task => $fullpath) {
                     if (!in_array($task, $task0)) {
                         $task0[] = $task;
                         $this->forkTask('Standalone.' . $task);
                     }
                 }
                 if ($i < 5) {
                     sleep(600);
                     clearstatcache();
                 }
             }
         } else {
             for ($i = 0; $i < 60; $i++) {
                 if ($i % 10 == 0) {
                     $tasks = $this->getTasks($dir);
                     //$this->_log->writeCrondLog(null, __FUNCTION__." scan $dir,".sizeof($tasks).' tasks found');
                     foreach ($tasks as $task => $fullpath) {
                         if (!in_array($task, $task0)) {
                             $task0[] = $task;
                             $this->newTask($dir, $task, $fullpath);
                         }
                     }
                     clearstatcache();
                 }
                 $ret = $this->loop($dt);
                 if ($i > 50 && $ret == false) {
                     break;
                 }
                 $dt->sleepTo($dt->hour, $dt->minute + 1, $ini->get('crondBatchSleepTo') - 0);
             }
         }
     } else {
         $r = explode('.', $task);
         $this->newTask($r[0], $r[1], $this->_baseDir . '/' . $r[0] . '/' . $r[1] . '.php');
         for ($i = 0; $i < 60; $i++) {
             if ($this->loop($dt)) {
                 //$this->_log->writeCrondLog(null, __FUNCTION__." run single,needs sleep to ".$dt->hour.":".($dt->minute+1));
                 $dt->sleepTo($dt->hour, $dt->minute + 1, $ini->get('crondBatchSleepTo') - 0);
             } else {
                 //$this->_log->writeCrondLog(null, __FUNCTION__." run single,end no more");
                 break;
             }
         }
     }
     //$this->_log->writeCrondLog(null, __FUNCTION__." done");
 }
Exemple #22
0
 protected static function getDBAndTbNameById(&$tbnameToSet, $splitedId, $isCache = false)
 {
     $dbByObj = static::idFor_dbByObj_InConf($isCache);
     $ini = sooh_ini::getInstance();
     $dbId = $ini->get('dbByObj.' . $dbByObj);
     if (is_array($dbId)) {
         $i = $splitedId % (sizeof($dbId) - 1);
         $confIDStr = 'dbConf.' . $dbId[$i + 1];
     } elseif (!empty($dbId)) {
         $confIDStr = 'dbConf.' . $dbId;
     } else {
         $tmp = $ini->get('dbByObj.default');
         if (empty($tmp)) {
             $confIDStr = 'dbConf.default';
         } else {
             if (is_array($tmp)) {
                 $i = $splitedId % (sizeof($tmp) - 1);
                 $confIDStr = 'dbConf.' . $tmp[$i + 1];
             } else {
                 $confIDStr = 'dbConf.' . $tmp;
             }
         }
     }
     $conf = $ini->get($confIDStr);
     if (empty($conf)) {
         error_log('try find ' . $confIDStr . ' in dbConf failed for ' . $dbByObj);
         return null;
     }
     $db = sooh_dbBroker::getInstance($conf, $dbByObj);
     if (isset($conf['dbEnums'][$dbByObj])) {
         $dbname = $conf['dbEnums'][$dbByObj];
     } else {
         $dbname = $conf['dbEnums']['default'];
     }
     $tbnameToSet = $dbname . '.' . static::splitedTbName($splitedId, $isCache);
     return $db;
 }