当前位置: 首页>>代码示例>>PHP>>正文


PHP URI::withQueryValue方法代码示例

本文整理汇总了PHP中URI::withQueryValue方法的典型用法代码示例。如果您正苦于以下问题:PHP URI::withQueryValue方法的具体用法?PHP URI::withQueryValue怎么用?PHP URI::withQueryValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在URI的用法示例。


在下文中一共展示了URI::withQueryValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: it_generates_the_expected_request_when_listing_notifications

 function it_generates_the_expected_request_when_listing_notifications()
 {
     //---------------------------------
     // Test Setup
     $filters = ['status' => 'delivered', 'page' => '1', 'template_type' => 'sms'];
     $this->httpClient->sendRequest(Argument::type('Psr\\Http\\Message\\RequestInterface'))->willReturn(new Response(200, ['Content-type' => 'application/json'], json_encode(['notifications' => array()])));
     //---------------------------------
     // Perform action
     $this->listNotifications($filters);
     //---------------------------------
     // Check result
     // Check the expected Request was sent.
     $this->httpClient->sendRequest(Argument::that(function ($v) use($filters) {
         // Check a request was sent.
         if (!$v instanceof RequestInterface) {
             return false;
         }
         //---
         $url = new Uri(self::BASE_URL . Client::PATH_NOTIFICATION_LIST);
         foreach ($filters as $name => $value) {
             $url = URI::withQueryValue($url, $name, $value);
         }
         // With the correct URL
         if ($v->getUri() != $url) {
             return false;
         }
         //---
         // Include the correct token header
         if ($v->getHeader('Authorization') != ['Bearer ' . self::TEST_JWT_TOKEN]) {
             return false;
         }
         // And correct Content-type
         if ($v->getHeader('Content-type') != ['application/json']) {
             return false;
         }
         return true;
     }))->shouldHaveBeenCalled();
 }
开发者ID:alphagov,项目名称:notifications-php-client,代码行数:38,代码来源:ClientSpec.php

示例2: httpGet

 /**
  * Performs a GET against the Notify API.
  *
  * @param string $path
  * @param array  $query
  *
  * @return array|null
  * @throw Exception\NotifyException | Exception\ApiException | Exception\UnexpectedValueException
  */
 private function httpGet($path, array $query = array())
 {
     $url = new Uri($this->baseUrl . $path);
     foreach ($query as $name => $value) {
         $url = URI::withQueryValue($url, $name, $value);
     }
     //---
     $request = new Request('GET', $url, $this->buildHeaders());
     try {
         $response = $this->getHttpClient()->sendRequest($request);
     } catch (\RuntimeException $e) {
         throw new Exception\NotifyException($e->getMessage(), $e->getCode(), $e);
     }
     //---
     switch ($response->getStatusCode()) {
         case 200:
             return $this->handleResponse($response);
         case 404:
             return null;
         default:
             return $this->handleErrorResponse($response);
     }
 }
开发者ID:alphagov,项目名称:notifications-php-client,代码行数:32,代码来源:Client.php


注:本文中的URI::withQueryValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。