本文整理汇总了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);
}
示例2: testPathMustBeValid
/**
* @expectedException \InvalidArgumentException
*/
public function testPathMustBeValid()
{
$uri = new Uri('');
$uri->withPath(array());
}