當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。