-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from aplazame/refactor
v2.0.0 Component refactor
- Loading branch information
Showing
46 changed files
with
855 additions
and
1,437 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
|
||
[**.php] | ||
indent_size = 4 | ||
continuation_indent_size = 4 | ||
insert_final_newline = true | ||
|
||
[**.xml] | ||
indent_size = 4 | ||
|
||
[**.yml] | ||
indent_size = 2 | ||
|
||
[*.{js,json}] | ||
indent_size = 2 | ||
|
||
[composer.{json,lock}] | ||
indent_size = 4 | ||
|
||
[Makefile] | ||
indent_style = tab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/vendor/ | ||
aplazame/config.xml | ||
.php_cs.cache | ||
composer.lock | ||
docker-compose.override.yml | ||
latest.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
return Symfony\CS\Config\Config::create() | ||
->setUsingCache(true) | ||
->fixers( | ||
array( | ||
'-concat_without_spaces', | ||
'-empty_return', | ||
'-phpdoc_indent', | ||
'-phpdoc_no_empty_return', | ||
'-phpdoc_params', | ||
'-phpdoc_to_comment', | ||
'-psr0', | ||
'-unneeded_control_parentheses', | ||
'long_array_syntax', | ||
'concat_with_spaces', | ||
'ereg_to_preg', | ||
'ordered_use', | ||
) | ||
) | ||
->finder( | ||
Symfony\CS\Finder\DefaultFinder::create() | ||
->in('aplazame') | ||
) | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
class Aplazame_Client | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $apiBaseUri; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $accessToken; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
private $sandbox; | ||
|
||
public function __construct($apiBaseUri, $accessToken, $sandbox) | ||
{ | ||
$this->apiBaseUri = $apiBaseUri; | ||
$this->accessToken = $accessToken; | ||
$this->sandbox = $sandbox; | ||
} | ||
|
||
public function callToRest($method, $path, array $values = null) | ||
{ | ||
$url = $this->apiBaseUri . $path; | ||
$headers = array( | ||
'Authorization: Bearer ' . $this->accessToken, | ||
'Accept: application/vnd.aplazame.' . ($this->sandbox ? 'sandbox.' : '') . 'v1+json', | ||
); | ||
|
||
$versions = array( | ||
'PHP/' . PHP_VERSION, | ||
'Prestashop/' . _PS_VERSION_, | ||
'AplazamePrestashop/' . Aplazame::VERSION, | ||
); | ||
$headers[] = 'User-Agent: ' . implode(', ', $versions); | ||
|
||
if ($values) { | ||
$headers[] = 'Content-type: application/json'; | ||
$values = json_encode($values); | ||
} | ||
|
||
$result = $this->doCurlRequest($method, $url, $headers, $values); | ||
$result['is_error'] = ($result['code'] >= 400); | ||
$result['payload'] = json_decode($result['payload'], true); | ||
|
||
return $result; | ||
} | ||
|
||
protected function doCurlRequest($method, $url, $headers, $values) | ||
{ | ||
$ch = curl_init(); | ||
curl_setopt($ch, CURLOPT_URL, $url); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); | ||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | ||
if ($values) { | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, $values); | ||
} | ||
|
||
$responseBody = curl_exec($ch); | ||
|
||
if (false === $responseBody) { | ||
$message = curl_error($ch); | ||
$code = curl_errno($ch); | ||
|
||
curl_close($ch); | ||
|
||
throw new RuntimeException($message, $code); | ||
} | ||
|
||
$result = array( | ||
'payload' => $responseBody, | ||
'code' => curl_getinfo($ch, CURLINFO_HTTP_CODE), | ||
); | ||
|
||
curl_close($ch); | ||
|
||
return $result; | ||
} | ||
} |
Oops, something went wrong.