A PHP Client of FOAAS
You can install the package via composer:
composer require codeat3/foaas-client
Basic usage of the client
use Codeat3\FoaasClient\FoaasClient;
$foaasClient = new FoaasClient([
'decency' => 'low', // possible decency filter options are 'low', 'medium', 'high', 'extreme' - default is no filter
]);
echo $foaasClient->what('John')->get();
// Output
What the f*ck‽ - John
Using format to get the response as per your need
use Codeat3\FoaasClient\FoaasClient;
$foaasClient = new FoaasClient([
'decency' => 'low',
'responseAs' => 'array', // possible response formats are 'text' (default), 'html', 'xml', 'json', 'array'
]);
print_r($foaasClient->what('John')->get());
// Output
Array
(
[message] => What the f*ck‽
[subtitle] => - John
)
Also few helpers are provided for the type of output expected
$foaasClient = new FoaasClient([
'decency' => 'low',
]);
echo $foaasClient->what('John')->getAsText(); // What the f*ck‽ - John
echo $foaasClient->what('John')->getAsXml(); // <?xml version="1.0" encoding="UTF-8"?> <foaas:response xmlns:foaas="http://foaas.com/f*ckoff"> <foaas:message>What the f*ck‽</foaas:message> <foaas:subtitle>- John</foaas:subtitle> </foaas:response>
echo $foaasClient->what('John')->getAsHtml(); // <!DOCTYPE html> <html> <head> <title>FOAAS - What the f*ck‽ - John</title> <meta charset="utf-8"> <meta property="og:title" content="What the f*ck‽ - John"> ...
echo $foaasClient->what('John')->getAsJson(); // {"message":"What the f*ck‽","subtitle":"- John"}
print_r($foaasClient->what('John')->getAsArray());
/*
Array
(
[message] => What the f*ck‽
[subtitle] => - John
)
*/
You can implement the custom responses and pass it in customer as per your need
// Implementation
class ObjectResponse implements FoaasResponse
{
protected $acceptHeader = 'application/json';
public function getHeaders():string
{
return $this->acceptHeader;
}
public function response(string $response, FoaasFilter $filter)
{
$response = $filter->filter($response);
return json_decode($response);
}
}
// Use
$foaasClient = new FoaasClient([
'decency' => 'low',
'responseAs' => 'object',
'responseFormats' => [
'object' => ObjectResponse::class,
]
]);
var_dump($foaasClient->what('John')->get());
/*
class stdClass#27 (2) {
public $message =>
string(16) "What the f*ck‽"
public $subtitle =>
string(6) "- John"
}
*/
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email swapnilsarwe@gmail.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the PHP Package Boilerplate.