Skip to content

Commit

Permalink
Migrate guzzlehttp/guzzle-service to Guzzle 6
Browse files Browse the repository at this point in the history
* Migrate the serialization
* Migrate the deserialization
* Move the response error handling from `HandleErrorResponses` to `Deserializer`
* Migrate the request locations
* Migrate the response locations
* Add request location FormParamLocation as substitute of PostFieldLocation
* Add request location MultiPartLocation as substitute of PostFileLocation
* Migrate ValidateInput to ValidateDescriptionHandler
* Move code from ProcessResponse to Deserializer
* Change Description::getBaseUrl() to Description::getBaseUri()
* Change Parameter::getRequired() to Parameter::isRequired()
* Change Parameter::getStatic() to Parameter::isStatic()
* Require PHP 5.5 and higher
  • Loading branch information
jeremeamia authored and Konafets committed Nov 24, 2016
1 parent 8adb1d1 commit 3bdd887
Show file tree
Hide file tree
Showing 64 changed files with 3,984 additions and 2,347 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.idea
.DS_STORE
phpunit.xml
composer.lock
vendor/
Expand Down
12 changes: 11 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
sudo: false
language: php

php:
- 5.4
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm
- nightly

matrix:
fast_finish: true
allow_failures:
- php: 7.1
- php: hhvm
- php: nightly

before_script:
- composer self-update
Expand Down
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Guzzle Services

[![License](https://poser.pugx.org/guzzlehttp/guzzle-services/license)](https://packagist.org/packages/guzzlehttp/guzzle-services)
[![Build Status](https://travis-ci.org/guzzle/guzzle-services.svg?branch=guzzle6)](https://travis-ci.org/guzzle/guzzle-services)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/guzzle/guzzle-services/badges/quality-score.png?b=guzzle6)](https://scrutinizer-ci.com/g/guzzle/guzzle-services/?branch=guzzle6)
[![Code Coverage](https://scrutinizer-ci.com/g/guzzle/guzzle-services/badges/coverage.png?b=guzzle6)](https://scrutinizer-ci.com/g/guzzle/guzzle-services/?branch=guzzle6)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/b08be676-b209-40b7-a6df-b6d13e8dff62/mini.png)](https://insight.sensiolabs.com/projects/b08be676-b209-40b7-a6df-b6d13e8dff62)
[![Latest Stable Version](https://poser.pugx.org/guzzlehttp/guzzle-services/v/stable)](https://packagist.org/packages/guzzlehttp/guzzle-services)
[![Latest Unstable Version](https://poser.pugx.org/guzzlehttp/guzzle-services/v/unstable)](https://packagist.org/packages/guzzlehttp/guzzle-services)
[![Total Downloads](https://poser.pugx.org/guzzlehttp/guzzle-services/downloads)](https://packagist.org/packages/guzzlehttp/guzzle-services)

Provides an implementation of the Guzzle Command library that uses Guzzle service descriptions to describe web services, serialize requests, and parse responses into easy to use model structures.

```php
use GuzzleHttp\Client;
use GuzzleHttp\Command\Guzzle\GuzzleClient;
use GuzzleHttp\Command\Guzzle\Description;

$client = new Client();
$description = new Description([
'baseUri' => 'http://httpbin.org/',
'operations' => [
'testing' => [
'httpMethod' => 'GET',
'uri' => '/get{?foo}',
'responseModel' => 'getResponse',
'parameters' => [
'foo' => [
'type' => 'string',
'location' => 'uri'
],
'bar' => [
'type' => 'string',
'location' => 'query'
]
]
]
],
'models' => [
'getResponse' => [
'type' => 'object',
'additionalProperties' => [
'location' => 'json'
]
]
]
]);

$guzzleClient = new GuzzleClient($client, $description);

$result = $guzzleClient->testing(['foo' => 'bar']);
echo $result['args']['foo'];
// bar
```

## Installing

This project can be installed using Composer:

``composer require guzzlehttp/guzzle-services``

For **Guzzle 5**, use ``composer require guzzlehttp/guzzle-services:0.5.*``.

**Note:** If Composer is not
`installed globally <https://getcomposer.org/doc/00-intro.md#globally>`_,
then you may need to run the preceding Composer commands using
``php composer.phar`` (where ``composer.phar`` is the path to your copy of
Composer), instead of just ``composer``.

## Plugins

* Load Service description from file [https://github.com/gimler/guzzle-description-loader]

More documentation coming soon.
68 changes: 0 additions & 68 deletions README.rst

This file was deleted.

20 changes: 17 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,22 @@
"name": "Michael Dowling",
"email": "[email protected]",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Jeremy Lindblom",
"email": "[email protected]",
"homepage": "https://github.com/jeremeamia"
},
{
"name": "Stefano Kowalke",
"email": "[email protected]",
"homepage": "https://github.com/konafets"
}
],
"require": {
"php": ">=5.4.0",
"guzzlehttp/command": "0.7.*"
"php": ">=5.5",
"guzzlehttp/guzzle": "^6.2",
"guzzlehttp/command": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
Expand All @@ -27,9 +38,12 @@
"GuzzleHttp\\Tests\\Command\\Guzzle\\": "tests/"
}
},
"suggest": {
"gimler/guzzle-description-loader": "^0.0.4"
},
"extra": {
"branch-alias": {
"dev-master": "0.4-dev"
"dev-master": "0.6-dev"
}
}
}
22 changes: 13 additions & 9 deletions src/Description.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace GuzzleHttp\Command\Guzzle;

use GuzzleHttp\Url;
use GuzzleHttp\Psr7\Uri;

/**
* Represents a Guzzle service description
Expand All @@ -26,8 +26,8 @@ class Description implements DescriptionInterface
/** @var array Any extra API data */
private $extraData = [];

/** @var string baseUrl/basePath */
private $baseUrl;
/** @var Uri baseUri/basePath */
private $baseUri;

/** @var SchemaFormatter */
private $formatter;
Expand All @@ -52,8 +52,12 @@ public function __construct(array $config, array $options = [])
}
}

// Set the baseUrl
$this->baseUrl = Url::fromString(isset($config['baseUrl']) ? $config['baseUrl'] : '');
// Set the baseUri
// Account for the old style of using baseUrl
if (isset($config['baseUrl'])) {
$config['baseUri'] = $config['baseUrl'];
}
$this->baseUri = isset($config['baseUri']) ? new Uri($config['baseUri']) : new Uri();

// Ensure that the models and operations properties are always arrays
$this->models = (array) $this->models;
Expand Down Expand Up @@ -91,13 +95,13 @@ public function __construct(array $config, array $options = [])
}

/**
* Get the basePath/baseUrl of the description
* Get the basePath/baseUri of the description
*
* @return Url
* @return Uri
*/
public function getBaseUrl()
public function getBaseUri()
{
return $this->baseUrl;
return $this->baseUri;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/DescriptionInterface.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php
namespace GuzzleHttp\Command\Guzzle;

use GuzzleHttp\Url;
use GuzzleHttp\Psr7\Uri;

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

/**
* Get the API operations of the service
Expand Down
Loading

0 comments on commit 3bdd887

Please sign in to comment.