2017 © Pedro Peláez
 

library net-driver

PHP network access library

image

stk2k/net-driver

PHP network access library

  • Wednesday, May 23, 2018
  • by stk2k
  • Repository
  • 1 Watchers
  • 0 Stars
  • 27 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 108 % Grown

The README.md

NetDriver, HTTP client with plug-in system

Description

NetDriver is a PHP library which provides sending HTTP requests., (*1)

Feature

  • Pluggable. You can easily replace other HTTP access library if you want.
  • Simple interfaces.
  • Callback events. You can customize your request before it is exectuted. Also you can get detail logs in sending request.
  • PSR-3 Logger acceptable.
  • cURL/PHP(file_get_contents) net drivers are bundled.

Usage

  1. Create net driver object(CurlNetDriver or PhpNetDriver are available).
  2. Create handle from net driver object.
  3. Create request object(HttpGetRequst/HttpPostRequest/JsonPostRequest are available).
  4. Call sendRequest method of net driver object and receive response object.

Demo

Example 1: sending HTTP request by cURL

use Stk2k\NetDriver\Drivers\Curl\CurlNetDriver;

$driver = new CurlNetDriver();
$request = new HttpGetRequest($driver, 'http://sazysoft.com/test/');
$handle = $driver->newHandle();

try{
    $response = $driver->sendRequest($handle, $request);
    echo $response->getBody();
}
catch(NetDriverException $e)
{
    // error handling here
}

Example 2: sending HTTP request by file_get_contents

use Stk2k\NetDriver\Drivers\Php\PhpNetDriver;

$driver = new PhpNetDriver();
$request = new HttpGetRequest($driver, 'http://sazysoft.com/test/');
$handle = $driver->newHandle();

try{
    $response = $driver->sendRequest($handle, $request);
    echo $response->getBody();
}
catch(NetDriverExceptionInterface $e)
{
    // error handling here
}

Example 3: post request

$driver = new CurlNetDriver();
$request = new HttpPostRequest($driver, 'http://sazysoft.com/test/', ['foo' => 'bar', 'baz' => 'qux']);
$handle = $driver->newHandle();

try{
    $response = $driver->sendRequest($handle, $request);
    echo $response->getBody();
}
catch(NetDriverExceptionInterface $e)
{
    // error handling here
}

Example 4: request callback

$driver = new CurlNetDriver();
$request = new HttpGetRequest($driver, 'http://sazysoft.com/test/');
$handle = $driver->newHandle();

try{
    $driver->listen('request', function(HttpRequest $request){
        $request->addHttpHeader('Content-Type', 'text/json');       // set content type to text/json
        return $request;    // replace old request to new one
    });
    $response = $driver->sendRequest($handle, $request);
    echo $response->getBody();
}
catch(NetDriverExceptionInterface $e)
{
    // error handling here
}

Example 5: verbose callback

$driver = new CurlNetDriver();
$request = new HttpGetRequest($driver, 'http://sazysoft.com/test/');
$handle = $driver->newHandle();

try{
    $driver->setVerbose(true);          // curl netdriver can write debug info to output
    $driver->listen('verbose', function($strerr, $header, $output){
        echo '----[ strerr ]----' . PHP_EOL;
        echo $strerr . PHP_EOL;
        echo '----[ header ]----' . PHP_EOL;
        echo $header . PHP_EOL;
        echo '----[ output ]----' . PHP_EOL;
        echo $output . PHP_EOL;
    });
    $response = $driver->sendRequest($handle, $request);
    echo '----[ response ]----' . PHP_EOL;
    echo $response->getBody();
}
catch(NetDriverExceptionInterface $e)
{
    // error handling here
}

Requirement

PHP 7.1 or later, (*2)

Installing NetDriver

The recommended way to install NetDriver is through Composer., (*3)

composer require stk2k/net-driver

After installing, you need to require Composer's autoloader:, (*4)

require 'vendor/autoload.php';

License

MIT, (*5)

Author

stk2k, (*6)

Disclaimer

This software is no warranty., (*7)

We are not responsible for any results caused by the use of this software., (*8)

Please use the responsibility of the your self., (*9)

The Versions

23/05 2018

dev-master

9999999-dev https://github.com/stk2k/net-driver

PHP network access library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Katsuki Shuto

php library http network bitflyer

22/05 2018

0.2.6

0.2.6.0 https://github.com/stk2k/net-driver

PHP network access library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Katsuki Shuto

php library http network bitflyer

21/05 2018

0.2.5

0.2.5.0 https://github.com/stk2k/net-driver

PHP network access library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Katsuki Shuto

php library http network bitflyer

21/05 2018

0.2.4

0.2.4.0 https://github.com/stk2k/net-driver

PHP network access library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Katsuki Shuto

php library http network bitflyer

21/05 2018

0.2.3

0.2.3.0 https://github.com/stk2k/net-driver

PHP network access library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Katsuki Shuto

php library http network bitflyer

21/05 2018

0.2.2

0.2.2.0 https://github.com/stk2k/net-driver

PHP network access library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Katsuki Shuto

php library http network bitflyer

21/05 2018

0.2.1

0.2.1.0 https://github.com/stk2k/net-driver

PHP network access library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Katsuki Shuto

php library http network bitflyer

20/05 2018

0.2.0

0.2.0.0 https://github.com/stk2k/net-driver

PHP network access library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Katsuki Shuto

php library http network bitflyer

20/05 2018

0.1.0

0.1.0.0 https://github.com/stk2k/net-driver

PHP network access library

  Sources   Download

MIT

The Requires

 

The Development Requires

by Katsuki Shuto

php library http network bitflyer