Skip to content

Commit

Permalink
Merge pull request #49 from danieledangeli/description-interface
Browse files Browse the repository at this point in the history
added description interface to extend it
  • Loading branch information
mtdowling committed Oct 16, 2014
2 parents e4511fc + f476d86 commit 75ae99f
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/Description.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Represents a Guzzle service description
*/
class Description
class Description implements DescriptionInterface
{
/** @var array Array of {@see OperationInterface} objects */
private $operations = [];
Expand Down
109 changes: 109 additions & 0 deletions src/DescriptionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<?php

namespace GuzzleHttp\Command\Guzzle;

use GuzzleHttp\Url;

interface DescriptionInterface
{
/**
* Get the basePath/baseUrl of the description
*
* @return Url
*/
public function getBaseUrl();

/**
* Get the API operations of the service
*
* @return Operation[] Returns an array of {@see Operation} objects
*/
public function getOperations();

/**
* Check if the service has an operation by name
*
* @param string $name Name of the operation to check
*
* @return bool
*/
public function hasOperation($name);

/**
* Get an API operation by name
*
* @param string $name Name of the command
*
* @return Operation
* @throws \InvalidArgumentException if the operation is not found
*/
public function getOperation($name);

/**
* Get a shared definition structure.
*
* @param string $id ID/name of the model to retrieve
*
* @return Parameter
* @throws \InvalidArgumentException if the model is not found
*/
public function getModel($id);

/**
* Get all models of the service description.
*
* @return array
*/
public function getModels();

/**
* Check if the service description has a model by name.
*
* @param string $id Name/ID of the model to check
*
* @return bool
*/
public function hasModel($id);

/**
* Get the API version of the service
*
* @return string
*/
public function getApiVersion();

/**
* Get the name of the API
*
* @return string
*/
public function getName();

/**
* Get a summary of the purpose of the API
*
* @return string
*/
public function getDescription();

/**
* Format a parameter using named formats.
*
* @param string $format Format to convert it to
* @param mixed $input Input string
*
* @return mixed
*/
public function format($format, $input);

/**
* Get arbitrary data from the service description that is not part of the
* Guzzle service description specification.
*
* @param string $key Data key to retrieve or null to retrieve all extra
*
* @return null|mixed
*/
public function getData($key = null);

}
12 changes: 6 additions & 6 deletions src/GuzzleClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ class GuzzleClient extends AbstractClient implements GuzzleClientInterface
* - response_locations: Associative array of location types mapping to
* ResponseLocationInterface objects.
*
* @param ClientInterface $client Client used to send HTTP requests
* @param Description $description Guzzle service description
* @param array $config Configuration options
* @param ClientInterface $client Client used to send HTTP requests
* @param DescriptionInterface $description Guzzle service description
* @param array $config Configuration options
*/
public function __construct(
ClientInterface $client,
Description $description,
DescriptionInterface $description,
array $config = []
) {
parent::__construct($client, $config);
Expand Down Expand Up @@ -73,11 +73,11 @@ public function getDescription()
* Creates a callable function used to create command objects from a
* service description.
*
* @param Description $description Service description
* @param DescriptionInterface $description Service description
*
* @return callable Returns a command factory
*/
public static function defaultCommandFactory(Description $description)
public static function defaultCommandFactory(DescriptionInterface $description)
{
return function (
$name,
Expand Down
2 changes: 1 addition & 1 deletion src/GuzzleClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface GuzzleClientInterface extends ServiceClientInterface
/**
* Returns the service description used by the client
*
* @return Description
* @return DescriptionInterface
*/
public function getDescription();
}
6 changes: 3 additions & 3 deletions src/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ class Operation implements ToArrayInterface
* - additionalParameters: (null|array) Parameter schema to use when an
* option is passed to the operation that is not in the schema
*
* @param array $config Array of configuration data
* @param Description $description Service description used to resolve models if $ref tags are found
* @param array $config Array of configuration data
* @param DescriptionInterface $description Service description used to resolve models if $ref tags are found
* @throws \InvalidArgumentException
*/
public function __construct(array $config = [], Description $description)
public function __construct(array $config = [], DescriptionInterface $description)
{
static $defaults = [
'name' => '',
Expand Down
2 changes: 1 addition & 1 deletion src/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function __construct(array $data = [], array $options = [])

if (isset($options['description'])) {
$this->serviceDescription = $options['description'];
if (!($this->serviceDescription instanceof Description)) {
if (!($this->serviceDescription instanceof DescriptionInterface)) {
throw new \InvalidArgumentException('description must be a Description');
}
if (isset($data['$ref'])) {
Expand Down

0 comments on commit 75ae99f

Please sign in to comment.