This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1,912 changed files
with
257,109 additions
and
5,252 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
exclude: | ||
- /vendor/.* | ||
- /Public/Assets/.* | ||
component_depth: 1 | ||
languages: | ||
- php |
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,9 @@ | ||
<?php | ||
/* Autoload */ | ||
define('ROOT_PATH', ''); | ||
define('NIL_INT', -1); | ||
define('NIL_INT', -1); | ||
define('DS', DIRECTORY_SEPARATOR); | ||
define('_PHP_CONGES', 1); | ||
define('API_SYSPATH', DS . 'tmp' . DS); | ||
define('API_PATH', ''); | ||
require_once ROOT_PATH . 'vendor/autoload.php'; |
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 |
---|---|---|
@@ -1,9 +1,7 @@ | ||
language: php | ||
php: | ||
- '5.5' | ||
- '5.6' | ||
- '7.0' | ||
notifications: | ||
irc: "irc.tuxfamily.org#Libertempo" | ||
before_script: composer require atoum/atoum | ||
script: vendor/bin/atoum |
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,6 @@ | ||
<?php | ||
namespace App\Exceptions; | ||
|
||
class NotFoundException extends \Exception | ||
{ | ||
} |
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,147 @@ | ||
<?php | ||
namespace App\Libraries; | ||
|
||
use GuzzleHttp\ClientInterface; | ||
use GuzzleHttp\Psr7; | ||
use GuzzleHttp\Exception; | ||
|
||
/** | ||
* Classe de consommation de l'API ; is immutable | ||
* | ||
* @author Prytoegrian <[email protected]> | ||
* @author Wouldsmina | ||
* @since 1.9 | ||
*/ | ||
final class ApiClient | ||
{ | ||
/** | ||
* @var ClientInterface Client de la requête | ||
*/ | ||
private $client; | ||
|
||
/** | ||
* @param ClientInterface $client Client de la requête | ||
* | ||
* @throws \RuntimeException if infrastructure pre-conditions aren't fulfilled | ||
*/ | ||
public function __construct(ClientInterface $client) | ||
{ | ||
if (!extension_loaded('curl')) { | ||
if (false === ini_set('allow_url_fopen', true)) { | ||
throw new \RuntimeException('cURL or allow_url_fopen are required'); | ||
} | ||
} | ||
$this->client = $client; | ||
} | ||
|
||
/** | ||
* Effectue l'ordre Http GET | ||
* | ||
* @param string $uri URI relative de la ressource | ||
* | ||
* @return \stdClass Au format Jsend | ||
*/ | ||
public function get($uri) | ||
{ | ||
return $this->request('GET', $uri, []); | ||
} | ||
|
||
/** | ||
* Récupère un token de l'API avec le connecteur DBConges | ||
* | ||
* @param string $login Login de l'utilisateur LT | ||
* @param string $password MDP de l'utilisateur LT | ||
* | ||
* @return \stdClass Au format Jsend | ||
*/ | ||
public function authentifyDbConges($login, $password) | ||
{ | ||
return $this->authentifyCommon($login, $password); | ||
} | ||
|
||
/** | ||
* Récupère un token de l'API avec le connecteur tierce | ||
* | ||
* @param string $login Login de l'utilisateur LT | ||
* | ||
* @return \stdClass Au format Jsend | ||
*/ | ||
public function authentifyThirdParty($login) | ||
{ | ||
return $this->authentifyCommon($login, 'none'); | ||
} | ||
|
||
/** | ||
* Récupère un token de l'API pour les futurs échanges | ||
* | ||
* @param string $login Login de l'utilisateur LT | ||
* @param string $password MDP de l'utilisateur LT | ||
* | ||
* @return \stdClass Au format Jsend | ||
*/ | ||
private function authentifyCommon($login, $password) | ||
{ | ||
$options = [ | ||
'headers' => [ | ||
'Authorization' => 'Basic ' . base64_encode($login . ':' . $password), | ||
], | ||
]; | ||
return $this->request('GET', 'authentification', $options); | ||
} | ||
|
||
/** | ||
* Effectue une requête HTTP | ||
* | ||
* @param string $method Ordre HTTP | ||
* @param string $uri URI relative de la ressource | ||
* @param array $options Options de requête | ||
* @example ['headers' => [], 'body' => []] | ||
* | ||
* @return \stdClass Au format Jsend | ||
* @throws \LogicException Si la requête est mal formée (Http4XX) | ||
*/ | ||
private function request($method, $uri, array $options) | ||
{ | ||
$json = 'application/json'; | ||
$options = array_merge_recursive($options, [ | ||
'headers' => [ | ||
'Content-Type' => $json, | ||
'Accept' => $json, | ||
], | ||
]); | ||
try { | ||
$response = $this->client->request($method, $uri, $options); | ||
} catch (Exception\ServerException $e) { | ||
throw new \RuntimeException('Erreur serveur : '. $this->formatError($e)); | ||
} catch (Exception\ClientException $e) { | ||
throw new \LogicException('Erreur client : '. $this->formatError($e)); | ||
} | ||
|
||
$body = json_decode($response->getBody(), false); | ||
if (null === $body) { | ||
throw new \RuntimeException('La réponse n\'est pas du JSON'); | ||
} | ||
|
||
return $body; | ||
} | ||
|
||
/** | ||
* Formate les erreurs pour afficher les informations nécessaires à la correction | ||
* | ||
* @param \Exception $exception | ||
* | ||
* @return string | ||
*/ | ||
private function formatError(\Exception $exception) | ||
{ | ||
return 'Request -> ' . Psr7\str($exception->getRequest()) . ' | Response <- ' . Psr7\str($exception->getResponse()); | ||
} | ||
|
||
/** | ||
* Clonage interdit | ||
*/ | ||
public function __clone() | ||
{ | ||
throw new \LogicException('Clonage interdit'); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.