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...
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
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