56 lines
1.4 KiB
PHP
56 lines
1.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Lib;
|
||
|
|
|
||
|
|
use App\Exceptions\CafelApiException;
|
||
|
|
|
||
|
|
class CafelApi
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* The api endpoint url
|
||
|
|
*
|
||
|
|
* @var string
|
||
|
|
*/
|
||
|
|
protected static $endpoint;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The api user
|
||
|
|
*
|
||
|
|
* @var string
|
||
|
|
*/
|
||
|
|
protected static $user;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* The api user password
|
||
|
|
*
|
||
|
|
* @var string
|
||
|
|
*/
|
||
|
|
protected static $password;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* CafelApi
|
||
|
|
*
|
||
|
|
* @param string|null $endpoint The api endpoint url.
|
||
|
|
* @param string|null $user The api user.
|
||
|
|
* @param string|null $password The api password.
|
||
|
|
* @throws CafelApiException If cafel.user, cafel.password or
|
||
|
|
* cafel.endpoint is missing on .env file or in laravel config.
|
||
|
|
*/
|
||
|
|
public function __construct(string $endpoint = null, string $user = null, string $password = null)
|
||
|
|
{
|
||
|
|
self::$endpoint = self::$endpoint ?: $endpoint;
|
||
|
|
self::$user = self::$user ?: $user;
|
||
|
|
self::$password = self::$password ?: $password;
|
||
|
|
|
||
|
|
static::$user = static::$user ?: config('cafel.user');
|
||
|
|
static::$password = static::$password ?: config('cafel.password');
|
||
|
|
static::$endpoint = static::$endpoint ?: config('cafel.endpoint');
|
||
|
|
|
||
|
|
if (!self::$user or !self::$password or !self::$endpoint) {
|
||
|
|
throw new CafelApiException(
|
||
|
|
'Either config or .env file need to have the token var set (cafel.user, cafel.password, cafel.endpoint)'
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|