2017 © Pedro Peláez
 

library common

Adadgio Commons

image

adadgio/common

Adadgio Commons

  • Tuesday, August 1, 2017
  • by romainbruckert
  • Repository
  • 3 Watchers
  • 0 Stars
  • 359 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 20 Versions
  • 19 % Grown

The README.md

AdadgioCommonBundle

Installation

Install with composer, (*1)

composer require adadgio/common

Table of contents

  1. Curl
  2. Url
  3. ParamResolver
  4. JsonResponse

Curl

To do Curl requests (get or post) and return results, (*2)

use Adadgio\Common\Http\Curl;


// GET request
$curl = new Curl();
$response = $curl
    ->get('http://example.com', array('query_param_1' => 'query param value'));


// or POST request with params
$curl = new Curl();
$response = $curl
    ->setContentType(Curl::JSON) // other options are JSON|XML|TEXT|FORL_URLENCODED|FORM_MULTIPART
    ->post('http://example.com', array('post_field_1' => 'psot field value'));

// POST request with more options
$curl = new Curl();
$response = $curl
    ->setContentType(Curl::JSON) // other options are JSON|XML|TEXT|FORL_URLENCODED|FORM_MULTIPART
    ->setAuthorizationBasic('Token', 'user', 'pass') // or ->setAuthorization('Basic', base64_encode('user:pass'))
    // or ->setAuthorization('Token', yO3my4To3en)
    ->setCookies(true)
    // ->addHeader('X-Custom-Header', 'CUst0mApiK3y')
    ->verifyHost(false) // or ->addOption(CURLOPT_SSL_VERIFYHOST, false)
    ->verifyPeer(true, "/home/my/server/cacert.pem") // second param is empty but you should set it in php.ini
    ->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..., (*3)

All methods are commented in UrlHelper.php, (*4)

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., (*5)

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, (*6)

use Adadgio\Common\JsonResponse;

// $data is an object or an array
$data = array('yes' => 'no', 'bar' => 'foo');

// default response code is 200
$code = 200;

// specific headers, default: array()
$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., (*7)

use Adadgio\Common\Moment\Since;
// Examples with referential date: "2016-07-29 12:00:00"

Since::format(new \DateTime('2016-06-29 09:00:00'));
// 09:00

Since::format(new \DateTime('2016-07-28 22:00:00'));
// Yesterday

Since::format(new \DateTime('2016-07-29 12:00:00'));
// Now

Since::format(new \DateTime('2016-07-29 11:59:55'));
// 5 seconds

The Versions

01/08 2017

dev-master

9999999-dev

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT

01/08 2017

2.0.9

2.0.9.0

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT

18/01 2017

2.0.8

2.0.8.0

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT

18/01 2017

2.0.7

2.0.7.0

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT

20/10 2016

2.0.6

2.0.6.0

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT

20/10 2016

2.0.5

2.0.5.0

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT

19/10 2016

2.0.4

2.0.4.0

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT

19/10 2016

2.0.3

2.0.3.0

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT

18/10 2016

2.0.2

2.0.2.0

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT

18/10 2016

2.0.1

2.0.1.0

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT

29/07 2016

2.0.0

2.0.0.0

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT

22/07 2016

v1.1.9

1.1.9.0

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT

22/07 2016

v1.1.8

1.1.8.0

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT

22/07 2016

v1.1.7

1.1.7.0

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT

22/07 2016

v1.1.6

1.1.6.0

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT

22/07 2016

v1.1.5

1.1.5.0

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT

21/07 2016

v1.1.4

1.1.4.0

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT

20/07 2016

v1.1.3

1.1.3.0

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT

15/06 2016

v1.1.2

1.1.2.0

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT

15/06 2016

v1.1.1

1.1.1.0

Adadgio Commons

  Sources   Download

MIT

The Requires

  • php >=5.3

 

by Romain BRUCKERT