Example #1
0
 public function initialize($args)
 {/*{{{*/
     if (isset($args['_master_']) && $args['_master_'])
     {
         BeanFinder::get('dbexecuter')->mustUseMaster();
     }
     $configs = $this->prepareConfigs();
     BeanFinder::register('configs', $configs);
     BeanFinder::register('idgenter', IDGenterClient::getInstance());
 }/*}}}*/
Example #2
0
 public function getRelationCache()
 {
     if (BeanFinder::has('relationcache'))
     {
         return BeanFinder::get('relationcache');
     }
     $cache = new DALRelationCacheManager($this->getCache(Cacher::CACHETYPE_RELATION));
     BeanFinder::register('relationcache', $cache);
     return $cache;
 }
Example #3
0
<?php
require(__DIR__.'/../assembly.php');
include(__DIR__.'/../mywebapp.php');

$cryptConfigFile = __DIR__.'/../controllers/mobileapi/ios/cryptconfig.php';
BeanFinder::register('wapconfigs', new Configuration($cryptConfigFile));

$application = new MyWebApplication(__DIR__.'/..');
$application->run();
Example #4
0
    public function run($configs)
    {/*{{{*/
        $result = array();
        $result['errno'] = -1;
        $result['data'] = array();
        try
        {
            BeanFinder::register('configs', new Configuration($configs));
            $this->initDebug();
            Logger::setUp($configs['system']);
            BeanFinder::get('debug')->begin('service', $this->service.'::'.$this->do, true);

            //是否需要进程间同步
            $synchronized = isset($this->options['synchronized'])?$this->options['synchronized']:false;
            if ($synchronized)
            {
                $cacher= DAL::get()->getCache(Cacher::CACHETYPE_LOCKER);
                $lockUtil  = LockUtil::factory(LockUtil::LOCK_TYPE_MEMCACHE, array('memcache' => $cacher));
                $lockName = $this->service.$this->do;

                //client来决定同步标志,同一个方法,可以根据不用的标志来实施不同的锁
                //同一个service,synchronizedKey 不能重复
                $synchronizedKey = isset($this->options['synchronizedKey'])?$this->options['synchronizedKey']:false;
                if ($synchronizedKey)
                {
                    $lockName = $this->service.':'.$synchronizedKey;
                }
                $lockName = strtolower($lockName);
                $lockUtil->getLock($lockName, 10);
            }

            $uw = new UnitOfWork();
            $service = new $this->service;
            $service->initialize($this->options);
            $this->checkMethod($service);
            

            //error_log("files: ".print_r($_FILES, true), 3, '/tmp/a');
            //error_log("args: ".print_r($this->args, true), 3, '/tmp/a');
            //error_log("service: ".print_r($service, true), 3, '/tmp/a');
            //error_log("do: ".print_r($this->do, true), 3, '/tmp/a');
            //error_log("options: ".print_r($this->options, true), 3, '/tmp/a');
            $result['data'] = call_user_func_array(array($service, $this->do), $this->args);

            $uw->commit();

            BeanFinder::get('debug')->end();
            $result = $this->terminateDebug($result);

            $service->terminate();

            if ($synchronized && $lockUtil)
			    $lockUtil->releaseLock($lockName);

            $uw = $service = null;
            $this->checkOutput($result['data']);
            $result['errno'] = 0;
        }
        catch (LockException $e)
        {
            $result['errmsg']  = 'LockTimeOut';
            $result['exception'] = get_class($e);
            $result['ex'] = $e;
            //do some log here
            error_log(date('Y-m-d H:i:s')." ".print_r(unserialize(serialize($e)), true), 3, '/tmp/exception_sys.log');

            BeanFinder::get('debug')->addParams($e)->autoCloseNode();
            $result = $this->terminateDebug($result);
        }
        catch (BizException $e)
        {
            $result['errmsg']  = $e->getMessage();
            $result['exception'] = get_class($e);
            $result['ex'] = $e;
            //do some log here
            //error_log(print_r($e, true), 3, '/tmp/exception_biz.log');

            if ($synchronized && $lockUtil)
			    $lockUtil->releaseLock($lockName);

            BeanFinder::get('debug')->addParams($e)->autoCloseNode();
            $result = $this->terminateDebug($result);
        }
        catch (SystemException $e)
        {
            $result['errmsg']  = '系统错误';
            $result['exception'] = get_class($e);
            $result['ex'] = $e;
            //do some log here
            error_log(date('Y-m-d H:i:s')." ".print_r(unserialize(serialize($e)), true), 3, '/tmp/exception_sys.log');

            if ($synchronized && $lockUtil)
			    $lockUtil->releaseLock($lockName);

            BeanFinder::get('debug')->addParams($e)->autoCloseNode();
            $result = $this->terminateDebug($result);
        }
        catch (CustomException $e)
        {
            $result['errmsg']  = '系统错误';
            $result['exception'] = get_class($e);
            $result['ex'] = $e;
            //do some log here
            error_log(date('Y-m-d H:i:s')." ".print_r($e->errorMessage(), true), 3, '/tmp/exception_sys.log');

            if ($synchronized && $lockUtil)
			    $lockUtil->releaseLock($lockName);

            BeanFinder::get('debug')->addParams($e)->autoCloseNode();
            $result = $this->terminateDebug($result);
        }
        catch (Exception $e)
        {
            $result['errmsg']  = '系统错误';
            $result['exception'] = get_class($e);
            $result['ex'] = $e;
            //do some log here
            error_log(date('Y-m-d H:i:s')." ".print_r(unserialize(serialize($e)), true), 3, '/tmp/exception_sys.log');

            if ($synchronized && $lockUtil)
			    $lockUtil->releaseLock($lockName);

            BeanFinder::get('debug')->addParams($e)->autoCloseNode();
            $result = $this->terminateDebug($result);
        }
        return $this->prepareOutput($result);
    }/*}}}*/
Example #5
0
 public final function commit($restart = false)
 {
     if ($this->isCommited()) {
         throw new SystemException('UnitOfWork is commited, can not commit again.');
     }
     if ($this->isReadOnly() == false) {
         $this->findModifiedEntities();
         $statements = array();
         $this->buildSqlStatement('getInsertCommand', $this->insertList, $statements);
         $this->buildSqlStatement('getUpdateCommand', $this->updateList, $statements);
         $this->buildSqlStatement('getDeleteCommand', $this->deleteList, $statements);
         $this->doCommit($statements);
         $this->cleanCache();
         $this->dealSearchIndex();
     }
     if ($restart) {
         $this->insertList = array();
         $this->updateList = array();
         $this->deleteList = array();
         $this->searchRelatedList = array();
         BeanFinder::register('LocalCache', new LocalCache());
     } else {
         BeanFinder::destroy('UnitOfWork');
     }
 }
Example #6
0
 public function initialize($args)
 {/*{{{*/
     $configs = $this->prepareConfigs();
     BeanFinder::register('configs', $configs);
     BeanFinder::register('dbexecuter', DAL::get()->getCmdDbExecuter());
 }/*}}}*/
Example #7
0
 private static function initForService($path, $encoding)
 {
     /*{{{*/
     self::init($path, $encoding);
     BeanFinder::register('idgenter', IDGenterClient::getInstance());
 }
Example #8
0
 /**
  * 初始化logger
  * 
  * @static
  * @access public
  * @return void
  */
 public static function setUp($channel)
 {
     /*{{{*/
     $configs = BeanFinder::get('configs');
     if (isset($configs->logLevel) && $configs->logLevel && isset($configs->logPath) && $configs->logPath) {
         $logger = new static($channel, $configs->logPath, $configs->logLevel);
     } else {
         $logger = NullEntity::create();
     }
     BeanFinder::register('logger', $logger);
 }
Example #9
0
 public function __construct()
 {/*{{{*/
     $this->mobiles = HdfPhoneNumber::$opsPhoneNumbers;
     BeanFinder::register('alertMobiles', $this->mobiles);
 }/*}}}*/
Example #10
0
require(__DIR__.'/../assembly.php');
require(__DIR__.'/databucket_test.php');
require(__DIR__.'/casedatabucket_test.php');
require(__DIR__.'/messagedatabucket_test.php');
require(__DIR__.'/followupdatabucket_test.php');
require(__DIR__.'/doctordatabucket_test.php');
require(__DIR__.'/articledatabucket_test.php');
require(__DIR__.'/paymentdatabucket_test.php');
require(__DIR__.'/hospitaldatabucket_test.php');
EnvSetupHelper::initForWeb(__DIR__.'/../');

$cryptConfigFile = __DIR__.'/../controllers/mobileapi/ios/cryptconfig.php';
BeanFinder::register('wapconfigs', new Configuration($cryptConfigFile));

$versionConfigFile = __DIR__.'/../config/config.php';
BeanFinder::register('configs', new Configuration($versionConfigFile));

class AllTests
{
    public static function suite()
    {/*{{{*/
        $suite = new PHPUnit_Framework_TestSuite();
        $suite->addTestSuite('DataBucketTest');
        $suite->addTestSuite('CaseDataBucketTest');
        $suite->addTestSuite('MessageDataBucketTest');
        $suite->addTestSuite('FollowupDataBucketTest');
        $suite->addTestSuite('DoctorDataBucketTest');
        $suite->addTestSuite('ArticleDataBucketTest');
        $suite->addTestSuite('PaymentDataBucketTest');
        $suite->addTestSuite('HospitalDataBucketTest');
        return $suite;