├── CHANGELOG.md ├── CONTRIBUTING ├── .styleci.yml ├── .gitignore ├── .scrutinizer.yml ├── .editorconfig ├── src ├── Facade │ └── Httplug.php ├── HttplugServiceProvider.php └── HttplugManager.php ├── .php_cs ├── tests ├── AbstractTestCase.php ├── Facade │ └── HttplugTest.php └── HttplugServiceProviderTest.php ├── phpunit.xml.dist ├── .travis.yml ├── LICENSE ├── config └── laravel-httplug.php ├── composer.json └── README.md /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | 4 | ## Unreleased 5 | -------------------------------------------------------------------------------- /CONTRIBUTING: -------------------------------------------------------------------------------- 1 | Please see http://docs.php-http.org/en/latest/development/contributing.html 2 | -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | 3 | finder: 4 | exclude: 5 | - "spec" 6 | path: 7 | - "src" 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | build/ 3 | .puli/ 4 | puli.json 5 | composer.lock 6 | .php_cs.cache 7 | phpspec.yml 8 | phpunit.xml 9 | -------------------------------------------------------------------------------- /.scrutinizer.yml: -------------------------------------------------------------------------------- 1 | filter: 2 | paths: [src/*] 3 | checks: 4 | php: 5 | code_rating: true 6 | duplication: true 7 | tools: 8 | external_code_coverage: true 9 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 4 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | -------------------------------------------------------------------------------- /src/Facade/Httplug.php: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | ./tests/ 21 | 22 | 23 | 24 | 25 | ./src 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | sudo: false 4 | 5 | cache: 6 | directories: 7 | - $HOME/.composer/cache 8 | 9 | php: 10 | - 5.5 11 | - 5.6 12 | - 7.0 13 | - 7.1 14 | - hhvm 15 | 16 | env: 17 | global: 18 | - TEST_COMMAND="composer test" 19 | 20 | branches: 21 | except: 22 | - /^analysis-.*$/ 23 | 24 | matrix: 25 | fast_finish: true 26 | include: 27 | - php: 5.5 28 | env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest" COVERAGE=true TEST_COMMAND="composer test-ci" 29 | 30 | before_install: 31 | - if [[ $COVERAGE != true ]]; then phpenv config-rm xdebug.ini || true; fi 32 | 33 | install: 34 | - travis_retry composer update ${COMPOSER_FLAGS} --prefer-source --no-interaction 35 | 36 | script: 37 | - $TEST_COMMAND 38 | 39 | after_success: 40 | - if [[ "$COVERAGE" = true ]]; then wget https://scrutinizer-ci.com/ocular.phar; fi 41 | - if [[ "$COVERAGE" = true ]]; then php ocular.phar code-coverage:upload --format=php-clover build/coverage.xml; fi 42 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015-2016 PHP HTTP Team 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /tests/HttplugServiceProviderTest.php: -------------------------------------------------------------------------------- 1 | assertIsInjectable(HttplugManager::class); 22 | } 23 | 24 | /** 25 | * @test 26 | */ 27 | public function canInjectMessageFactory() 28 | { 29 | $this->assertIsInjectable(MessageFactory::class); 30 | } 31 | 32 | /** 33 | * @test 34 | */ 35 | public function canInjectResponseFactory() 36 | { 37 | $this->assertIsInjectable(ResponseFactory::class); 38 | } 39 | 40 | /** 41 | * @test 42 | */ 43 | public function canInjectUriFactory() 44 | { 45 | $this->assertIsInjectable(UriFactory::class); 46 | } 47 | 48 | /** 49 | * @test 50 | */ 51 | public function canInjectStreamFactory() 52 | { 53 | $this->assertIsInjectable(StreamFactory::class); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /config/laravel-httplug.php: -------------------------------------------------------------------------------- 1 | 'guzzle6', 6 | 7 | 'adapters' => [ 8 | 9 | /** 10 | * @link https://github.com/php-http/guzzle6-adapter 11 | */ 12 | 'guzzle6' => [ 13 | 'factory' => 'httplug.factory.guzzle6', 14 | 'plugins' => [ 15 | 'httplug.plugin.authentication.my_wsse', 16 | 'httplug.plugin.cache', 17 | 'httplug.plugin.retry', 18 | ], 19 | 20 | 'config' => [ 21 | 'verify' => false, 22 | 'timeout' => 2, 23 | ], 24 | ], 25 | 26 | /** 27 | * @link https://github.com/php-http/guzzle5-adapter 28 | */ 29 | 'guzzle5' => [ 30 | 31 | ], 32 | 33 | /** 34 | * @link https://github.com/php-http/curl-client 35 | */ 36 | 'curl' => [ 37 | 38 | ], 39 | 40 | /** 41 | * @link https://github.com/php-http/socket-client 42 | */ 43 | 'socket' => [ 44 | 45 | ], 46 | 47 | /** 48 | * @link https://github.com/php-http/buzz-adapter 49 | */ 50 | 'buzz' => [ 51 | 'resolver' => [ 52 | 'timeout' => 5, 53 | 'verify_peer' => true, 54 | 'verify_host' => 2, 55 | 'proxy' => null, 56 | ], 57 | ], 58 | 59 | /** 60 | * @link https://github.com/php-http/react-adapter 61 | */ 62 | 'react' => [ 63 | 64 | ], 65 | 66 | ], 67 | 68 | ]; 69 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "php-http/laravel-httplug", 3 | "description": "Laravel package to integrate the Httplug generic HTTP client into Laravel", 4 | "keywords": ["http", "discovery", "adapter", "message", "factory", "httplug", "php-http", "psr-7", "laravel"], 5 | "homepage": "http://php-http.org", 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Mathieu Santo Stefano--Féron", 10 | "email": "mathieu.santostefano@gmail.com" 11 | }, 12 | { 13 | "name": "Daniel Nilsson" 14 | }, 15 | { 16 | "name": "Tobias Nyholm" 17 | } 18 | ], 19 | "require": { 20 | "php": "^5.5 || ^7.0", 21 | "illuminate/support": "~5", 22 | "php-http/message": "^1.3", 23 | "php-http/client-common": "^1.2", 24 | "php-http/cache-plugin": "^1.0", 25 | "php-http/logger-plugin": "^1.0", 26 | "php-http/discovery": "^1.0" 27 | }, 28 | "require-dev": { 29 | "phpunit/phpunit": "^4.5 || ^5.4 || ^6.0", 30 | "graham-campbell/testbench": "^3.1", 31 | "friendsofphp/php-cs-fixer": "^2.0", 32 | "sllh/php-cs-fixer-styleci-bridge": "^1.5", 33 | "php-http/curl-client": "^1.0", 34 | "php-http/socket-client": "^1.0", 35 | "php-http/guzzle6-adapter": "^1.1", 36 | "php-http/react-adapter": "^2.1", 37 | "php-http/buzz-adapter": "^1.0" 38 | }, 39 | "autoload": { 40 | "psr-4": { 41 | "Http\\Httplug\\": "src/" 42 | } 43 | }, 44 | "autoload-dev": { 45 | "psr-4": { 46 | "Http\\Httplug\\": "tests/" 47 | } 48 | }, 49 | "scripts": { 50 | "test": "vendor/bin/phpunit", 51 | "test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml" 52 | }, 53 | "extra": { 54 | "laravel": { 55 | "providers": [ 56 | "Http\\Httplug\\HttplugServiceProvider" 57 | ], 58 | "aliases": { 59 | "Httplug": "Http\\Httplug\\Facade\\Httplug" 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel-Httplug 2 | 3 | [![Latest Version](https://img.shields.io/github/release/php-http/laravel-httplug.svg?style=flat-square)](https://github.com/php-http/laravel-httplug/releases) 4 | [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) 5 | [![Build Status](https://img.shields.io/travis/php-http/laravel-httplug.svg?style=flat-square)](https://travis-ci.org/php-http/laravel-httplug) 6 | [![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/php-http/laravel-httplug.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/laravel-httplug) 7 | [![Quality Score](https://img.shields.io/scrutinizer/g/php-http/laravel-httplug.svg?style=flat-square)](https://scrutinizer-ci.com/g/php-http/laravel-httplug) 8 | [![Total Downloads](https://img.shields.io/packagist/dt/php-http/laravel-httplug.svg?style=flat-square)](https://packagist.org/packages/php-http/laravel-httplug) 9 | 10 | ## Install 11 | 12 | Via Composer 13 | 14 | ``` bash 15 | $ composer require php-http/laravel-httplug 16 | ``` 17 | 18 | With Laravel 5.5 or newer, the package will be discovered automatically. 19 | If you're using an older version of Laravel, add the following to your 20 | `config/app.php`: 21 | 22 | ```php 23 | [ 27 | ..., 28 | ..., 29 | 30 | Http\Httplug\HttplugServiceProvider::class, 31 | 32 | ], 33 | 34 | 'aliases' => [ 35 | ..., 36 | ..., 37 | 38 | 'Httplug' => Http\Httplug\Facade\Httplug::class, 39 | 40 | ], 41 | 42 | 43 | ``` 44 | 45 | Publish the package config file to `config/httplug.php`: 46 | 47 | ``` 48 | php artisan vendor:publish --provider="Http\Httplug\HttplugServiceProvider" 49 | ``` 50 | 51 | ## Usage 52 | 53 | ```php 54 | make('httplug.message_factory.default'); 58 | $request = $factory->createRequest('GET', 'http://httpbin.org'); 59 | 60 | $httplug = app()->make('httplug'); 61 | 62 | // Send request with default driver 63 | $response = $httplug->sendRequest($request); 64 | 65 | // Send request with another driver 66 | $response = $httplug->driver('curl')->sendRequest($request); 67 | 68 | // Send request with default driver using facade 69 | $response = Httplug::sendRequest($request); 70 | 71 | // Send request with another driver using facade 72 | $response = Httplug::driver('curl')->sendRequest($request) 73 | 74 | ``` 75 | 76 | ## Testing 77 | 78 | ``` bash 79 | $ composer test 80 | ``` 81 | 82 | ## Contributing 83 | 84 | Please see our [contributing guide](http://docs.php-http.org/en/latest/development/contributing.html). 85 | 86 | ## Security 87 | 88 | If you discover any security related issues, please contact us at [security@php-http.org](mailto:security@php-http.org). 89 | 90 | 91 | ## License 92 | 93 | The MIT License (MIT). Please see [License File](LICENSE) for more information. 94 | -------------------------------------------------------------------------------- /src/HttplugServiceProvider.php: -------------------------------------------------------------------------------- 1 | publishes([$source => config_path('httplug.php')], 'config'); 30 | $this->mergeConfigFrom($source, 'httplug'); 31 | } 32 | 33 | /** 34 | * Register the application services. 35 | */ 36 | public function register() 37 | { 38 | $this->registerHttplugFactories(); 39 | $this->registerHttplug(); 40 | } 41 | 42 | /** 43 | * Register php-http interfaces to container. 44 | */ 45 | protected function registerHttplugFactories() 46 | { 47 | $this->app->bind('httplug.message_factory.default', function ($app) { 48 | return MessageFactoryDiscovery::find(); 49 | }); 50 | $this->app->alias('httplug.message_factory.default', MessageFactory::class); 51 | $this->app->alias('httplug.message_factory.default', ResponseFactory::class); 52 | 53 | $this->app->bind('httplug.uri_factory.default', function ($app) { 54 | return UriFactoryDiscovery::find(); 55 | }); 56 | $this->app->alias('httplug.uri_factory.default', UriFactory::class); 57 | 58 | $this->app->bind('httplug.stream_factory.default', function ($app) { 59 | return StreamFactoryDiscovery::find(); 60 | }); 61 | $this->app->alias('httplug.stream_factory.default', StreamFactory::class); 62 | } 63 | 64 | /** 65 | * Register httplug to container. 66 | */ 67 | protected function registerHttplug() 68 | { 69 | $this->app->singleton('httplug', function ($app) { 70 | return new HttplugManager($app); 71 | }); 72 | $this->app->alias('httplug', HttplugManager::class); 73 | 74 | $this->app->singleton('httplug.default', function ($app) { 75 | return $app['httplug']->driver(); 76 | }); 77 | } 78 | 79 | /** 80 | * Get the services provided by the provider. 81 | * 82 | * @return array 83 | */ 84 | public function provides() 85 | { 86 | return [ 87 | 'httplug', 88 | 'httplug.default', 89 | 'httplug.message_factory.default', 90 | 'httplug.uri_factory.default', 91 | 'httplug.stream_factory.default', 92 | MessageFactory::class, 93 | ResponseFactory::class, 94 | StreamFactory::class, 95 | UriFactory::class, 96 | 97 | ]; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /src/HttplugManager.php: -------------------------------------------------------------------------------- 1 | app = $app; 35 | } 36 | 37 | /** 38 | * Get default driver. 39 | * 40 | * @return string 41 | */ 42 | public function getDefaultDriver() 43 | { 44 | return $this->app['config']['httplug.default']; 45 | } 46 | 47 | /** 48 | * @param string $name 49 | * 50 | * @return array 51 | */ 52 | protected function getConfig($name) 53 | { 54 | return $this->app['config']["httplug.adapters.{$name}"]; 55 | } 56 | 57 | /** 58 | * @return \Http\Adapter\Guzzle6\Client 59 | */ 60 | public function createGuzzle6Driver() 61 | { 62 | return GuzzleSixAdapter::createWithConfig($this->getConfig('guzzle6')); 63 | } 64 | 65 | /** 66 | * @return \Http\Adapter\Guzzle5\Client 67 | */ 68 | public function createGuzzle5Driver() 69 | { 70 | return new GuzzleFiveAdapter( 71 | new GuzzleFiveClient($this->getConfig('guzzle5')), 72 | $this->app->make(MessageFactory::class) 73 | ); 74 | } 75 | 76 | /** 77 | * @return \Http\Client\Curl\Client 78 | */ 79 | public function createCurlDriver() 80 | { 81 | return new CurlAdapter( 82 | $this->app->make(MessageFactory::class), 83 | $this->app->make(StreamFactory::class), 84 | $this->getConfig('curl') 85 | ); 86 | } 87 | 88 | /** 89 | * @return \Http\Client\Socket\Client 90 | */ 91 | public function createSocketDriver() 92 | { 93 | return new SocketAdapter( 94 | $this->app->make(MessageFactory::class), 95 | $this->getConfig('socket') 96 | ); 97 | } 98 | 99 | /** 100 | * @todo add custom configuration 101 | * 102 | * @return \Http\Adapter\Buzz\Client 103 | */ 104 | public function createBuzzDriver() 105 | { 106 | return new BuzzAdapter( 107 | null, 108 | $this->app->make(ResponseFactory::class) 109 | ); 110 | } 111 | 112 | /** 113 | * @todo add custom configuration 114 | * 115 | * @return \Http\Adapter\React\Client 116 | */ 117 | public function createReactDriver() 118 | { 119 | return new ReactAdapter( 120 | $this->app->make(ResponseFactory::class) 121 | ); 122 | } 123 | } 124 | --------------------------------------------------------------------------------