本文整理汇总了PHP中Guzzle\Http\Client::patch方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::patch方法的具体用法?PHP Client::patch怎么用?PHP Client::patch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Client
的用法示例。
在下文中一共展示了Client::patch方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: patchDoctorService
/**
* @param int $facilityId
* @param int $doctorId
* @param DoctorService $doctorService
*
* @return DoctorService
*/
public function patchDoctorService($facilityId, $doctorId, $doctorService)
{
$request = $this->client->patch(['facilities/{facilityId}/doctors/{doctorId}/services/{doctorServiceId}', ['facilityId' => $facilityId, 'doctorId' => $doctorId, 'doctorServiceId' => $doctorService->getId()]], [], $this->serializer->serialize($doctorService, 'json', SerializationContext::create()->setGroups(['patch'])));
/** @var DoctorService $newDoctorService */
$newDoctorService = $this->authorizedRequest($request, DoctorService::class, DeserializationContext::create()->setGroups(['get']));
return $newDoctorService;
}
示例2: patchUser
/**
* Edit an user fields.
*
* @param int $id
* @param array $fields
*
* @return mixed
*/
public function patchUser($id, array $fields)
{
$request = $this->client->patch($this->customer['url'] . '/api/users/' . $id);
$request->setAuth($this->customer['username'], $this->customer['password']);
$request->setBody(json_encode($fields));
$response = $request->send();
return json_decode($response->getBody(true));
}
示例3: patch
function patch($endpoint, $data = array())
{
try {
$client = new Client();
$bearerAuth = new BearerAuth($this->token);
$client->addSubscriber($bearerAuth);
$request = $client->patch($this->base_url . $endpoint, array(), json_encode($data, JSON_FORCE_OBJECT));
$request->addHeader('Content-Type', 'application/json');
$response = $request->send();
return $response->json();
} catch (BearerErrorResponseException $e) {
return $e->getMessage();
} catch (BadResponseException $e) {
return $e->getMessage();
}
}
示例4: patch
/**
* Patch (partial update) an object at a set location ($path)
* @param string $path the path to post this object to.
* @param object $object the object to be posted to given path
* @param array $headers an array of headers to send with the request
* @return \DrestClient\Response $response Response object with a populated representation instance
* @throws ErrorException upon the return of any error document from the server
*/
public function patch($path, &$object, array $headers = array())
{
$representation = $this->getRepresentationInstance();
$representation->update($object);
$request = $this->transport->patch($path, $headers, $representation->__toString());
foreach ($this->getVarsFromPath($path) as $key => $value) {
$request->setPostField($key, $value);
}
$request->setHeader('Content-Type', $representation->getContentType());
try {
$response = $this->transport->send($request);
} catch (BadResponseException $exception) {
throw $this->handleErrorResponse($exception);
}
return new Response($representation, $response);
}
示例5: elseif
$app['session']->set('error', $e->getResponse()->getStatusCode() . ": " . $e->getResponse()->getReasonPhrase());
return $app->redirect('../../ui/error');
}
}
// return the response (the json or php file)
return $response;
} elseif ($app['session']->get('method') == 'get') {
$title = $title . "for getting";
$app['session']->set('userget', $formdata['Username']);
$app['session']->set('pswdget', $formdata['Password']);
} elseif ($app['session']->get('method') == 'patch') {
$title = $title . "for editing";
$app['session']->set('userpatch', $formdata['Username']);
$app['session']->set('pswdpatch', $formdata['Password']);
try {
$request = $client->patch($app['session']->get('path'), null, $app['session']->get('body'))->setAuth($formdata['Username'], $formdata['Password']);
$response = $request->send();
} catch (ClientErrorResponseException $e) {
if ($e->getResponse()->getStatusCode() == 401) {
return $app->redirect($hostname . 'ui/authentication');
} else {
$app['session']->set('error', $e->getResponse()->getStatusCode() . ": " . $e->getResponse()->getReasonPhrase());
return $app->redirect('../../ui/error');
}
}
} elseif ($app['session']->get('method') == 'put') {
$title = $title . "for putting";
$app['session']->set('userput', $formdata['Username']);
$app['session']->set('pswdput', $formdata['Password']);
try {
$request = $client->put($app['session']->get('path'), null, $app['session']->get('body'))->setAuth($formdata['Username'], $formdata['Password']);
示例6: testClientHasHelperMethodsForCreatingRequests
public function testClientHasHelperMethodsForCreatingRequests()
{
$url = $this->getServer()->getUrl();
$client = new Client($url . 'base');
$this->assertEquals('GET', $client->get()->getMethod());
$this->assertEquals('PUT', $client->put()->getMethod());
$this->assertEquals('POST', $client->post()->getMethod());
$this->assertEquals('HEAD', $client->head()->getMethod());
$this->assertEquals('DELETE', $client->delete()->getMethod());
$this->assertEquals('OPTIONS', $client->options()->getMethod());
$this->assertEquals('PATCH', $client->patch()->getMethod());
$this->assertEquals($url . 'base/abc', $client->get('abc')->getUrl());
$this->assertEquals($url . 'zxy', $client->put('/zxy')->getUrl());
$this->assertEquals($url . 'zxy?a=b', $client->post('/zxy?a=b')->getUrl());
$this->assertEquals($url . 'base?a=b', $client->head('?a=b')->getUrl());
$this->assertEquals($url . 'base?a=b', $client->delete('/base?a=b')->getUrl());
}
示例7: array
// getting the data from the form
$formdata = $form->getData();
// making array for the body of the put request
$body = array();
foreach ($parameterstobechanged as $key => $value) {
$body[$key] = $formdata[$key];
}
// initializing a new client
$client2 = new Client();
try {
$path = $hostname . "tdtadmin/resources/" . $app['session']->get('pathtoresource');
// the put request
// checking if once in a session time a username and password is given to authorise for patching
// if not, try without authentication
if ($app['session']->get('userpatch') == null || $app['session']->get('pswdpatch') == null) {
$request = $client2->patch($path, null, $body);
} else {
$request = $client2->patch($path, null, $body)->setAuth($app['session']->get('userpatch'), $app['session']->get('pswdpatch'));
}
$response = $request->send();
} catch (ClientErrorResponseException $e) {
// if tried with authentication and it failed
// or when tried without authentication and authentication is needed
if ($e->getResponse()->getStatusCode() == 401) {
// necessary information is stored in the session object, needed to redo the request after authentication
$app['session']->set('method', 'patch');
$app['session']->set('path', $path);
$app['session']->set('body', $body);
$app['session']->set('redirect', $hostname . 'ui/package');
$app['session']->set('referer', $hostname . 'ui/resource/edit');
return $app->redirect('../../ui/authentication');
示例8: executeRequest
/**
* @param Client $client
* @param string $method
* @param string $url
* @param array $parameters
* @param array $options
* @param string|null $payload
* @return \Guzzle\Http\Message\Response
* @throws \Exception
*/
protected function executeRequest(Client $client, $method, $url, array $parameters, array $options, $payload = null)
{
switch ($method) {
case 'get':
$request = $client->get($url, $parameters, $options);
break;
case 'post':
case 'upload':
$request = $client->post($url, $parameters, $payload, $options);
break;
case 'put':
$request = $client->put($url, $parameters, $payload, $options);
break;
case 'patch':
$request = $client->patch($url, $parameters, $payload, $options);
break;
case 'delete':
$request = $client->delete($url, $parameters, $payload, $options);
break;
default:
throw new \Exception('Invalid method');
break;
}
return $request->send();
}