本文整理汇总了PHP中GuzzleHttp\Client::patch方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::patch方法的具体用法?PHP Client::patch怎么用?PHP Client::patch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GuzzleHttp\Client
的用法示例。
在下文中一共展示了Client::patch方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getResponse
private function getResponse($stack, $base_uri, $uri, $data, $httpMethod)
{
$middleware = new Oauth1(['consumer_key' => self::CONSUMER_KEY, 'consumer_secret' => self::CONSUMER_SECRET, 'token_secret' => self::TOKEN_SECRET]);
//'auth' => ['user_name', 'pass_name'], // when using username & password
$options = ['auth' => 'oauth', 'debug' => false, 'headers' => ['Accept' => 'application/hal+json', 'Content-Type' => 'application/hal+json'], 'body' => json_encode($data)];
$stack->push($middleware);
$client = new Client(['base_uri' => $base_uri, 'handler' => $stack]);
$response = false;
switch ($httpMethod) {
case self::HTTP_GET:
$response = $client->get($uri, $options);
break;
case self::HTTP_POST:
$response = $client->post($uri, $options);
break;
case self::HTTP_PUT:
$response = $client->put($uri, $options);
break;
case self::HTTP_PATCH:
$response = $client->patch($uri, $options);
break;
case self::HTTP_DELETE:
$response = $client->delete($uri, $options);
break;
}
return $response;
}
示例2: patch
/**
* @param string $url
* @param array $options
* @throws GuzzleException
* @return Response
*/
public function patch($url, array $options = [])
{
if (strpos($url, 'http') !== 0) {
$url = $this->baseUrl . '/' . $this->collection . '/' . ltrim($url, '/');
}
return new Response($this, $this->client->patch($url, $options));
}
示例3: patch
public function patch($resource, $data, $type, $options = [])
{
$options['json'] = $data;
$options['headers'] = ['Content-Type' => 'application/json'];
$content = $this->client->patch($resource, $options)->getBody()->getContents();
return $this->deserialize($content, $type);
}
示例4: patch
public function patch($resource, $data, $type, $options = [])
{
$options['future'] = true;
$options['json'] = $data;
$options['headers'] = ['Content-Type' => 'application/json'];
return $this->client->patch($resource, $options)->then(function (Response $reponse) {
return $reponse->getBody()->getContents();
})->then(function ($content) use($type) {
return $this->deserialize($content, $type);
});
}
示例5: testNoCacheOtherMethod
public function testNoCacheOtherMethod()
{
$this->client->post("anything");
$response = $this->client->post("anything");
$this->assertEquals("", $response->getHeaderLine("X-Cache"));
$this->client->put("anything");
$response = $this->client->put("anything");
$this->assertEquals("", $response->getHeaderLine("X-Cache"));
$this->client->delete("anything");
$response = $this->client->delete("anything");
$this->assertEquals("", $response->getHeaderLine("X-Cache"));
$this->client->patch("anything");
$response = $this->client->patch("anything");
$this->assertEquals("", $response->getHeaderLine("X-Cache"));
}
示例6: testNoCacheOtherMethod
public function testNoCacheOtherMethod()
{
$this->client->post('anything');
$response = $this->client->post('anything');
$this->assertEquals(CacheMiddleware::HEADER_CACHE_MISS, $response->getHeaderLine(CacheMiddleware::HEADER_CACHE_INFO));
$this->client->put('anything');
$response = $this->client->put('anything');
$this->assertEquals(CacheMiddleware::HEADER_CACHE_MISS, $response->getHeaderLine(CacheMiddleware::HEADER_CACHE_INFO));
$this->client->delete('anything');
$response = $this->client->delete('anything');
$this->assertEquals(CacheMiddleware::HEADER_CACHE_MISS, $response->getHeaderLine(CacheMiddleware::HEADER_CACHE_INFO));
$this->client->patch('anything');
$response = $this->client->patch('anything');
$this->assertEquals(CacheMiddleware::HEADER_CACHE_MISS, $response->getHeaderLine(CacheMiddleware::HEADER_CACHE_INFO));
}
示例7: handle
/**
* Send Rename request to slave
*
*/
public function handle()
{
$client = new Client();
try {
$response = $client->patch($this->slave . ApiUrl::$rename . '/' . $this->from . '/' . $this->to . '?token=' . getMasterPassword());
} catch (\Exception $e) {
}
}
示例8: patch
/**
* @param string $uri
* @param array $data
* @param array $options
* @param bool $api
* @return $this;
*/
public function patch($uri, array $data = [], array $options = [], $api = true)
{
$options = $this->configureOptions($options);
$uri = $api ? $this->getServiceConfig('api_url') . $uri : $uri;
$response = $this->client->patch($uri, array_merge($options, ['form_params' => $data]));
$this->setGuzzleResponse($response);
return $this;
}
示例9: disableEmailObfuscation
private function disableEmailObfuscation()
{
try {
$response = $this->client->patch('zones/' . $this->zoneId . '/settings/email_obfuscation', ['json' => ['value' => 'off']]);
return $response->json(['object' => true])->result;
} catch (Exception $e) {
throw $this->createCloudflareException($e);
}
}
示例10: patch
/**
* @param $url
* @param $version
* @param array $data
* @param string $bodyEncoding
*
* @return \GuzzleHttp\Message\FutureResponse|\GuzzleHttp\Message\ResponseInterface|\GuzzleHttp\Ring\Future\FutureInterface|null
*/
private function patch($url, $version, array $data = [], $bodyEncoding = 'json')
{
$requestOptions = $this->getPostRequestOptions($version, $data, $bodyEncoding);
$response = $this->client->patch($url, $requestOptions);
if (200 !== $response->getStatusCode()) {
throw new \LogicException('An error occurred when trying to POST data to MR API');
}
return $response;
}
示例11: patch
/**
* @param string $path
* @param array $options
*
* @throws ClientException
*
* @return string
*/
public function patch($path, array $options = [])
{
$options = array_merge($this->options, $options);
try {
/** @var Response $result */
$result = $this->guzzle->patch($path, $options);
} catch (RequestException $requestException) {
throw new ClientException('Could not update.', 0, $requestException);
}
return $result->getBody()->getContents();
}
示例12: patch
public function patch($uri, array $body)
{
$this->lastRequestBody = $body;
try {
$this->lastResponse = $this->client->patch($uri, ['json' => $body, 'headers' => $this->headers]);
} catch (RequestException $e) {
$this->lastResponse = $e->getResponse();
} finally {
$this->lastResponseBody = $this->lastResponse->getBody()->getContents();
}
}
示例13: completeTask
/**
* Completes a task
*
* @param int $taskId
* @param int $revision
*
* @return array
*/
public function completeTask($taskId, $revision)
{
if (!is_numeric($taskId)) {
throw new \InvalidArgumentException('The list id must be numeric');
} elseif (!is_numeric($revision)) {
throw new \InvalidArgumentException('The revision must be numeric');
}
$response = $this->guzzle->patch('tasks/' . $taskId, ['body' => json_encode(['revision' => (int) $revision, 'completed' => true])]);
$this->checkResponseStatusCode($response, 200);
return json_decode($response->getBody(), true);
}
示例14: rename
/**
* Modify the name of a remote `Node`.
*
* @param string $name
*
* @return array
*/
public function rename($name)
{
$retval = ['success' => false, 'data' => []];
$response = self::$httpClient->patch(self::$account->getMetadataUrl() . "nodes/{$this['id']}", ['headers' => ['Authorization' => 'Bearer ' . self::$account->getToken()['access_token']], 'json' => ['name' => $name], 'exceptions' => false]);
$retval['data'] = json_decode((string) $response->getBody(), true);
if ($response->getStatusCode() === 200) {
$retval['success'] = true;
$this->replace($retval['data']);
$this->save();
}
return $retval;
}
示例15: method
private function method($object, $url, $name = 'post', $args = null)
{
try {
if (is_array($args)) {
$url = array($url, $args);
}
switch ($name) {
case 'post':
$response = $this->client->post($url, array('body' => $this->object[$object]));
break;
case 'patch':
$response = $this->client->patch($url, array('body' => $this->object[$object]));
break;
default:
throw new \Exception("Method isn't defined");
}
//Fetch recent created record
$this->object_created[$object] = $this->client->get($response->getHeader('location'))->json();
} catch (ClientException $e) {
var_dump($e->getResponse()->json());
\PHPUnit_Framework_TestCase::fail('CLIENT: ' . $e->getMessage());
}
}