AdadgioCommonBundle
Installation
Install with composer
composer require adadgio/common
Table of contents
Curl
To do Curl requests (get or post) and return results
use Adadgio\Common\Http\Curl;
$curl = new Curl();
$response = $curl
->get('http://example.com', array('query_param_1' => 'query param value'));
$curl = new Curl();
$response = $curl
->setContentType(Curl::JSON)
->post('http://example.com', array('post_field_1' => 'psot field value'));
$curl = new Curl();
$response = $curl
->setContentType(Curl::JSON)
->setAuthorizationBasic('Token', 'user', 'pass')
->setCookies(true)
->verifyHost(false)
->verifyPeer(true, "/home/my/server/cacert.pem")
->post('http://example.com', array('post_field_1' => 'psot field value'));
UrlHelper
Help to check if an URL is relative or aboslute, normalise an URL, get protocol, check protocol less...
All methods are commented in UrlHelper.php
ParamResolver
Two methods let to know if value is a valid array or valid integer (>0). If it's not the case, return default value parameter.
use Adadgio\Common\ParamResolver;
$arrayToTest = array(
'one' => true,
'barbar' => 29393,
'first' => 'foo',
);
$defaultArray = array(
'one' => false,
'second' => 'yolo',
);
$array = ParamResolver::toArray($arrayToTest, $defaultArray);
use Adadgio\Common\ParamResolver;
$integer = ParamResolver::toInt(430, 0);
JsonResponse
A custom easy response object handler to respond with JSON data
use Adadgio\Common\JsonResponse;
$data = array('yes' => 'no', 'bar' => 'foo');
$code = 200;
$headers = array();
$array = JsonResponse::fire($data, $code, $headers);
Since
This tool return an human date to display, like few some seconds...
Default referential is the current date and time, a custom referential can be set in second parameter.
use Adadgio\Common\Moment\Since;
Since::format(new \DateTime('2016-06-29 09:00:00'));
Since::format(new \DateTime('2016-07-28 22:00:00'));
Since::format(new \DateTime('2016-07-29 12:00:00'));
Since::format(new \DateTime('2016-07-29 11:59:55'));