1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-25 02:22:57 +01:00

[Service] Adding result_type, result_doc, and deprecated to service description commands. Changing most default values of command date to null instead of an empty string.

This commit is contained in:
Michael Dowling 2012-06-06 17:06:16 -07:00
parent ebaff511f7
commit 7370ad44ca
2 changed files with 103 additions and 40 deletions

View File

@ -53,6 +53,21 @@ class ApiCommand
*/
protected $class;
/**
* @var string Result type generated by the command
*/
protected $resultType;
/**
* @var string Result type generated by the command
*/
protected $resultDoc;
/**
* @var bool Whether or not the command is deprecated
*/
protected $deprecated;
/**
* @var array Cache of parsed Command class ApiCommands
*/
@ -62,40 +77,46 @@ class ApiCommand
* Constructor
*
* @param array $config Array of configuration data using the following keys
* - name: Name of the command
* - doc: Method documentation
* - method: HTTP method of the command
* - uri: URI routing information of the command
* - class: Concrete class that implements this command
* - params: Associative array of parameters for the command with each
* parameter containing the following keys:
* - name: Parameter name
* - type: Type of variable (boolean, integer, string,
* array, class name, etc...)
* - type_args: Argument(s) to pass to the type validation
* - required: Whether or not the parameter is required
* - default: Default value
* - doc: Documentation
* - min_length: Minimum length
* - max_length: Maximum length
* - location: One of query, path, header, or body
* - location_key: Location key mapping value (e.g. query string value name)
* - static: Whether or not the param can be changed
* from this value
* - prepend: Text to prepend when adding this value
* - append: Text to append when adding this value
* - filters: Comma separated list of filters to run the
* value through. Must be a callable. Can
* call static class methods by separating the
* class and function with ::.
* - name: Name of the command
* - doc: Method documentation
* - method: HTTP method of the command
* - uri: URI routing information of the command
* - class: Concrete class that implements this command
* - result_type: Optional string containing the type of result created by the command
* - result_doc: Optional string containing the description of the result
* - deprecated: Set to true if this is a deprecated command
* - params: Associative array of parameters for the command with each
* parameter containing the following keys:
* - name: Parameter name
* - type: Type of variable (boolean, integer, string,
* array, class name, etc...)
* - type_args: Argument(s) to pass to the type validation
* - required: Whether or not the parameter is required
* - default: Default value
* - doc: Documentation
* - min_length: Minimum length
* - max_length: Maximum length
* - location: One of query, path, header, or body
* - location_key: Location key mapping value (e.g. query string value name)
* - static: Whether or not the param can be changed
* from this value
* - prepend: Text to prepend when adding this value
* - append: Text to append when adding this value
* - filters: Comma separated list of filters to run the
* value through. Must be a callable. Can
* call static class methods by separating the
* class and function with ::.
*/
public function __construct(array $config)
{
$this->name = isset($config['name']) ? trim($config['name']) : '';
$this->doc = isset($config['doc']) ? trim($config['doc']) : '';
$this->method = isset($config['method']) ? trim($config['method']) : '';
$this->name = isset($config['name']) ? trim($config['name']) : null;
$this->doc = isset($config['doc']) ? trim($config['doc']) : null;
$this->method = isset($config['method']) ? trim($config['method']) : null;
$this->uri = isset($config['uri']) ? trim($config['uri']) : '';
$this->class = isset($config['class']) ? trim($config['class']) : self::DEFAULT_COMMAND_CLASS;
$this->resultType = isset($config['result_type']) ? $config['result_type'] : null;
$this->resultDoc = isset($config['result_doc']) ? $config['result_doc'] : null;
$this->deprecated = isset($config['deprecated']) && ($config['deprecated'] === 'true' || $config['deprecated'] === true);
if (!empty($config['params'])) {
foreach ($config['params'] as $name => $param) {
@ -173,12 +194,15 @@ class ApiCommand
public function toArray()
{
return array(
'name' => $this->name,
'doc' => $this->doc,
'method' => $this->method,
'uri' => $this->uri,
'class' => $this->class,
'params' => $this->params
'name' => $this->name,
'doc' => $this->doc,
'method' => $this->method,
'uri' => $this->uri,
'class' => $this->class,
'params' => $this->params,
'result_type' => $this->resultType,
'result_doc' => $this->resultDoc,
'deprecated' => $this->deprecated
);
}
@ -207,7 +231,7 @@ class ApiCommand
/**
* Get the HTTP method of the command
*
* @return string
* @return string|null
*/
public function getMethod()
{
@ -227,7 +251,7 @@ class ApiCommand
/**
* Get the name of the command
*
* @return string
* @return string|null
*/
public function getName()
{
@ -237,13 +261,43 @@ class ApiCommand
/**
* Get the documentation for the command
*
* @return string
* @return string|null
*/
public function getDoc()
{
return $this->doc;
}
/**
* Get the type of data stored in the result of the command
*
* @return string|null
*/
public function getResultType()
{
return $this->resultType;
}
/**
* Get the documentation specific to the result of the command
*
* @return string|null
*/
public function getResultDoc()
{
return $this->resultDoc;
}
/**
* Get whether or not the command is deprecated
*
* @return bool
*/
public function isDeprecated()
{
return $this->deprecated;
}
/**
* Get the URI that will be merged into the generated request
*

View File

@ -39,6 +39,9 @@ class ApiCommandTest extends \Guzzle\Tests\GuzzleTestCase
'doc' => 'doc',
'method' => 'POST',
'uri' => '/api/v1',
'result_type' => 'array',
'result_doc' => 'returns the json_decoded response',
'deprecated' => true,
'params' => array(
'key' => array(
'required' => 'true',
@ -57,6 +60,9 @@ class ApiCommandTest extends \Guzzle\Tests\GuzzleTestCase
$this->assertEquals('doc', $c->getDoc());
$this->assertEquals('POST', $c->getMethod());
$this->assertEquals('/api/v1', $c->getUri());
$this->assertEquals('array', $c->getResultType());
$this->assertEquals('returns the json_decoded response', $c->getResultDoc());
$this->assertTrue($c->isDeprecated());
$this->assertEquals('Guzzle\\Service\\Command\\DynamicCommand', $c->getConcreteClass());
$this->assertEquals(array(
'key' => new ApiParam(array(
@ -106,7 +112,7 @@ class ApiCommandTest extends \Guzzle\Tests\GuzzleTestCase
public function testConvertsToArray()
{
$data = array(
'name' => 'test',
'name' => 'test',
'class' => 'Guzzle\\Service\\Command\ClosureCommand',
'doc' => 'test',
'method' => 'PUT',
@ -115,7 +121,10 @@ class ApiCommandTest extends \Guzzle\Tests\GuzzleTestCase
'p' => new ApiParam(array(
'name' => 'foo'
))
)
),
'result_type' => null,
'result_doc' => null,
'deprecated' => false
);
$c = new ApiCommand($data);
$this->assertEquals($data, $c->toArray());