Добавлен LongPoll. Переработка ядра, переработка сборщика, переработка сообщений.

This commit is contained in:
RedHood
2020-09-26 20:28:13 +10:00
parent 48946d9070
commit ce92d44b8b
15 changed files with 1497 additions and 1079 deletions

View File

@@ -4,27 +4,34 @@ declare(strict_types=1);
namespace VK;
use \VK\Loggers\Jasmo;
use \VK\Traits\Singleton;
use \VK\Traits\Registry;
use \VK\Builder,
\VK\Loggers\Jasmo,
\VK\Traits\Singleton,
\VK\Traits\Registry,
\VK\Robots\RobotAbstract;
/**
* Ядро фреймворка для работы с VK API
* Ядро
*
* @property int $robots Количество роботов
* @property string $timezone Временная зона (журналирование)
* @property array $path Пути (архитектура проекта)
*
* @method protected static function __construct() Инициализация
* @method public static function init() Запуск инициализации или получение инстанции
* @method public public function build() Сборщик
* @method public function set($id, $value) Запись в реестр
* @method public function get($id = null) Чтение из реестра
*
* @package VK
*
* @property int robots Количество роботов
*
* @method build(...$params) Инициализация сборщика
*
* @author Arsen Mirzaev
* @author Арсен Мирзаев <red@hood.su>
*/
class Core
{
use Singleton, Registry {
Singleton::__construct insteadof Registry;
}
/**
* Количество роботов
*
@@ -32,7 +39,7 @@ class Core
*
* @var int
*/
public static int $robots = 0;
public int $robots = 0;
/**
* Временная зона
@@ -41,7 +48,7 @@ class Core
*
* @var string
*/
public static string $timezone = 'Europe/Moscow';
public string $timezone = 'Europe/Moscow';
/**
* Пути
@@ -50,39 +57,52 @@ class Core
*
* @var array
*/
public static array $path = [
public array $path = [
'root' => '',
'log' => ''
'logs' => './logs',
'temp' => './temp'
];
protected function __construct() {
self::$path = [
'root' => dirname(__DIR__) . '..',
'log' => self::$path['root'] . '/log'
];
/**
* Инициализация
*
* @see Singleton->__construct() Внимание на protected
*/
protected function __construct()
{
$this->path['root'] = $root = dirname(__DIR__);
$this->path['logs'] = $root . '/logs';
$this->path['temp'] = $root . '/temp';
}
/**
* Инициализация сборщика
* Сборщик
*
* @return Builder
*/
public function build(): Builder
{
return new Builder();
return new Builder($this);
}
/**
* Активация журналирования
* Запись в реестр
*
* @return Core
* Модификация наследуемого метода
*
* @todo Добавить установку иного журналиста по спецификации PSR-3
* @param mixed $id
* @param mixed $robot
*
* @return void
*/
public function log($file = null): Core
public static function set(int $id, RobotAbstract $robot): bool
{
Jasmo::init()::post($file)::postErrorHandler()::postShutdownHandler();
if (empty(self::$registry[$id])) {
self::$registry[$id] = [];
}
return $this;
array_push(self::$registry[$id], $robot);
return true;
}
}