當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DI函數代碼示例

本文整理匯總了PHP中DI函數的典型用法代碼示例。如果您正苦於以下問題:PHP DI函數的具體用法?PHP DI怎麽用?PHP DI使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了DI函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: go

 /**
  * 執行任務
  * @param string $service MQ中的接口服務名稱,如:Default.Index
  * @return array('total' => 總數量, 'fail' => 失敗數量)
  */
 public function go($service)
 {
     $rs = array('total' => 0, 'fail' => 0);
     $todoList = $this->mq->pop($service, $this->step);
     $failList = array();
     while (!empty($todoList)) {
         $rs['total'] += count($todoList);
         foreach ($todoList as $params) {
             try {
                 $isFinish = $this->youGo($service, $params);
                 if (!$isFinish) {
                     $rs['fail']++;
                 }
             } catch (PhalApi_Exception_InternalServerError $ex) {
                 $rs['fail']++;
                 $failList[] = $params;
                 DI()->logger->error('task occur exception to go', array('service' => $service, 'params' => $params, 'error' => $ex->getMessage()));
             }
         }
         $todoList = $this->mq->pop($service, $this->step);
     }
     foreach ($failList as $params) {
         $this->mq->add($service, $params);
     }
     return $rs;
 }
開發者ID:visionzk,項目名稱:phalapi,代碼行數:31,代碼來源:Runner.php

示例2: generateService

 /**
  * 創建服務器
  * 根據客戶端提供的接口服務名稱和需要調用的方法進行創建工作,如果創建失敗,則拋出相應的自定義異常
  *
  * 創建過程主要如下:
  * - 1、 是否缺少控製器名稱和需要調用的方法
  * - 2、 控製器文件是否存在,並且控製器是否存在
  * - 3、 方法是否可調用
  * - 4、 控製器是否初始化成功
  *
  * @param boolen $isInitialize 是否在創建後進行初始化
  * @param string $_REQUEST['service'] 接口服務名稱,格式:XXX.XXX
  * @return PhalApi_Api 自定義的控製器
  *
  * @uses PhalApi_Api::init()
  * @throws PhalApi_Exception_BadRequest 非法請求下返回400
  */
 static function generateService($isInitialize = TRUE)
 {
     $service = DI()->request->get('service', 'Default.Index');
     $serviceArr = explode('.', $service);
     if (count($serviceArr) < 2) {
         throw new PhalApi_Exception_BadRequest(T('service ({service}) illegal', array('service' => $service)));
     }
     list($apiClassName, $action) = $serviceArr;
     $apiClassName = 'Api_' . ucfirst($apiClassName);
     $action = lcfirst($action);
     if (!class_exists($apiClassName)) {
         throw new PhalApi_Exception_BadRequest(T('no such service as {service}', array('service' => $service)));
     }
     $api = new $apiClassName();
     if (!is_subclass_of($api, 'PhalApi_Api')) {
         throw new PhalApi_Exception_InternalServerError(T('{class} should be subclass of PhalApi_Api', array('class' => $apiClassName)));
     }
     if (!method_exists($api, $action) || !is_callable(array($api, $action))) {
         throw new PhalApi_Exception_BadRequest(T('no such service as {service}', array('service' => $service)));
     }
     if ($isInitialize) {
         $api->init();
     }
     return $api;
 }
開發者ID:visionzk,項目名稱:phalapi,代碼行數:42,代碼來源:ApiFactory.php

示例3: request

 protected function request($type, $uri, $params, $timeoutMs)
 {
     $url = $this->host . '/' . ltrim($uri, '/');
     $params['client_id'] = $this->clientId;
     $curl = $this->curl;
     $apiRs = null;
     if ($type == 'get') {
         $apiRs = $curl->get($url . '?' . http_build_query($params), $timeoutMs);
     } else {
         $apiRs = $curl->post($url, $params, $timeoutMs);
     }
     if ($apiRs === false) {
         DI()->logger->debug("youku api {$type} timeout", $url . '?' . http_build_query($params));
         return array();
     }
     $apiRsArr = json_decode($apiRs, true);
     if (empty($apiRsArr) || !is_array($apiRsArr)) {
         DI()->logger->debug("youku api {$type} nothing return", $url . '?' . http_build_query($params));
         return array();
     }
     if (isset($apiRsArr['error'])) {
         DI()->logger->debug("youku  api {$type} error", array('error' => $apiRsArr['error'], 'url' => $url . '?' . http_build_query($params)));
     }
     return $apiRsArr;
 }
開發者ID:WJayWJay,項目名稱:phalapi-library,代碼行數:25,代碼來源:Lite.php

示例4: runAllWaittingItems

 protected function runAllWaittingItems()
 {
     $waittingItems = $this->model->getAllWaittingItems();
     foreach ($waittingItems as $item) {
         //
         if (!$this->model->isRunnable($item['id'])) {
             continue;
         }
         $class = $item['trigger_class'];
         $params = $item['fire_params'];
         if (empty($class) || !class_exists($class)) {
             DI()->logger->error('Error: task can not run illegal class', $item);
             $this->model->updateExceptionItem($item['id'], 'task can not run illegal class');
             continue;
         }
         $trigger = new $class();
         if (!is_callable(array($class, 'fire'))) {
             DI()->logger->error('Error: task can not call fire()', $item);
             $this->model->updateExceptionItem($item['id'], 'task can not call fire()');
             continue;
         }
         $this->model->setRunningState($item['id']);
         try {
             $result = call_user_func(array($trigger, 'fire'), $params);
             $this->model->updateFinishItem($item['id'], $result);
         } catch (Exception $ex) {
             throw $ex;
             $this->model->updateExceptionItem($item['id'], $ex->getMessage());
         }
     }
 }
開發者ID:visionzk,項目名稱:phalapi,代碼行數:31,代碼來源:Progress.php

示例5: send

 /**
  * 發送郵件
  * @param array/string $addresses 待發送的郵箱地址
  * @param sting $title 標題
  * @param string $content 內容
  * @param boolean $isHtml 是否使用HTML格式,默認是
  * @return boolean 是否成功
  */
 public function send($addresses, $title, $content, $isHtml = TRUE)
 {
     $mail = new PHPMailer();
     $cfg = $this->config;
     $mail->isSMTP();
     $mail->Host = $cfg['host'];
     $mail->SMTPAuth = true;
     $mail->Username = $cfg['username'];
     $mail->Password = $cfg['password'];
     $mail->CharSet = 'utf-8';
     $mail->From = $cfg['username'];
     $mail->FromName = $cfg['fromName'];
     $addresses = is_array($addresses) ? $addresses : array($addresses);
     foreach ($addresses as $address) {
         $mail->addAddress($address);
     }
     $mail->WordWrap = 50;
     $mail->isHTML($isHtml);
     $mail->Subject = trim($title);
     $mail->Body = $content . $cfg['sign'];
     if (!$mail->send()) {
         if ($this->debug) {
             DI()->logger->debug('Fail to send email with error: ' . $mail->ErrorInfo);
         }
         return false;
     }
     if ($this->debug) {
         DI()->logger->debug('Succeed to send email', array('addresses' => $addresses, 'title' => $title));
     }
     return true;
 }
開發者ID:WJayWJay,項目名稱:phalapi-library,代碼行數:39,代碼來源:Lite.php

示例6: __construct

 /**
  * 為代理指定委托的緩存組件,默認情況下使用DI()->cache
  */
 public function __construct(PhalApi_Cache $cache = NULL)
 {
     $this->cache = $cache !== NULL ? $cache : DI()->cache;
     //退而求其次
     if ($this->cache === NULL) {
         $this->cache = new PhalApi_Cache_None();
     }
 }
開發者ID:visionzk,項目名稱:phalapi,代碼行數:11,代碼來源:ModelProxy.php

示例7: testCheckWithRightSign

 public function testCheckWithRightSign()
 {
     $data = array('service' => 'PhalApi_Api_Impl.Add', 'left' => 1, 'right' => 1, 'sign' => 'd5c2ea888a6390de5210b9496a1b787a');
     DI()->request = new PhalApi_Request($data);
     $api = new PhalApi_Api_Impl();
     $api->init();
     $rs = $api->add();
     $this->assertEquals(2, $rs);
 }
開發者ID:visionzk,項目名稱:phalapi,代碼行數:9,代碼來源:PhalApi_Filter_SimpleMd5_Test.php

示例8: _renewalTo

 /**
  * 續期
  *
  * - 當有效期為當前時間時,即退出
  */
 protected static function _renewalTo($newExpiresTime)
 {
     $userId = DI()->request->get('user_id');
     $token = DI()->request->get('token');
     if (empty($userId) || empty($token)) {
         return;
     }
     $model = new Model_User_UserSession();
     $model->updateExpiresTime($userId, $token, $newExpiresTime);
 }
開發者ID:WJayWJay,項目名稱:phalapi-library,代碼行數:15,代碼來源:Lite.php

示例9: formatAllType

 /**
  * 統一分發處理
  * @param string $type 類型
  * @param string $value 值
  * @param array $rule 規則配置
  * @return mixed
  */
 protected static function formatAllType($type, $value, $rule)
 {
     $diKey = '_formatter' . ucfirst($type);
     $diDefautl = 'PhalApi_Request_Formatter_' . ucfirst($type);
     $formatter = DI()->get($diKey, $diDefautl);
     if (!$formatter instanceof Phalapi_Request_Formatter) {
         throw new PhalApi_Exception_InternalServerError(T('invalid type: {type} for rule: {name}', array('type' => $type, 'name' => $rule['name'])));
     }
     return $formatter->parse($value, $rule);
 }
開發者ID:visionzk,項目名稱:phalapi,代碼行數:17,代碼來源:Var.php

示例10: getByUserIdWithCache

 public function getByUserIdWithCache($userId)
 {
     $key = 'userbaseinfo_' . $userId;
     $rs = DI()->cache->get($key);
     if ($rs === NULL) {
         $rs = $this->getByUserId($userId);
         DI()->cache->set($key, $rs, 600);
     }
     return $rs;
 }
開發者ID:visionzk,項目名稱:phalapi,代碼行數:10,代碼來源:User.php

示例11: __construct

 /**
  * @param $config['crypt'] 加密的服務,如果未設置,默認取DI()->crypt,須實現PhalApi_Crypt接口
  * @param $config['key'] $config['crypt']用的密鑰,未設置時有一個md5串
  */
 public function __construct($config = array())
 {
     parent::__construct($config);
     $this->config['crypt'] = isset($config['crypt']) ? $config['crypt'] : DI()->crypt;
     if (isset($config['crypt']) && $config['crypt'] instanceof PhalApi_Crypt) {
         $this->config['key'] = isset($config['key']) ? $config['key'] : 'debcf37743b7c835ba367548f07aadc3';
     } else {
         $this->config['crypt'] = NULL;
     }
 }
開發者ID:visionzk,項目名稱:phalapi,代碼行數:14,代碼來源:Multi.php

示例12: response

 public function response($params = NULL)
 {
     $paramsArr = json_decode($params, TRUE);
     if ($paramsArr !== FALSE) {
         DI()->request = new PhalApi_Request(array_merge($_GET, $paramsArr));
     } else {
         DI()->request = new PhalApi_Request($_GET);
     }
     $rs = $this->phalapi->response();
     return $rs->getResult();
 }
開發者ID:WJayWJay,項目名稱:phalapi-library,代碼行數:11,代碼來源:PhalApi.php

示例13: testDecryptAfterEncrypt

 /**
  * demo
  */
 public function testDecryptAfterEncrypt()
 {
     $keyG = new PhalApi_Crypt_RSA_KeyGenerator();
     $privkey = $keyG->getPriKey();
     $pubkey = $keyG->getPubKey();
     DI()->crypt = new PhalApi_Crypt_RSA_MultiPri2Pub();
     $data = 'AHA! I have $2.22 dollars!';
     $encryptData = DI()->crypt->encrypt($data, $privkey);
     $decryptData = DI()->crypt->decrypt($encryptData, $pubkey);
     $this->assertEquals($data, $decryptData);
 }
開發者ID:visionzk,項目名稱:phalapi,代碼行數:14,代碼來源:PhalApi_Crypt_RSA_MultiPri2Pub_Test.php

示例14: __construct

 public function __construct($queryArr = array())
 {
     $this->timestamp = $_SERVER['REQUEST_TIME'];
     if (DI()->debug) {
         $this->readCache = FALSE;
         $this->writeCache = FALSE;
     }
     foreach ($queryArr as $key => $value) {
         $this->{$key} = $value;
     }
 }
開發者ID:visionzk,項目名稱:phalapi,代碼行數:11,代碼來源:ModelQuery.php

示例15: youGo

 protected function youGo($service, $params)
 {
     $rs = $this->contector->request($service, $params, $this->timeoutMS);
     if ($this->contector->getRet() == 404) {
         throw PhalApi_Exception_InternalServerError('task request api time out', array('url' => $this->contector->getUrl()));
     }
     $isOk = $this->contector->getRet() == 200 ? TRUE : FALSE;
     if (!$isOk) {
         DI()->logger->debug('task remote request not ok', array('url' => $this->contector->getUrl(), 'ret' => $this->contector->getRet(), 'msg' => $this->contector->getMsg()));
     }
     return $isOk;
 }
開發者ID:visionzk,項目名稱:phalapi,代碼行數:12,代碼來源:Remote.php


注:本文中的DI函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。