kernel update
This commit is contained in:
42
kernel/helpers/Html.php
Normal file
42
kernel/helpers/Html.php
Normal file
@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\helpers;
|
||||
|
||||
class Html
|
||||
{
|
||||
|
||||
public static function img(string $src, array $params = [])
|
||||
{
|
||||
$paramsStr = self::createParams($params);
|
||||
return "<img src='$src' $paramsStr>";
|
||||
}
|
||||
|
||||
public static function h(string|int $type = 1, string $title = '', array $params = [])
|
||||
{
|
||||
$paramsStr = self::createParams($params);
|
||||
return "<h$type $paramsStr>$title</h$type>";
|
||||
}
|
||||
|
||||
public static function a(string $link, array $params = []): string
|
||||
{
|
||||
$paramsStr = self::createParams($params);
|
||||
return "<a href='$link' $paramsStr>";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
* @return string
|
||||
*/
|
||||
public static function createParams(array $data = []): string
|
||||
{
|
||||
$paramsString = "";
|
||||
foreach($data as $key => $param){
|
||||
if(is_string($param)){
|
||||
$paramsString .= $key . "='" . $param . "'";
|
||||
}
|
||||
}
|
||||
|
||||
return $paramsString;
|
||||
}
|
||||
|
||||
}
|
@ -22,4 +22,31 @@ class RESTClient
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function request_without_auth(string $url, string $method = 'GET'): \Psr\Http\Message\ResponseInterface
|
||||
{
|
||||
$client = new \GuzzleHttp\Client();
|
||||
return $client->request($method, $url);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public static function post(string $url, array $data = [], bool $auth = true): \Psr\Http\Message\ResponseInterface
|
||||
{
|
||||
$headers = [];
|
||||
if ($auth){
|
||||
$headers = [
|
||||
'Authorization' => 'Bearer ' . $_ENV['MODULE_SHOP_TOKEN']
|
||||
];
|
||||
}
|
||||
$client = new \GuzzleHttp\Client();
|
||||
return $client->request("POST", $url, [
|
||||
'form_params' => $data,
|
||||
'headers' => $headers,
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
40
kernel/helpers/SMTP.php
Normal file
40
kernel/helpers/SMTP.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace kernel\helpers;
|
||||
|
||||
use PHPMailer\PHPMailer\Exception;
|
||||
use PHPMailer\PHPMailer\PHPMailer;
|
||||
|
||||
class SMTP
|
||||
{
|
||||
public PHPMailer $mail;
|
||||
public function __construct()
|
||||
{
|
||||
$this->mail = new PHPMailer(true);
|
||||
$this->mail->CharSet = 'UTF-8';
|
||||
$this->mail->isSMTP();
|
||||
$this->mail->SMTPAuth = true;
|
||||
$this->mail->SMTPDebug = 0;
|
||||
$this->mail->Host = $_ENV['MAIL_SMTP_HOST'];
|
||||
$this->mail->Port = $_ENV['MAIL_SMTP_PORT'];
|
||||
$this->mail->Username = $_ENV['MAIL_SMTP_USERNAME'];
|
||||
$this->mail->Password = $_ENV['MAIL_SMTP_PASSWORD'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function send_html(array $params)
|
||||
{
|
||||
if (!isset($params['address'])){
|
||||
return false;
|
||||
}
|
||||
$this->mail->setFrom($this->mail->Username, $params['from_name'] ?? $this->mail->Host);
|
||||
$this->mail->addAddress($params['address']);
|
||||
$this->mail->Subject = $params['subject'] ?? 'Без темы';
|
||||
$body = $params['body'] ?? 'Нет информации';
|
||||
$this->mail->msgHTML($body);
|
||||
|
||||
$this->mail->send();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user