Compare commits
4 Commits
4b0a1a1c34
...
b7e26f01ca
Author | SHA1 | Date | |
---|---|---|---|
Arsen Mirzaev Tatyano-Muradovich | b7e26f01ca | ||
Arsen Mirzaev Tatyano-Muradovich | 0b236a672c | ||
Arsen Mirzaev Tatyano-Muradovich | e2e5635cd3 | ||
Arsen Mirzaev Tatyano-Muradovich | 4fc8e011d0 |
|
@ -1,30 +1,37 @@
|
|||
{
|
||||
"name": "mirzaev/accounts",
|
||||
"type": "library",
|
||||
"description": "Менеджер аккаунтов",
|
||||
"description": "Simple accounts manager",
|
||||
"readme": "README.md",
|
||||
"keywords": [
|
||||
"accounts"
|
||||
],
|
||||
"homepage": "https://git.hood.su/mirzaev/accounts",
|
||||
"homepage": "https://git.mirzaev.sexy/mirzaev/accounts",
|
||||
"license": "WTFPL",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Arsen Mirzaev",
|
||||
"email": "red@hood.su",
|
||||
"homepage": "https://hood.su/sex",
|
||||
"name": "Arsen Mirzaev Tatyano-Muradovich",
|
||||
"email": "arsen@mirzaev.sexy",
|
||||
"homepage": "https://mirzaev.sexy",
|
||||
"role": "Programmer"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"docs": "https://git.hood.su/mirzaev/accounts/manual",
|
||||
"issues": "https://git.hood.su/mirzaev/accounts/issues",
|
||||
"chat": "https://vk.me/darkweb228"
|
||||
"email": "arsen@mirzaev.sexy",
|
||||
"wiki": "https://git.mirzaev.sexy/mirzaev/accounts/wiki",
|
||||
"issues": "https://git.mirzaev.sexy/mirzaev/accounts/issues"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"type": "funding",
|
||||
"url": "https://fund.mirzaev.sexy"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "~8.0",
|
||||
"php": "~8.1",
|
||||
"ext-dom": "20031129",
|
||||
"ext-libxml": "~8.0",
|
||||
"guzzlehttp/guzzle": "~7.2"
|
||||
"ext-libxml": "^7.4",
|
||||
"guzzlehttp/guzzle": "^7.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpdocumentor/phpdocumentor": ">=2.9",
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,161 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace hood\accounts;
|
||||
|
||||
use GuzzleHttp\Client as guzzle;
|
||||
use GuzzleHttp\Cookie\FileCookieJar;
|
||||
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Аккаунт
|
||||
*
|
||||
* @package hood\accounts
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
abstract class account
|
||||
{
|
||||
/**
|
||||
* @var guzzle $browser Браузер
|
||||
*/
|
||||
protected guzzle $browser;
|
||||
|
||||
/**
|
||||
* @var bool $ssl SSL-протокол
|
||||
*/
|
||||
protected bool $ssl = true;
|
||||
|
||||
/**
|
||||
* Конструктор
|
||||
*
|
||||
* @var int $id Идентификатор
|
||||
* @var string $path Корневой каталог аккаунтов
|
||||
*/
|
||||
public function __construct(
|
||||
protected int $id,
|
||||
protected string $path = __DIR__ . DIRECTORY_SEPARATOR . 'accounts'
|
||||
) {
|
||||
// Инициализация
|
||||
$this->path($path . DIRECTORY_SEPARATOR . $id);
|
||||
$this->browser();
|
||||
}
|
||||
|
||||
/**
|
||||
* Деструктор
|
||||
*
|
||||
* @todo Разработать
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
// Деаутентификация
|
||||
// $this->deauth();
|
||||
}
|
||||
|
||||
/**
|
||||
* Инициализация браузера
|
||||
*/
|
||||
protected function browser(): guzzle
|
||||
{
|
||||
return isset($this->path, $this->ssl) ? $this->browser = new guzzle([
|
||||
'verify' => $this->ssl,
|
||||
'cookies' => (new FileCookieJar($this->path . DIRECTORY_SEPARATOR . 'cookie.txt'))
|
||||
]) : throw new Exception('Не удалось записать браузер');
|
||||
}
|
||||
|
||||
/**
|
||||
* Инициализация директории пользователя
|
||||
*
|
||||
* @param string $path Путь к директории
|
||||
*/
|
||||
protected function path(string $path): string
|
||||
{
|
||||
// Инициализация директории
|
||||
if (file_exists($this->path = $path) || mkdir($this->path, 0775, true)) {
|
||||
return $this->path;
|
||||
}
|
||||
|
||||
throw new Exception('Не удалось записать путь к директории');
|
||||
}
|
||||
|
||||
/**
|
||||
* Запись свойства
|
||||
*
|
||||
* @param string $name Название
|
||||
* @param mixed $value Значение
|
||||
*/
|
||||
public function __set(string $name, mixed $value): void
|
||||
{
|
||||
match ($name) {
|
||||
'id' => match (false) {
|
||||
isset($this->id) => $this->id = $value,
|
||||
default => throw new Exception('Запрещено перезаписывать идентификатор')
|
||||
},
|
||||
'browser' => match (false) {
|
||||
isset($this->browser) => $this->browser = $value,
|
||||
default => throw new Exception('Запрещено перезаписывать браузер')
|
||||
},
|
||||
'path' => match (false) {
|
||||
isset($this->path) => $this->path($value),
|
||||
default => throw new Exception('Запрещено перезаписывать путь к директории')
|
||||
},
|
||||
'ssl' => $this->ssl = $value,
|
||||
default => throw new Exception('Не найдено: ' . $name, 404)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Чтение свойства
|
||||
*
|
||||
* @param string $name Название
|
||||
*/
|
||||
public function __get(string $name): mixed
|
||||
{
|
||||
return match ($name) {
|
||||
'id' => $this->id,
|
||||
'browser' => $this->browser,
|
||||
'path' => $this->path,
|
||||
'ssl' => $this->ssl,
|
||||
default => throw new Exception('Не найдено: ' . $name, 404)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверка инициализации
|
||||
*
|
||||
* @param mixed $name Название
|
||||
*/
|
||||
public function __isset(string $name): bool
|
||||
{
|
||||
return match ($name) {
|
||||
'id' => isset($this->id),
|
||||
'browser' => isset($this->browser),
|
||||
'path' => isset($this->path),
|
||||
'ssl' => isset($this->ssl),
|
||||
default => false
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Удаление свойства
|
||||
*
|
||||
* @param mixed $name Название
|
||||
*/
|
||||
public function __unset(string $name): void
|
||||
{
|
||||
match ($name) {
|
||||
'id' => throw new Exception('Запрещено деинициализировать идентификатор'),
|
||||
'browser' => function () {
|
||||
unset($this->browser);
|
||||
},
|
||||
'path' => function () {
|
||||
unset($this->path);
|
||||
},
|
||||
'ssl' => function () {
|
||||
unset($this->ssl);
|
||||
},
|
||||
default => null
|
||||
};
|
||||
}
|
||||
}
|
|
@ -4,13 +4,14 @@ declare(strict_types=1);
|
|||
|
||||
namespace mirzaev\accounts;
|
||||
|
||||
// Браузер
|
||||
use GuzzleHttp\Client as browser;
|
||||
|
||||
/**
|
||||
* Аккаунт
|
||||
*
|
||||
* @package mirzaev\accounts
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <red@hood.su>
|
||||
* @author Arsen Mirzaev Tatyano-Muradovich <arsen@mirzaev.sexy>
|
||||
*/
|
||||
class account
|
||||
{
|
||||
|
@ -29,7 +30,6 @@ class account
|
|||
*/
|
||||
protected string $path;
|
||||
|
||||
|
||||
/**
|
||||
* Конструктор
|
||||
*
|
||||
|
|
|
@ -5,7 +5,7 @@ declare(strict_types=1);
|
|||
namespace mirzaev\accounts\auth;
|
||||
|
||||
/**
|
||||
* Базовая авторизация
|
||||
* Базовая аутентификация
|
||||
*/
|
||||
interface basic
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue