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


PHP Uri::withPath方法代码示例

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


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

示例1: execute

 /**
  * @param array $params {
  *      @var string             $resource Flora resource
  *      @var int|string         $id             optional    Unique item identifier
  *      @var string             $format         optional    Output format (default json)
  *      @var string             $action         optional    API action (default: retrieve)
  *      @var string             $select         optional    Retrieve only specified attributes
  *      @var string             $filter         optional    Filter items by criteria
  *      @var int                $limit          optional    Limit result set
  *      @var int                $page           optional    Paginate through result set
  *      @var string             $search         optional    Search items by full-text search
  *      @var bool               $cache          optional    En-/disable caching (default: true)
  *      @var bool               $authenticate   optional    Use authentication provider to add some authentication information to request
  *      @var string             $httpMethod     optional    Explicitly set/override HTTP (GET, POST,...) method
  *      @var array|\stdClass    $data           optional    Send $data as JSON
  * }
  * @return \stdClass
  * @throws \Flora\Exception
  */
 public function execute(array $params)
 {
     if (!isset($params['resource']) || empty($params['resource'])) {
         throw new Exception('Resource must be set');
     }
     $uri = $this->uri->withPath($this->getPath($params));
     foreach (['resource', 'id', 'format'] as $param) {
         // remove path params from request params
         if (isset($params[$param])) {
             unset($params[$param]);
         }
     }
     if (array_key_exists('cache', $params)) {
         if ((bool) $params['cache'] === false) {
             $params['_'] = time();
         }
         unset($params['cache']);
     }
     if (isset($params['action']) && $params['action'] == 'retrieve') {
         unset($params['action']);
     }
     $httpMethod = $this->getHttpMethod($params);
     $request = new Request($httpMethod, $uri, ['Referer' => $this->getCurrentUri()]);
     if (isset($params['authenticate'])) {
         if ((bool) $params['authenticate']) {
             if ($this->authProvider === null) {
                 throw new Exception('Authentication provider is not configured');
             }
             $request = $this->authProvider->authenticate($request);
         }
         unset($params['authenticate']);
     }
     if (!empty($this->defaultParams)) {
         $params = array_merge($this->defaultParams, $params);
     }
     if (!empty($params)) {
         $request = $this->applyParameters($request, $params);
     }
     try {
         $response = $this->httpClient->send($request, $this->httpOptions);
     } catch (RequestException $e) {
         throw new Exception($e->getMessage());
     }
     $result = $response->getBody();
     $contentType = $response->getHeaderLine('Content-Type');
     if (strpos($contentType, 'application/json') !== false) {
         $result = json_decode($result);
     }
     $statusCode = $response->getStatusCode();
     if ($statusCode < 400) {
         return $result;
     }
     $this->throwError($statusCode, $result->error);
 }
开发者ID:godmodelabs,项目名称:flora-client-php,代码行数:73,代码来源:Client.php

示例2: testPathMustBeValid

 /**
  * @expectedException \InvalidArgumentException
  */
 public function testPathMustBeValid()
 {
     $uri = new Uri('');
     $uri->withPath(array());
 }
开发者ID:kirill-konshin,项目名称:psr7,代码行数:8,代码来源:UriTest.php


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