当前位置: 首页>>代码示例>>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;未经允许,请勿转载。