Skip to content

Commit 18422b6

Browse files
authored
feat: update monolog version to get any version #182
2 parents 17ebd71 + eba67cf commit 18422b6

File tree

269 files changed

+32676
-37
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

269 files changed

+32676
-37
lines changed

composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
"type": "library",
1212
"require": {
1313
"php": ">=7.1",
14-
"monolog/monolog": "<3",
15-
"pagarme/pagarmecoreapi": "v5.6.6",
14+
"monolog/monolog": "*",
15+
"apimatic/unirest-php": "^2.0.0",
16+
"apimatic/jsonmapper": "^1.3.1",
1617
"ext-json": "*"
1718
},
1819
"require-dev": {
@@ -25,7 +26,8 @@
2526
"psr-4": {
2627
"Pagarme\\Core\\": "src",
2728
"Pagarme\\Core\\Test\\": "tests",
28-
"Pagarme\\Core\\Test\\Mock\\": "tests\\mock"
29+
"Pagarme\\Core\\Test\\Mock\\": "tests\\mock",
30+
"PagarmeCoreApiLib\\": "lib\\src"
2931
}
3032
},
3133
"scripts": {

lib/src/APIException.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/*
3+
* PagarmeCoreApiLib
4+
*
5+
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
6+
*/
7+
8+
namespace PagarmeCoreApiLib;
9+
10+
use Exception;
11+
12+
/**
13+
* Class for exceptions when there is a network error, status code error, etc.
14+
*/
15+
class APIException extends Exception
16+
{
17+
/**
18+
* Error message
19+
* @var string
20+
*/
21+
private $errorMessage;
22+
23+
/**
24+
* HTTP context
25+
* @var Http\HttpContext
26+
*/
27+
private $context;
28+
29+
/**
30+
* The HTTP response code from the API request
31+
* @param string $reason the reason for raising an exception
32+
* @param int $responseCode the HTTP response code from the API request
33+
* @param string $responseBody the HTTP response body from the API request
34+
*/
35+
public function __construct($reason, $context)
36+
{
37+
parent::__construct($reason, $context->getResponse()->getStatusCode());
38+
$this->context = $context;
39+
$this->errorMessage = $reason;
40+
41+
if (get_class() != 'APIException') {
42+
$this->unbox();
43+
}
44+
}
45+
46+
/**
47+
* Unbox response into this exception class
48+
*/
49+
public function unbox()
50+
{
51+
}
52+
53+
/**
54+
* The HTTP context from the API request
55+
* @return Http\HttpContext
56+
*/
57+
public function getContext()
58+
{
59+
return $this->context;
60+
}
61+
62+
/**
63+
* The HTTP response code from the API request
64+
* @return int
65+
*/
66+
public function getResponseCode()
67+
{
68+
return $this->context->getResponse()->getStatusCode();
69+
}
70+
71+
/**
72+
* The HTTP response body from the API request
73+
* @return mixed
74+
*/
75+
public function getResponseBody()
76+
{
77+
return $this->context->getResponse()->getRawBody();
78+
}
79+
80+
/**
81+
* The reason for raising an exception
82+
* @return string
83+
*/
84+
public function getReason()
85+
{
86+
return $this->message;
87+
}
88+
}

lib/src/APIHelper.php

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
<?php
2+
/*
3+
* PagarmeCoreApiLib
4+
*
5+
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
6+
*/
7+
8+
namespace PagarmeCoreApiLib;
9+
10+
use InvalidArgumentException;
11+
use JsonSerializable;
12+
13+
/**
14+
* API utility class
15+
*/
16+
class APIHelper
17+
{
18+
/**
19+
* Replaces template parameters in the given url
20+
* @param string $url The query string builder to replace the template parameters
21+
* @param array $parameters The parameters to replace in the url
22+
* @return string The processed url
23+
*/
24+
public static function appendUrlWithTemplateParameters($url, $parameters)
25+
{
26+
//perform parameter validation
27+
if (is_null($url) || !is_string($url)) {
28+
throw new InvalidArgumentException('Given value for parameter "queryBuilder" is invalid.');
29+
}
30+
31+
if (is_null($parameters)) {
32+
return $url;
33+
}
34+
35+
//iterate and append parameters
36+
foreach ($parameters as $key => $value) {
37+
$replaceValue = '';
38+
39+
//load parameter value
40+
if (is_null($value)) {
41+
$replaceValue = '';
42+
} elseif (is_array($value)) {
43+
$replaceValue = implode("/", array_map("urlencode", $value));
44+
} else {
45+
$replaceValue = urlencode(strval($value));
46+
}
47+
48+
//find the template parameter and replace it with its value
49+
$url = str_replace('{' . strval($key) . '}', $replaceValue, $url);
50+
}
51+
52+
return $url;
53+
}
54+
55+
/**
56+
* Appends the given set of parameters to the given query string
57+
* @param string $queryBuilder The query url string to append the parameters
58+
* @param array $parameters The parameters to append
59+
* @return void
60+
*/
61+
public static function appendUrlWithQueryParameters(&$queryBuilder, $parameters)
62+
{
63+
//perform parameter validation
64+
if (is_null($queryBuilder) || !is_string($queryBuilder)) {
65+
throw new InvalidArgumentException('Given value for parameter "queryBuilder" is invalid.');
66+
}
67+
if (is_null($parameters)) {
68+
return;
69+
}
70+
//does the query string already has parameters
71+
$hasParams = (strrpos($queryBuilder, '?') > 0);
72+
73+
//if already has parameters, use the &amp; to append new parameters
74+
$queryBuilder = $queryBuilder . (($hasParams) ? '&' : '?');
75+
76+
//append parameters
77+
$queryBuilder = $queryBuilder . http_build_query($parameters);
78+
}
79+
80+
/**
81+
* Validates and processes the given Url
82+
* @param string $url The given Url to process
83+
* @return string Pre-processed Url as string */
84+
public static function cleanUrl($url)
85+
{
86+
//perform parameter validation
87+
if (is_null($url) || !is_string($url)) {
88+
throw new InvalidArgumentException('Invalid Url.');
89+
}
90+
//ensure that the urls are absolute
91+
$matchCount = preg_match("#^(https?://[^/]+)#", $url, $matches);
92+
if ($matchCount == 0) {
93+
throw new InvalidArgumentException('Invalid Url format.');
94+
}
95+
//get the http protocol match
96+
$protocol = $matches[1];
97+
98+
//remove redundant forward slashes
99+
$query = substr($url, strlen($protocol));
100+
$query = preg_replace("#//+#", "/", $query);
101+
102+
//return process url
103+
return $protocol.$query;
104+
}
105+
106+
/**
107+
* Deserialize a Json string
108+
* @param string $json A valid Json string
109+
* @param mixed $instance Instance of an object to map the json into
110+
* @param boolean $isArray Is the Json an object array?
111+
* @return mixed Decoded Json
112+
*/
113+
public static function deserialize($json, $instance = null, $isArray = false)
114+
{
115+
if ($instance == null) {
116+
return json_decode($json, true);
117+
} else {
118+
$mapper = new \apimatic\jsonmapper\JsonMapper();
119+
if ($isArray) {
120+
return $mapper->mapArray(json_decode($json), array(), $instance);
121+
} else {
122+
return $mapper->map(json_decode($json), $instance);
123+
}
124+
}
125+
}
126+
127+
/**
128+
* Check if an array isAssociative (has string keys)
129+
* @param array $array A valid array
130+
* @return boolean True if the array is Associative, false if it is Indexed
131+
*/
132+
private static function isAssociative($arr)
133+
{
134+
foreach ($arr as $key => $value) {
135+
if (is_string($key)) {
136+
return true;
137+
}
138+
}
139+
140+
return false;
141+
}
142+
143+
/**
144+
* Prepare a model for form encoding
145+
* @param JsonSerializable $model A valid instance of JsonSerializable
146+
* @return array The model as a map of key value pairs
147+
*/
148+
public static function prepareFormFields($model)
149+
{
150+
if (!$model instanceof JsonSerializable) {
151+
return $model;
152+
}
153+
154+
$arr = $model->jsonSerialize();
155+
156+
foreach ($model as $key => $value) {
157+
if ($value instanceof JsonSerializable) {
158+
$arr[$key] = static::prepareFormFields($model->$key);
159+
} elseif (is_array($value) && !empty($value) && !static::isAssociative($value) &&
160+
$value[0] instanceof JsonSerializable) {
161+
$temp = array();
162+
foreach ($value as $k => $v) {
163+
$temp[$k] = static::prepareFormFields($v);
164+
}
165+
$arr[$key] = $temp;
166+
}
167+
}
168+
return $arr;
169+
}
170+
}

lib/src/Configuration.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/*
3+
* PagarmeCoreApiLib
4+
*
5+
* This file was automatically generated by APIMATIC v2.0 ( https://apimatic.io ).
6+
*/
7+
8+
namespace PagarmeCoreApiLib;
9+
10+
/**
11+
* All configuration including auth info and base URI for the API access
12+
* are configured in this class.
13+
*/
14+
class Configuration
15+
{
16+
/**
17+
* The base Uri for API calls
18+
* @var string
19+
*/
20+
public static $BASEURI = 'https://api.pagar.me/core/v5';
21+
22+
/**
23+
* The username to use with basic authentication
24+
* @var string
25+
*/
26+
public static $basicAuthUserName = 'TODO: Replace';
27+
28+
/**
29+
* The password to use with basic authentication
30+
* @var string
31+
*/
32+
public static $basicAuthPassword = 'TODO: Replace';
33+
}

0 commit comments

Comments
 (0)