本文整理汇总了PHP中Guzzle\Service\Client::setDescription方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::setDescription方法的具体用法?PHP Client::setDescription怎么用?PHP Client::setDescription使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Service\Client
的用法示例。
在下文中一共展示了Client::setDescription方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor
*
* @param string $accessToken
*/
public function __construct($accessToken)
{
$this->accessToken = $accessToken;
$this->client = new Client();
$this->client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/config/service.json'));
$this->client->getEventDispatcher()->addListener('client.create_request', [$this, 'onClientCreateRequest']);
$this->client->getEventDispatcher()->addListener('request.error', [$this, 'onRequestError']);
}
示例2: __construct
/**
* Initializes initializer
*
* @param Client $client
* @param array $parameters
*/
public function __construct(Client $client, array $parameters)
{
$this->client = $client;
$this->parameters = $parameters;
if (!empty($parameters['service_descriptions'])) {
$this->client->setDescription(ServiceDescription::factory($parameters['service_descriptions']));
}
}
示例3: __construct
public function __construct($request_options)
{
$description = ServiceDescription::factory(__DIR__ . "/../../clients/index.json");
$this->client = new Client($request_options['base_url']);
$this->client->setDescription($description);
$this->client->setConfig($request_options);
$tokenPlugin = new \Gitlab\Auth\Token\Plugin($this, $request_options);
$urlEncoder = new \Gitlab\Core\Plugin\UrlEncoder();
$this->client->addSubscriber($tokenPlugin);
$this->client->addSubscriber($urlEncoder);
}
示例4: getClient
protected function getClient()
{
$service = ServiceDescription::factory(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'TestData' . DIRECTORY_SEPARATOR . 'test_service.xml');
$client = new Client('http://www.google.com/');
$client->setDescription($service);
return $client;
}
示例5: testClientConstruct
/**
* @return Client
*/
public function testClientConstruct()
{
// Define a service with a test() method
$service = new ServiceDescription(array('name' => 'test-service', 'operations' => array('test' => array('uri' => '/test.json', 'httpMethod' => 'GET', 'responseClass' => 'TestModel', 'class' => '\\Loco\\Utils\\Swizzle\\Command\\StrictCommand'), 'testlist' => array('uri' => '/testlist.json', 'httpMethod' => 'GET', 'responseClass' => 'array', 'class' => '\\Loco\\Utils\\Swizzle\\Command\\StrictCommand', 'items' => array('$ref' => 'TestModel')), 'testwrap' => array('uri' => '/testwrap.json', 'httpMethod' => 'GET', 'responseClass' => 'TestModelList', 'class' => '\\Loco\\Utils\\Swizzle\\Command\\StrictCommand'), 'testwrapobj' => array('uri' => '/testwrapobj.json', 'httpMethod' => 'GET', 'responseClass' => 'TestModelListObject', 'class' => '\\Loco\\Utils\\Swizzle\\Command\\StrictCommand')), 'models' => array('TestModel' => array('type' => 'object', 'additionalProperties' => false, 'properties' => array('foo' => array('type' => 'integer', 'location' => 'json', 'required' => true), 'bar' => array('type' => 'integer', 'location' => 'json', 'required' => false))), 'TestModelList' => array('type' => 'array', 'items' => array('$ref' => 'TestModel')), 'TestModelListObject' => array('type' => 'object', 'additionalProperties' => false, 'properties' => array('list' => array('type' => 'array', 'location' => 'json', 'items' => array('$ref' => 'TestModel')))))));
$client = new Client();
$client->setDescription($service);
// test models are defined ok
$op = $service->getOperation('test');
$this->assertEquals('model', $op->getResponseType());
$this->assertEquals('TestModel', $op->getResponseClass());
// listing is just an array
$op = $service->getOperation('testlist');
$this->assertEquals('primitive', $op->getResponseType());
$this->assertEquals('array', $op->getResponseClass());
// test listing is aware of models in itself
// It's not. Operation has no 'items' property
// list wrapper is a model
$op = $service->getOperation('testwrap');
$this->assertEquals('model', $op->getResponseType());
$this->assertEquals('TestModelList', $op->getResponseClass());
// test model resolved from $ref
$listModel = $service->getModel('TestModelList');
$this->assertInstanceOf('\\Guzzle\\Service\\Description\\Parameter', $listModel);
// items should be single schema specifying one allowed model type
$items = $listModel->getItems();
$this->assertInstanceOf('\\Guzzle\\Service\\Description\\Parameter', $items);
$this->assertEquals('object', $items->getType());
$this->assertArrayHasKey('foo', $items->getProperties());
return $client;
}
示例6: getClient
protected function getClient()
{
$description = new ServiceDescription(array('operations' => array('test' => array('httpMethod' => 'PUT', 'parameters' => array('ContentMD5' => array(), 'Body' => array('location' => 'body'))))));
$client = new Client();
$client->setDescription($description);
return $client;
}
示例7: testClientConstruct
/**
* Construct Swagger client for calling the petstore
* @depends testServiceBuild
* @return Client
*/
public function testClientConstruct(ServiceDescription $service)
{
$client = new Client();
$client->setDescription($service);
$this->assertEquals('http://petstore.swagger.wordnik.com/api', $client->getBaseUrl());
// @todo add Accept: application/json to every request?
return $client;
}
示例8: testAllowsForJsonBasedArrayParamsFunctionalTest
public function testAllowsForJsonBasedArrayParamsFunctionalTest()
{
$description = new ServiceDescription(array('operations' => array('test' => new Operation(array('httpMethod' => 'PUT', 'parameters' => array('data' => array('required' => true, 'filters' => 'json_encode', 'location' => 'body')))))));
$client = new Client();
$client->setDescription($description);
$command = $client->getCommand('test', array('data' => array('foo' => 'bar')));
$request = $command->prepare();
$this->assertEquals('{"foo":"bar"}', (string) $request->getBody());
}
示例9: testAllowsForJsonBasedArrayParamsFunctionalTest
public function testAllowsForJsonBasedArrayParamsFunctionalTest()
{
$service = array('test' => new ApiCommand(array('method' => 'PUT', 'params' => array('data' => array('required' => true, 'type' => 'type:array', 'filters' => 'json_encode', 'location' => 'body')))));
$description = new ServiceDescription($service);
$client = new Client();
$client->setDescription($description);
$command = $client->getCommand('test', array('data' => array('foo' => 'bar')));
$request = $command->prepare();
$this->assertEquals(json_encode(array('foo' => 'bar')), (string) $request->getBody());
}
示例10: createEchaleGasClient
public function createEchaleGasClient()
{
$client = new Client();
$client->setDescription(ServiceDescription::factory('config/services/echalegas.json'));
$logger = new Logger('debug');
$logger->pushHandler(new StreamHandler('logs/debug.log'));
$logPlugin = new LogPlugin(new MonologLogAdapter($logger), MessageFormatter::DEBUG_FORMAT);
$client->addSubscriber($logPlugin);
return $client;
}
示例11: getMockedClient
protected function getMockedClient(Response $response)
{
$operation = new Operation(array('httpMethod' => 'GET', 'name' => 'Mock'));
$service = new ServiceDescription();
$service->addOperation($operation);
$plugin = new MockPlugin();
$plugin->addResponse($response);
$client = new Client();
$client->setDescription($service);
$client->addSubscriber($plugin);
return $client;
}
示例12: testValidatesAdditionalParameters
public function testValidatesAdditionalParameters()
{
$description = ServiceDescription::factory(array('operations' => array('foo' => array('httpMethod' => 'PUT', 'parameters' => array('bar' => array('location' => 'header')), 'additionalParameters' => array('location' => 'json')))));
$client = new Client();
$client->setDescription($description);
$command = $client->getCommand('foo');
$command['bar'] = 'test';
$command['hello'] = 'abc';
$request = $command->prepare();
$this->assertEquals('test', (string) $request->getHeader('bar'));
$this->assertEquals('{"hello":"abc"}', (string) $request->getBody());
}
示例13: testVisitsLocationWithMultipleFiles
public function testVisitsLocationWithMultipleFiles()
{
$description = ServiceDescription::factory(array('operations' => array('DoPost' => array('httpMethod' => 'POST', 'parameters' => array('foo' => array('location' => 'postFile', 'type' => array('string', 'array')))))));
$this->getServer()->flush();
$this->getServer()->enqueue(array("HTTP/1.1 200 OK\r\nContent-Length:0\r\n\r\n"));
$client = new Client($this->getServer()->getUrl());
$client->setDescription($description);
$command = $client->getCommand('DoPost', array('foo' => array(__FILE__, __FILE__)));
$command->execute();
$received = $this->getServer()->getReceivedRequests();
$this->assertContains('name="foo[0]";', $received[0]);
$this->assertContains('name="foo[1]";', $received[0]);
}
示例14: testUsesProcessedModelsWhenEnabled
public function testUsesProcessedModelsWhenEnabled()
{
$d = ServiceDescription::factory(array('operations' => array('foobar' => array('name' => 'foobar', 'httpMethod' => 'PUT', 'responseClass' => 'foo', 'responseType' => 'model', 'class' => 'Aws\\Common\\Command\\JsonCommand', 'parameters' => array('test' => array('location' => 'query')))), 'models' => array('foo' => array('type' => 'object', 'properties' => array('test' => array('type' => 'string', 'location' => 'json', 'filters' => array('strtoupper')))))));
$response = new Response(200, array('Content-Type' => 'application/json'), '{"test":"bar"}');
$client = new Client('http://localhost:1245');
$client->setDescription($d);
$this->setMockResponse($client, array($response));
$command = $client->getCommand('foobar');
$this->assertEquals(array('test' => 'bar'), $command->execute()->toArray());
$this->setMockResponse($client, array($response));
$command = $client->getCommand('foobar');
$command->set('command.model_processing', true);
$this->assertEquals(array('test' => 'BAR'), $command->execute()->toArray());
}
示例15: testSupportsServiceDescriptionBaseUrls
public function testSupportsServiceDescriptionBaseUrls()
{
$description = new ServiceDescription(array('baseUrl' => 'http://foo.com'));
$client = new Client();
$client->setDescription($description);
$this->assertEquals('http://foo.com', $client->getBaseUrl());
}