bee4 / transport
A simple chainable transport client.
Installs: 2 118
Dependents: 1
Suggesters: 0
Security: 0
Stars: 16
Watchers: 2
Forks: 0
Open Issues: 6
Requires
- php: >=5.6.0
- ext-curl: *
- bee4/events: ^1.1
- composer/ca-bundle: ^1.0
Requires (Dev)
- behat/behat: ~3
- evenement/evenement: ~2
- phpunit/phpunit: ~4.0
- squizlabs/php_codesniffer: ~2.0
README
This library is a transport client that can be used to handle HTTP, FTP, FTPS, SFTP, SCP calls. All protocols are processed the same way and the API is a simple Request
> Response
mechanism.
It is inspired by the Guzzle 3 implementation with a simpler approach (no curl_multi, no SSL...), just Request and Response handling. For the moment cURL is the only implementation and all Requests options are CURL_*
options...
Installing
This project can be installed using Composer. Add the following to your composer.json:
{ "require": { "bee4/transport": "~1.2" } }
or run this command:
composer require bee4/transport:~1.2
Example
You must create a Client
instance then built the request and send it to retrieve the response.
<?php $client = new Bee4\Transport\MagicHandler(); $request = $client->get('http://www.example.com', ['Accept: text/html']); $response = $request->send(); $respose->getStatusMessage(); //Retrieve the status definition example: 301 Moved Permanently $respose->getBody(); //Retrieve response content //The same is possible with FTP $request = $client->head('ftp://user@pass:host.com/path')->send(); //Remove a file $client->delete('ftp://user@pass:host.com/path/to/file.php')->send(); //And SFTP - Upload a file $client->put('sftp://user@pass:host.com/path/to/file.php') ->setBody('File content here') ->send();
A mapping is done between HTTP methods name and client calls to maintain the same API :
head
is used to check if the resource is here ;get
is used to retrieve a resource ;put
is used to upload a resource ;delete
is used to remove a resource.
Others method are handled only by HTTP: POST