72 lines
2.1 KiB
PHP
72 lines
2.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Providers;
|
|
|
|
use GuzzleHttp\Psr7\Uri;
|
|
use Illuminate\Foundation\Application;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\ServiceProvider;
|
|
use Psr\Log\LoggerInterface;
|
|
use Uwil\ArcadiaApiPhpClient\ArcadiaApiClient;
|
|
use Uwil\ArcadiaApiPhpClient\Auth\ClientIdentifier;
|
|
use Uwil\ArcadiaApiPhpClient\Auth\ClientSecret;
|
|
use Uwil\ArcadiaApiPhpClient\Lib\ApiConfig;
|
|
use Uwil\ArcadiaApiPhpClient\Service\EmployeeService as LibEmployeeService;
|
|
use Uwil\ArcadiaApiPhpClient\Service\IncoService as LibIncoService;
|
|
|
|
class ArcadiaApiProvider extends ServiceProvider
|
|
{
|
|
/**
|
|
* Register any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
#[\Override]
|
|
public function register()
|
|
{
|
|
$this->app->singleton(
|
|
ApiConfig::class,
|
|
fn (Application $app) => $this->apiConfig($app->make(LoggerInterface::class))
|
|
);
|
|
$this->app->singleton(
|
|
LibEmployeeService::class,
|
|
fn (Application $app) => $app->make(ArcadiaApiClient::class)->employees()
|
|
);
|
|
$this->app->singleton(
|
|
LibIncoService::class,
|
|
fn (Application $app) => $app->make(ArcadiaApiClient::class)->incoSheets()
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Bootstrap any application services.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function boot()
|
|
{
|
|
}
|
|
|
|
private function apiConfig(LoggerInterface $logger): ApiConfig
|
|
{
|
|
$endpoint = new Uri(Config::string('services.arcadia_api.endpoint'));
|
|
$clientIdentifier = new ClientIdentifier(
|
|
Config::string('services.arcadia_api.api_key')
|
|
);
|
|
$clientSecret = new ClientSecret(
|
|
Config::string('services.arcadia_api.api_secret')
|
|
);
|
|
|
|
$ignoreSelfSignedCert = Config::boolean('services.arcadia_api.ignore_self_signed_cert', true);
|
|
|
|
return new ApiConfig(
|
|
endpoint: $endpoint,
|
|
apiKey: $clientIdentifier,
|
|
secret: $clientSecret,
|
|
ignoreSelfSignedCert: $ignoreSelfSignedCert,
|
|
logger: $logger
|
|
);
|
|
}
|
|
}
|