kernel, env, compoder, botstrap update

This commit is contained in:
2024-12-09 16:46:31 +03:00
parent 0e0bc80260
commit bfeb2d3c56
30 changed files with 926 additions and 56 deletions

View File

@ -11,6 +11,18 @@ class Html
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

View File

@ -2,13 +2,17 @@
namespace kernel\helpers;
use GuzzleHttp\Exception\GuzzleException;
use http\Client;
class RESTClient
{
public static function request(string $url, string $method = 'GET')
/**
* @throws GuzzleException
*/
public static function request(string $url, string $method = 'GET'): \Psr\Http\Message\ResponseInterface
{
$client = new \GuzzleHttp\Client();
return $client->request($method, $url, [
@ -18,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
View 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();
}
}