mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Removed ely/email-renderer package and implemented new emails renderer client [skip ci]
This commit is contained in:
59
common/components/EmailsRenderer/Api.php
Normal file
59
common/components/EmailsRenderer/Api.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace common\components\EmailsRenderer;
|
||||
|
||||
use GuzzleHttp\Client as GuzzleClient;
|
||||
use GuzzleHttp\ClientInterface;
|
||||
|
||||
class Api {
|
||||
|
||||
private $baseUrl;
|
||||
|
||||
/**
|
||||
* @var ClientInterface
|
||||
*/
|
||||
private $client;
|
||||
|
||||
public function __construct(string $baseUrl) {
|
||||
$this->baseUrl = $baseUrl;
|
||||
}
|
||||
|
||||
public function setClient(ClientInterface $client): void {
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \common\components\EmailsRenderer\Request\TemplateRequest $request
|
||||
*
|
||||
* @return string
|
||||
* @throws \GuzzleHttp\Exception\GuzzleException
|
||||
*/
|
||||
public function getTemplate(Request\TemplateRequest $request): string {
|
||||
return $this->getClient()
|
||||
->request('GET', "/templates/{$request->getLocale()}/{$request->getName()}", [
|
||||
'query' => $request->getParams(),
|
||||
])
|
||||
->getBody()
|
||||
->getContents();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ClientInterface
|
||||
*/
|
||||
protected function getClient(): ClientInterface {
|
||||
if ($this->client === null) {
|
||||
$this->client = $this->createDefaultClient();
|
||||
}
|
||||
|
||||
return $this->client;
|
||||
}
|
||||
|
||||
private function createDefaultClient(): ClientInterface {
|
||||
return new GuzzleClient([
|
||||
'timeout' => 5,
|
||||
'base_uri' => $this->baseUrl,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user