Добавлен LongPoll. Переработка ядра, переработка сборщика, переработка сообщений.
This commit is contained in:
@@ -4,118 +4,108 @@ declare(strict_types=1);
|
||||
|
||||
namespace VK;
|
||||
|
||||
use \Exception;
|
||||
use \VK\Core;
|
||||
use \VK\BuildAbstract;
|
||||
use \VK\Robots\RobotAbstract;
|
||||
use \VK\Robots\Group;
|
||||
use \VK\Robots\User;
|
||||
use \VK\Browsers\BrowserAbstract;
|
||||
use \VK\Proxies\ProxyAbstract;
|
||||
use \VK\Captchas\CaptchaAbstract;
|
||||
use \VK\Loggers\Jasmo;
|
||||
use \VK\Core,
|
||||
\VK\Robots\RobotAbstract,
|
||||
\VK\Robots\Group,
|
||||
\VK\Robots\User,
|
||||
\VK\Loggers\Jasmo;
|
||||
|
||||
/**
|
||||
* Сборщик
|
||||
*
|
||||
* @package Builder
|
||||
* @property Core $core Ядро
|
||||
*
|
||||
* @method public group() Создание робота-группы
|
||||
* @method public user() Создание робота-пользователя
|
||||
* @method public function __construct(Core $core = null) Инициализация
|
||||
* @method public function group() Создание робота-группы
|
||||
* @method public function user() Создание робота-пользователя
|
||||
* @method private function reg() Регистрация в ядре
|
||||
* @method public function log(string $file = null) Журналирование
|
||||
*
|
||||
* @method private reg() Регистрация в ядре
|
||||
*
|
||||
* @author Arsen Mirzaev
|
||||
* @package VK\Builder
|
||||
* @author Arsen Mirzaev <red@hood.su>
|
||||
*/
|
||||
class Builder
|
||||
{
|
||||
public function __construct()
|
||||
/**
|
||||
* Инициализация
|
||||
*
|
||||
* @param Core $core Ядро
|
||||
*/
|
||||
public function __construct(Core $core = null)
|
||||
{
|
||||
return $this;
|
||||
if (isset($core)) {
|
||||
$this->core = $core::init();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Создание робота-группы
|
||||
*
|
||||
* @param int $id Идентификатор
|
||||
*
|
||||
* @return Group
|
||||
*/
|
||||
public function group(): Group
|
||||
public function group(int $id): Group
|
||||
{
|
||||
return $this->reg(new \VK\Robots\Group());
|
||||
// Создание робота
|
||||
$robot = new Group();
|
||||
|
||||
// Идентификатор
|
||||
$robot->id = $id;
|
||||
|
||||
// Сессия
|
||||
$robot->session = isset($this->core) ? count($this->core->get($id)) : 0;
|
||||
|
||||
return isset($this->core) ? $this->reg($robot) : $robot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Создание робота-пользователя
|
||||
*
|
||||
* @param int $id Идентификатор
|
||||
*
|
||||
* @return User
|
||||
*/
|
||||
public function user(): User
|
||||
{
|
||||
return $this->reg(new \VK\Robots\User());
|
||||
return $this->reg(new User());
|
||||
}
|
||||
|
||||
/**
|
||||
* Регистрация в ядре
|
||||
*
|
||||
* @param RobotAbstract $robot Регистрируемый робот
|
||||
*
|
||||
* @return RobotAbstract
|
||||
*
|
||||
* @todo Добавить создание нового процесса (многопоточность)
|
||||
*/
|
||||
private function reg(RobotAbstract $robot): RobotAbstract
|
||||
{
|
||||
// Присвоение идентификатора
|
||||
$robot->id = ++Core::$robots;
|
||||
|
||||
// Регистрация в ядре
|
||||
Core::set($robot->id, $robot);
|
||||
$this->core->set((int) $robot->id, $robot);
|
||||
|
||||
// Количество роботов
|
||||
++$this->core->robots;
|
||||
|
||||
return $robot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Установка журналирования
|
||||
* Журналирование
|
||||
*
|
||||
* @return RobotAbstract
|
||||
* @param string $file Файл для журналирования
|
||||
*
|
||||
* @return Builder
|
||||
*
|
||||
* @todo Добавить установку иного журналиста по спецификации PSR-3
|
||||
* @todo Более гибкое журналирование
|
||||
*/
|
||||
public function log($file = null): Builder
|
||||
public function log(string $file = null): Builder
|
||||
{
|
||||
// Инициализация журналиста (требует переработки)
|
||||
Jasmo::init()::post($file)::postErrorHandler()::postShutdownHandler();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Установка браузера
|
||||
*
|
||||
* @return RobotAbstract
|
||||
*/
|
||||
public function browser(BrowserAbstract $browser): Builder
|
||||
{
|
||||
$this->browser = $browser;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Установка прокси
|
||||
*
|
||||
* @return RobotAbstract
|
||||
*/
|
||||
public function proxy(ProxyAbstract $proxy): Builder
|
||||
{
|
||||
$this->proxy = $proxy;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Установка обработчика капч
|
||||
*
|
||||
* @return RobotAbstract
|
||||
*/
|
||||
public function captcha(CaptchaAbstract $captcha): Builder
|
||||
{
|
||||
$this->captcha = $captcha;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user