當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Client::put方法代碼示例

本文整理匯總了PHP中GuzzleHttp\Client::put方法的典型用法代碼示例。如果您正苦於以下問題:PHP Client::put方法的具體用法?PHP Client::put怎麽用?PHP Client::put使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在GuzzleHttp\Client的用法示例。


在下文中一共展示了Client::put方法的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;
 }
開發者ID:suffrajet,項目名稱:gdoctor,代碼行數:27,代碼來源:Guzzle.php

示例2: makeHttpRequest

 function makeHttpRequest($method, $url, $apiRequest = null, $queryString = null)
 {
     $urlEndPoint = $this->apiConfiguration->getDefaultEndPoint() . '/' . $url;
     $data = ['headers' => ['Authorization' => 'Bearer ' . $this->apiConfiguration->getAccessToken()], 'json' => $apiRequest, 'query' => $queryString];
     try {
         switch ($method) {
             case 'post':
                 $response = $this->guzzle->post($urlEndPoint, $data);
                 break;
             case 'put':
                 $response = $this->guzzle->put($urlEndPoint, $data);
                 break;
             case 'delete':
                 $response = $this->guzzle->delete($urlEndPoint, $data);
                 break;
             case 'get':
                 $response = $this->guzzle->get($urlEndPoint, $data);
                 break;
             default:
                 throw new \Exception('Missing request method!');
         }
         if (in_array(current($response->getHeader('Content-Type')), ['image/png', 'image/jpg'])) {
             $result = $response->getBody()->getContents();
         } else {
             $result = json_decode($response->getBody(), true);
         }
         return $result;
     } catch (ConnectException $c) {
         throw $c;
     } catch (RequestException $e) {
         throw $e;
     }
 }
開發者ID:turboship,項目名稱:api-php,代碼行數:33,代碼來源:HttpRequest.php

示例3: post

 /**
  * Make a post request to shorte.st.
  *
  * @param $url_to_shorten
  *
  * @return \GuzzleHttp\Stream\StreamInterface|null|\Psr\Http\Message\StreamInterface
  */
 private function post($url_to_shorten)
 {
     // Prepare the request.
     $request = $this->client->put(Shortest::BASE_URL, ['headers' => ['public-api-token' => $this->config->get('shortest.api_token')], 'form_params' => ['urlToShorten' => $url_to_shorten]]);
     // Return the body as json.
     return $request->getBody();
 }
開發者ID:appsketch,項目名稱:shorte.st,代碼行數:14,代碼來源:Shortest.php

示例4: put

 public function put($resource, $body, $type, $options = [])
 {
     $options['body'] = $this->serializer->serialize($body, 'json');
     $options['headers'] = ['Content-Type' => 'application/json'];
     $content = $this->client->put($resource, $options)->getBody()->getContents();
     return $this->deserialize($content, $type);
 }
開發者ID:italolelis,項目名稱:wunderlist,代碼行數:7,代碼來源:GuzzleAdapter.php

示例5: updateObject

 public function updateObject($object, ChangeSet $changeSet)
 {
     $data = $this->prepareUpdateChangeSet($object, $changeSet);
     $identifier = $this->getObjectIdentifier($object);
     $class = $this->objectManager->getClassMetadata(get_class($object));
     $url = sprintf('%s/%s', $this->url, $identifier[$class->identifier[0]]);
     return $this->client->put($url, array('body' => $data))->json();
 }
開發者ID:basuritas-php,項目名稱:skeleton-mapper,代碼行數:8,代碼來源:HttpObjectPersister.php

示例6: testUpdateSchedule

 public function testUpdateSchedule()
 {
     $response = self::$client->put('/');
     $updatedSchedule = Schedule::create($response->json());
     $this->assertInstanceOf('Ctct\\Components\\EmailMarketing\\Schedule', $updatedSchedule);
     $this->assertEquals(1, $updatedSchedule->id);
     $this->assertEquals("2012-12-16T11:07:43.626Z", $updatedSchedule->scheduled_date);
 }
開發者ID:GafaMX,項目名稱:dev_funciones_basicas,代碼行數:8,代碼來源:CampaignScheduleServiceUnitTest.php

示例7: run

 /**
  * @param string $testId
  * @return int result_id
  */
 public function run($testId)
 {
     $url = sprintf(static::API_BASE_URL . '/tests/%s/run', $testId);
     $response = $this->client->put($url);
     if (empty($response->getBody())) {
         return null;
     }
     return $response->json(['object' => true])->result_id;
 }
開發者ID:shin1x1,項目名稱:loaderio-runner,代碼行數:13,代碼來源:Client.php

示例8: testUpdateList

 public function testUpdateList()
 {
     $response = self::$client->put('/');
     $list = ContactList::create($response->json());
     $this->assertInstanceOf('Ctct\\Components\\Contacts\\ContactList', $list);
     $this->assertEquals(6, $list->id);
     $this->assertEquals("Test List 4", $list->name);
     $this->assertEquals("HIDDEN", $list->status);
     $this->assertEquals(19, $list->contact_count);
 }
開發者ID:GafaMX,項目名稱:dev_funciones_basicas,代碼行數:10,代碼來源:ListServiceUnitTest.php

示例9: shouldRespondToMultipleRequestsWithTheSameResponse

 /** @test */
 public function shouldRespondToMultipleRequestsWithTheSameResponse()
 {
     $mockResponse = $this->createResponse(new Response(200, ['Content-Type' => 'application/json'], Stream::factory(json_encode(['hello' => 'world', 'howareyou' => 'today']))));
     $this->httpMock->shouldReceiveRequest()->once()->withUrl('http://example.com/foo')->withMethod('PUT')->withQueryParams(['faz' => 'baz'])->withJsonBodyParams(['shakeyo' => 'body'])->andRespondWith($mockResponse);
     $this->httpMock->shouldReceiveRequest()->once()->withUrl('http://example.com/foo')->withMethod('PUT')->withQueryParams(['faz' => 'baz'])->withJsonBodyParams(['shakeyo' => 'hands in the air like you just don\'t care'])->andRespondWith($mockResponse);
     $actualResponse = $this->guzzleClient->put('http://example.com/foo', ['query' => ['faz' => 'baz'], 'body' => json_encode(['shakeyo' => 'body']), 'headers' => ['Content-Type' => 'application/json']]);
     $actualResponse2 = $this->guzzleClient->put('http://example.com/foo', ['query' => ['faz' => 'baz'], 'body' => json_encode(['shakeyo' => 'hands in the air like you just don\'t care']), 'headers' => ['Content-Type' => 'application/json']]);
     $this->httpMock->verify();
     $this->assertSame($mockResponse, $actualResponse);
     $this->assertSame($mockResponse, $actualResponse2);
 }
開發者ID:lezhnev74,項目名稱:GuzzleHttpMock,代碼行數:12,代碼來源:MockTest.php

示例10: put

 public function put($resource, $body, $type, $options = [])
 {
     $options['future'] = true;
     $options['body'] = $this->serializer->serialize($body, 'json');
     $options['headers'] = ['Content-Type' => 'application/json'];
     return $this->client->put($resource, $options)->then(function (Response $reponse) {
         return $reponse->getBody()->getContents();
     })->then(function ($content) use($type) {
         return $this->deserialize($content, $type);
     });
 }
開發者ID:italolelis,項目名稱:wunderlist,代碼行數:11,代碼來源:AsyncGuzzleAdapter.php

示例11: 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"));
 }
開發者ID:royopa,項目名稱:guzzle-cache-middleware,代碼行數:15,代碼來源:BaseTest.php

示例12: 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));
 }
開發者ID:kevinrob,項目名稱:guzzle-cache-middleware,代碼行數:15,代碼來源:BaseTest.php

示例13: makeRequest

 public static function makeRequest($request, $url, $getRawResponse = false)
 {
     $client = new Client();
     switch ($request->getActionType()) {
         case ActionType::GET:
             if ($getRawResponse) {
                 return $client->get($url);
             } else {
                 $response = GuzzleHelper::getAsset($url);
                 //$client->get($url);
             }
             break;
         case ActionType::DELETE:
             $response = $client->delete($url);
             break;
         case ActionType::PUT:
             $response = $client->put($url);
             break;
         case ActionType::POST:
             $response = $client->post($url);
             break;
         default:
             $response = GuzzleHelper::getAsset($url);
             //$client->get($url);
     }
     return $response;
 }
開發者ID:Poornimagaurav,項目名稱:delphinium,代碼行數:27,代碼來源:GuzzleHelper.php

示例14: put

 public static function put($url, $data)
 {
     $result = [];
     $client = new Client();
     try {
         $response = $client->put($url, ['body' => json_encode($data)]);
         $result = $response->getBody();
         if ($result->isReadable()) {
             return $result->__toString();
         } else {
             return null;
         }
     } catch (\GuzzleHttp\Exception\ClientErrorResponseException $e) {
         //$resp              = $e->getResponse();
         return null;
     } catch (\GuzzleHttp\Exception\ServerErrorResponseException $e) {
         return null;
     } catch (\GuzzleHttp\Exception\BadResponseException $e) {
         return null;
     } catch (\GuzzleHttp\Exception\ClientException $e) {
         return null;
     } catch (Exception $e) {
         return null;
     }
 }
開發者ID:mediakreasi,項目名稱:api,代碼行數:25,代碼來源:Connection.php

示例15: testStreamAttributeKeepsStreamOpen

 public function testStreamAttributeKeepsStreamOpen()
 {
     Server::flush();
     Server::enqueue("HTTP/1.1 200 OK\r\nFoo: Bar\r\nContent-Length: 8\r\n\r\nhi there");
     $client = new Client(['base_url' => Server::$url, 'adapter' => new StreamAdapter(new MessageFactory())]);
     $response = $client->put('/foo', ['headers' => ['Foo' => 'Bar'], 'body' => 'test', 'stream' => true]);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals('OK', $response->getReasonPhrase());
     $this->assertEquals('8', $response->getHeader('Content-Length'));
     $body = $response->getBody();
     if (defined('HHVM_VERSION')) {
         $this->markTestIncomplete('HHVM has not implemented this?');
     }
     $this->assertEquals('http', $body->getMetadata()['wrapper_type']);
     $this->assertEquals(8, $body->getMetadata()['unread_bytes']);
     $this->assertEquals(Server::$url . 'foo', $body->getMetadata()['uri']);
     $this->assertEquals('hi', $body->read(2));
     $body->close();
     $sent = Server::received(true)[0];
     $this->assertEquals('PUT', $sent->getMethod());
     $this->assertEquals('/foo', $sent->getResource());
     $this->assertEquals('127.0.0.1:8125', $sent->getHeader('host'));
     $this->assertEquals('Bar', $sent->getHeader('foo'));
     $this->assertTrue($sent->hasHeader('user-agent'));
 }
開發者ID:davidsoloman,項目名稱:drupalconsole.com,代碼行數:25,代碼來源:StreamAdapterTest.php


注:本文中的GuzzleHttp\Client::put方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。