diff --git a/composer.lock b/composer.lock index c82233f..09f5044 100644 --- a/composer.lock +++ b/composer.lock @@ -8,22 +8,22 @@ "packages": [ { "name": "guzzlehttp/guzzle", - "version": "7.2.0", + "version": "7.3.0", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "0aa74dfb41ae110835923ef10a9d803a22d50e79" + "reference": "7008573787b430c1c1f650e3722d9bba59967628" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/0aa74dfb41ae110835923ef10a9d803a22d50e79", - "reference": "0aa74dfb41ae110835923ef10a9d803a22d50e79", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/7008573787b430c1c1f650e3722d9bba59967628", + "reference": "7008573787b430c1c1f650e3722d9bba59967628", "shasum": "" }, "require": { "ext-json": "*", "guzzlehttp/promises": "^1.4", - "guzzlehttp/psr7": "^1.7", + "guzzlehttp/psr7": "^1.7 || ^2.0", "php": "^7.2.5 || ^8.0", "psr/http-client": "^1.0" }, @@ -31,6 +31,7 @@ "psr/http-client-implementation": "1.0" }, "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", "ext-curl": "*", "php-http/client-integration-tests": "^3.0", "phpunit/phpunit": "^8.5.5 || ^9.3.5", @@ -44,7 +45,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "7.1-dev" + "dev-master": "7.3-dev" } }, "autoload": { @@ -84,6 +85,10 @@ "rest", "web service" ], + "support": { + "issues": "https://github.com/guzzle/guzzle/issues", + "source": "https://github.com/guzzle/guzzle/tree/7.3.0" + }, "funding": [ { "url": "https://github.com/GrahamCampbell", @@ -102,7 +107,7 @@ "type": "github" } ], - "time": "2020-10-10T11:47:56+00:00" + "time": "2021-03-23T11:33:13+00:00" }, { "name": "guzzlehttp/promises", @@ -153,20 +158,24 @@ "keywords": [ "promise" ], + "support": { + "issues": "https://github.com/guzzle/promises/issues", + "source": "https://github.com/guzzle/promises/tree/1.4.1" + }, "time": "2021-03-07T09:25:29+00:00" }, { "name": "guzzlehttp/psr7", - "version": "1.7.0", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "53330f47520498c0ae1f61f7e2c90f55690c06a3" + "reference": "35ea11d335fd638b5882ff1725228b3d35496ab1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/53330f47520498c0ae1f61f7e2c90f55690c06a3", - "reference": "53330f47520498c0ae1f61f7e2c90f55690c06a3", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/35ea11d335fd638b5882ff1725228b3d35496ab1", + "reference": "35ea11d335fd638b5882ff1725228b3d35496ab1", "shasum": "" }, "require": { @@ -224,7 +233,11 @@ "uri", "url" ], - "time": "2020-09-30T07:37:11+00:00" + "support": { + "issues": "https://github.com/guzzle/psr7/issues", + "source": "https://github.com/guzzle/psr7/tree/1.8.1" + }, + "time": "2021-03-21T16:25:00+00:00" }, { "name": "hood/accounts", @@ -268,6 +281,11 @@ "hood", "vk" ], + "support": { + "chat": "https://vk.me/darkweb228", + "docs": "https://git.hood.su/hood/accounts/manual", + "issues": "https://git.hood.su/hood/accounts/issues" + }, "funding": [ { "url": "https://git.hood.su/hood/accounts/thanks", @@ -322,6 +340,10 @@ "exception handler", "middleware" ], + "support": { + "issues": "https://github.com/jasny/error-handler/issues", + "source": "https://github.com/jasny/error-handler" + }, "abandoned": true, "time": "2017-01-25T01:27:18+00:00" }, @@ -395,6 +417,10 @@ "logging", "psr-3" ], + "support": { + "issues": "https://github.com/Seldaek/monolog/issues", + "source": "https://github.com/Seldaek/monolog/tree/1.26.0" + }, "funding": [ { "url": "https://github.com/Seldaek", @@ -454,6 +480,9 @@ "psr", "psr-18" ], + "support": { + "source": "https://github.com/php-fig/http-client/tree/master" + }, "time": "2020-06-29T06:28:15+00:00" }, { @@ -504,6 +533,9 @@ "request", "response" ], + "support": { + "source": "https://github.com/php-fig/http-message/tree/master" + }, "time": "2016-08-06T14:39:51+00:00" }, { @@ -551,6 +583,9 @@ "psr", "psr-3" ], + "support": { + "source": "https://github.com/php-fig/log/tree/1.1.3" + }, "time": "2020-03-23T09:12:05+00:00" }, { @@ -591,6 +626,10 @@ } ], "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, "time": "2019-03-08T08:55:37+00:00" } ], @@ -644,6 +683,10 @@ "constructor", "instantiate" ], + "support": { + "issues": "https://github.com/doctrine/instantiator/issues", + "source": "https://github.com/doctrine/instantiator/tree/1.4.0" + }, "funding": [ { "url": "https://www.doctrine-project.org/sponsorship.html", @@ -706,6 +749,10 @@ "object", "object graph" ], + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.10.2" + }, "funding": [ { "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", @@ -764,6 +811,10 @@ "parser", "php" ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v4.10.4" + }, "time": "2020-12-20T10:01:03+00:00" }, { @@ -820,6 +871,10 @@ } ], "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "support": { + "issues": "https://github.com/phar-io/manifest/issues", + "source": "https://github.com/phar-io/manifest/tree/master" + }, "time": "2020-06-27T14:33:11+00:00" }, { @@ -867,6 +922,10 @@ } ], "description": "Library for handling version information and constraints", + "support": { + "issues": "https://github.com/phar-io/version/issues", + "source": "https://github.com/phar-io/version/tree/3.1.0" + }, "time": "2021-02-23T14:00:09+00:00" }, { @@ -916,6 +975,10 @@ "reflection", "static analysis" ], + "support": { + "issues": "https://github.com/phpDocumentor/ReflectionCommon/issues", + "source": "https://github.com/phpDocumentor/ReflectionCommon/tree/2.x" + }, "time": "2020-06-27T09:03:43+00:00" }, { @@ -968,6 +1031,10 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", + "support": { + "issues": "https://github.com/phpDocumentor/ReflectionDocBlock/issues", + "source": "https://github.com/phpDocumentor/ReflectionDocBlock/tree/master" + }, "time": "2020-09-03T19:13:55+00:00" }, { @@ -1013,20 +1080,24 @@ } ], "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", + "support": { + "issues": "https://github.com/phpDocumentor/TypeResolver/issues", + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.4.0" + }, "time": "2020-09-17T18:55:26+00:00" }, { "name": "phpspec/prophecy", - "version": "1.12.2", + "version": "1.13.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "245710e971a030f42e08f4912863805570f23d39" + "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/245710e971a030f42e08f4912863805570f23d39", - "reference": "245710e971a030f42e08f4912863805570f23d39", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/be1996ed8adc35c3fd795488a653f4b518be70ea", + "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea", "shasum": "" }, "require": { @@ -1076,20 +1147,24 @@ "spy", "stub" ], - "time": "2020-12-19T10:15:11+00:00" + "support": { + "issues": "https://github.com/phpspec/prophecy/issues", + "source": "https://github.com/phpspec/prophecy/tree/1.13.0" + }, + "time": "2021-03-17T13:42:18+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.5", + "version": "9.2.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "f3e026641cc91909d421802dd3ac7827ebfd97e1" + "reference": "f6293e1b30a2354e8428e004689671b83871edde" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f3e026641cc91909d421802dd3ac7827ebfd97e1", - "reference": "f3e026641cc91909d421802dd3ac7827ebfd97e1", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f6293e1b30a2354e8428e004689671b83871edde", + "reference": "f6293e1b30a2354e8428e004689671b83871edde", "shasum": "" }, "require": { @@ -1143,13 +1218,17 @@ "testing", "xunit" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.6" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", "type": "github" } ], - "time": "2020-11-28T06:44:49+00:00" + "time": "2021-03-28T07:26:59+00:00" }, { "name": "phpunit/php-file-iterator", @@ -1199,6 +1278,10 @@ "filesystem", "iterator" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/3.0.5" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1258,6 +1341,10 @@ "keywords": [ "process" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-invoker/issues", + "source": "https://github.com/sebastianbergmann/php-invoker/tree/3.1.1" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1313,6 +1400,10 @@ "keywords": [ "template" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/2.0.4" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1368,6 +1459,10 @@ "keywords": [ "timer" ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "source": "https://github.com/sebastianbergmann/php-timer/tree/5.0.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1378,16 +1473,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.2", + "version": "9.5.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "f661659747f2f87f9e72095bb207bceb0f151cb4" + "reference": "c73c6737305e779771147af66c96ca6a7ed8a741" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/f661659747f2f87f9e72095bb207bceb0f151cb4", - "reference": "f661659747f2f87f9e72095bb207bceb0f151cb4", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c73c6737305e779771147af66c96ca6a7ed8a741", + "reference": "c73c6737305e779771147af66c96ca6a7ed8a741", "shasum": "" }, "require": { @@ -1463,6 +1558,10 @@ "testing", "xunit" ], + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.4" + }, "funding": [ { "url": "https://phpunit.de/donate.html", @@ -1473,7 +1572,7 @@ "type": "github" } ], - "time": "2021-02-02T14:45:58+00:00" + "time": "2021-03-23T07:16:29+00:00" }, { "name": "sebastian/cli-parser", @@ -1519,6 +1618,10 @@ ], "description": "Library for parsing CLI options", "homepage": "https://github.com/sebastianbergmann/cli-parser", + "support": { + "issues": "https://github.com/sebastianbergmann/cli-parser/issues", + "source": "https://github.com/sebastianbergmann/cli-parser/tree/1.0.1" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1571,6 +1674,10 @@ ], "description": "Collection of value objects that represent the PHP code units", "homepage": "https://github.com/sebastianbergmann/code-unit", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit/issues", + "source": "https://github.com/sebastianbergmann/code-unit/tree/1.0.8" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1622,6 +1729,10 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/2.0.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1692,6 +1803,10 @@ "compare", "equality" ], + "support": { + "issues": "https://github.com/sebastianbergmann/comparator/issues", + "source": "https://github.com/sebastianbergmann/comparator/tree/4.0.6" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1745,6 +1860,10 @@ ], "description": "Library for calculating the complexity of PHP code units", "homepage": "https://github.com/sebastianbergmann/complexity", + "support": { + "issues": "https://github.com/sebastianbergmann/complexity/issues", + "source": "https://github.com/sebastianbergmann/complexity/tree/2.0.2" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1807,6 +1926,10 @@ "unidiff", "unified diff" ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "source": "https://github.com/sebastianbergmann/diff/tree/4.0.4" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1866,6 +1989,10 @@ "environment", "hhvm" ], + "support": { + "issues": "https://github.com/sebastianbergmann/environment/issues", + "source": "https://github.com/sebastianbergmann/environment/tree/5.1.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1939,6 +2066,10 @@ "export", "exporter" ], + "support": { + "issues": "https://github.com/sebastianbergmann/exporter/issues", + "source": "https://github.com/sebastianbergmann/exporter/tree/4.0.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -1999,6 +2130,10 @@ "keywords": [ "global state" ], + "support": { + "issues": "https://github.com/sebastianbergmann/global-state/issues", + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.2" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2052,6 +2187,10 @@ ], "description": "Library for counting the lines of code in PHP source code", "homepage": "https://github.com/sebastianbergmann/lines-of-code", + "support": { + "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/1.0.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2105,6 +2244,10 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/4.0.4" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2156,6 +2299,10 @@ ], "description": "Allows reflection of object attributes, including inherited and non-public ones", "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-reflector/issues", + "source": "https://github.com/sebastianbergmann/object-reflector/tree/2.0.4" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2215,6 +2362,10 @@ ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", + "support": { + "issues": "https://github.com/sebastianbergmann/recursion-context/issues", + "source": "https://github.com/sebastianbergmann/recursion-context/tree/4.0.4" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2266,6 +2417,10 @@ ], "description": "Provides a list of PHP built-in functions that operate on resources", "homepage": "https://www.github.com/sebastianbergmann/resource-operations", + "support": { + "issues": "https://github.com/sebastianbergmann/resource-operations/issues", + "source": "https://github.com/sebastianbergmann/resource-operations/tree/3.0.3" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2318,6 +2473,10 @@ ], "description": "Collection of value objects that represent the types of the PHP type system", "homepage": "https://github.com/sebastianbergmann/type", + "support": { + "issues": "https://github.com/sebastianbergmann/type/issues", + "source": "https://github.com/sebastianbergmann/type/tree/2.3.1" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2367,6 +2526,10 @@ ], "description": "Library that helps with managing the version number of Git-hosted PHP projects", "homepage": "https://github.com/sebastianbergmann/version", + "support": { + "issues": "https://github.com/sebastianbergmann/version/issues", + "source": "https://github.com/sebastianbergmann/version/tree/3.0.2" + }, "funding": [ { "url": "https://github.com/sebastianbergmann", @@ -2435,6 +2598,9 @@ "polyfill", "portable" ], + "support": { + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.22.1" + }, "funding": [ { "url": "https://symfony.com/sponsor", @@ -2489,6 +2655,10 @@ } ], "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "support": { + "issues": "https://github.com/theseer/tokenizer/issues", + "source": "https://github.com/theseer/tokenizer/tree/master" + }, "funding": [ { "url": "https://github.com/theseer", @@ -2549,6 +2719,10 @@ "check", "validate" ], + "support": { + "issues": "https://github.com/webmozarts/assert/issues", + "source": "https://github.com/webmozarts/assert/tree/1.10.0" + }, "time": "2021-03-09T10:59:23+00:00" } ], @@ -2563,5 +2737,5 @@ "php": "~8.0" }, "platform-dev": [], - "plugin-api-version": "1.1.0" + "plugin-api-version": "2.0.0" } diff --git a/hood/vk/system/api/api.php b/hood/vk/system/api/api.php deleted file mode 100644 index a929d1a..0000000 --- a/hood/vk/system/api/api.php +++ /dev/null @@ -1,202 +0,0 @@ -_init(); - } - } - - /** - * Инициализация (безопасная) - */ - public function init(): array - { - if (!isset($blocked)) { - // Нет блокировки (запуск в первый раз) - - // Блокировка - static $blocked = true; - - try { - $this->_init(); - } catch (Throwable $t) { - throw new Exception('Не удалось инициализировать API', $t->getCode(), $t->getPrevious()); - } - } - - return $this->settings; - } - - /** - * Реинициализация - */ - public function reinit(): array - { - // Реинициализация - //unset($this->settings); - $this->settings = []; - - try { - $this->_init(); - } catch (Throwable $t) { - throw new Exception('Не удалось инициализировать API', $t->getCode(), $t->getPrevious()); - } - - return $this->settings; - } - - /** - * Инициализация - */ - protected function _init(): void - { - // Ключ - $this->settings['access_token'] = $this->robot->key; - - // Версия API - $this->settings['v'] = $this->version; - } - - /** - * Выбрать получателя - * - * Определяет получателей по входным параметрам - * - * @see hood\vk\api\methods\messages Сообщения - */ - public function chooseDestination(string|array|int $destination): void - { - if (is_int($destination)) { - // Идентификатор - - $this->settings['peer_id'] = $destination; - } else if (is_array($destination)) { - // Идентификаторы - - $this->settings['user_ids'] = $destination; - } else { - // Домен - - $this->settings['domain'] = $destination; - } - } - - /** - * Записать свойство - * - * @param string $name Название - * @param mixed $value Значение - */ - public function __set(string $name, mixed $value): void - { - match ($name) { - 'settings' => !isset($this->settings) ? $this->settings = $value : throw new Exception('Запрещено перезаписывать настройки'), - 'robot' => !isset($this->robot) ? $this->robot = $value : throw new Exception('Запрещено перезаписывать Робота'), - default => $this->settings[$name] = $value - }; - } - - /** - * Прочитать свойство - * - * @param string $name Название - */ - public function __get(string $name): mixed - { - return match ($name) { - 'settings' => $this->settings ?? throw new Exception('Настройки не инициализированы'), - 'robot' => $this->robot, - default => $this->settings[$name] ?? throw new Exception('Параметр не найден: settings[\'' . $name . '\']') - }; - } - - /** - * Записать по смещению - */ - public function offsetSet(mixed $offset, mixed $value): void - { - if ($offset == 'settings') { - !isset($this->settings) ? $this->settings = $value : throw new Exception('Запрещено перезаписывать настройки'); - } else if (isset($this->settings)) { - $this->settings[$offset] = $value; - } else { - throw new Exception('Настройки не инициализированы'); - } - } - - /** - * Прочитать по смещению - */ - public function offsetGet(mixed $offset): mixed - { - if ($offset == 'settings' && isset($this->settings)) { - return $this->settings; - } else if (isset($this->settings)) { - if (isset($this->settings[$offset])) { - return $this->settings[$offset]; - } else { - throw new Exception('Не найдено: settings[\'' . $offset . '\']'); - } - } else { - throw new Exception('Настройки не инициализированы'); - } - } - - /** - * Проверка существования смещения - */ - public function offsetExists(mixed $offset): bool - { - if ($offset == 'settings' && isset($this->settings)) { - return isset($this->settings); - } else if (isset($this->settings)) { - return isset($this->settings[$offset]); - } else { - throw new Exception('Настройки не инициализированы'); - } - } - - /** - * Удалить по смещению - */ - public function offsetUnset(mixed $offset): void - { - if ($offset == 'settings' && isset($this->settings)) { - unset($this->settings); - } else if (isset($this->settings)) { - unset($this->settings[$offset]); - } else { - throw new Exception('Настройки не инициализированы'); - } - } -} diff --git a/hood/vk/system/api/data.php b/hood/vk/system/api/data.php deleted file mode 100644 index 79ff9a7..0000000 --- a/hood/vk/system/api/data.php +++ /dev/null @@ -1,75 +0,0 @@ -data) + count($data) > 10) { - throw new Exception('Превышен лимит вложений (10)'); - } - - // Запись вложений - $this->data = array_merge($this->data, $data); - - return $this; - } - - /** - * Очистить вложения - */ - public function clear(): self - { - // Очистка вложений - $this->data = []; - - return $this; - } - - /** - * Прочитать свойство - * - * @param string $name Название - * - * @return mixed - */ - public function __get(string $name): mixed - { - return match ($name) { - 'data' => $this->data, - default => throw new Exception('Свойство не найдено: ' . $name) - }; - } -} diff --git a/hood/vk/system/api/methods/messages.php b/hood/vk/system/api/methods/messages.php index 7ee698d..4ed11be 100644 --- a/hood/vk/system/api/methods/messages.php +++ b/hood/vk/system/api/methods/messages.php @@ -27,46 +27,43 @@ use hood\vk\robots\group; final class messages extends method { /** - * @param int $mode Режим отправки + * @var int $mode Режим отправки */ protected int $mode = 1; /** - * @param string|null $text Текст + * @var array[int] Сообщения для пересылки */ + protected array $forward; /** - * @var data Вложения + * @var int Сообщение для ответа */ - protected data $data; + protected int $reply; /** - * @var array Пересылаемые сообщения - */ - protected array $forwardMessages = []; - - /** - * @var int $ReplyMessage Ответное сообщение - */ - protected int $ReplyMessage; - - /** - * Создать сообщение + * Конструктор * * @param robot $robot Робот + * @param string|null $text Текст + * @param int|string|array $destination = null */ public function __construct( protected robot $robot, - protected string|null $text = null + protected string|null $text = null, + int|string|array $destination = null ) { + if (isset($this->text, $destination)) { + // Быстрая отправка + + $this->send($destination); + } } /** * Записать текст * * @param string $text Текст - * - * @return self */ public function text(string $text): self { @@ -81,84 +78,27 @@ final class messages extends method } /** - * Записать пересылаемые сообщения - * - * @param $messageIds id пересылаемых сообщений - * - * @return self + * Записать сообщения для пересылки + * + * @param $ids Идентификаторы сообщений */ - public function forward(...$messageIds): self + public function forward(...$ids): self { - // Запись пересылаемых сообщений - $this->forwardMessages = array_merge($this->forwardMessages, $messageIds); + // Запись + $this->forward = array_merge($this->forward ?? [], $ids); return $this; } /** - * Записать ответное сообщение - * - * @param $messageId id ответного сообщения - * - * @return self - */ - public function reply(int $messageId): self - { - // Запись ответного сообщения - $this->ReplyMessage = $messageId; - - return $this; - } - - /** - * Записать фото + * Записать сообщение для ответа * - * @param $img Фото - * - * @return self + * @param $id Идентификатор сообщения */ - public function image(...$pathPhoto): self + public function reply(int $id): self { - // Перебор фото - foreach ($pathPhoto as $photo) { - - // Загрузить фото - $id = $this->robot->photo()->getPhoto($photo); - - // Записать к вложениям - $this->attachments($id); - } - - return $this; - } - - /** - * Записать вложение - * - * @param $attachments Вложения - * - * @return self - */ - public function attachments(string ...$attachments): self - { - if (isset($this->data)) { - // Если вложения инициализированны - - // Записать вложение - foreach ($attachments as $attachment) { - $this->data->addData($attachment); - } - } else { - // Если вложения не инициализированны - - // Инициализация вложений - $this->data = new data($this->robot); - - // Записать вложение - foreach ($attachments as $attachment) { - $this->data->addData($attachment); - } - } + // Запись + $this->reply = $id; return $this; } @@ -171,8 +111,10 @@ final class messages extends method * @see https://vk.com/dev/messages.send * * @return array Ответ сервера + * + * @todo Написать обработчик ошибок возвращаемых ВКонтакте */ - public function send(int|string|array $destination): mixed + public function send(int|string|array $destination): array { // Идентификатор $random_id = time(); @@ -243,10 +185,6 @@ final class messages extends method $this->send($destination); } } else { - // Что-то придумать :) - // наверно throw new exception($request->error->error_msg) - // А стоп. Ничего не нужно, просто возвращаем объект с ошибкой, где всё будет написано - // Костя ты тупой? } } @@ -264,8 +202,7 @@ final class messages extends method public function __set(string $name, mixed $value): void { match ($name) { - 'data' => !isset($this->data) ? $this->data->addData($value) : throw new Exception('Вложения не инициализированны'), - default => throw new Exception('Свойство не найдено: ' . $name) + default => throw new Exception("Свойство $name не найдено", 404) }; } @@ -280,16 +217,15 @@ final class messages extends method { return match ($name) { 'text' => $this->text ?? throw new Exception('Текст не инициализирован'), - 'data' => isset($this->data) ? $this->data->data : throw new Exception('Вложения не инициализированны'), - 'forwardMessages' => !empty($this->forwardMessages) ? $this->forwardMessages : throw new Exception('Пересылаемые сообщения не инициализированны'), - 'ReplyMessage' => isset($this->ReplyMessage) ? $this->ReplyMessage : throw new Exception('Ответное сообщение не инициализированно'), - default => throw new Exception('Свойство не найдено: ' . $name) + 'forward' => empty($this->forward) ? throw new Exception('Сообщения для пересылки не инициализированы') : $this->forward, + 'reply' => isset($this->reply) ? $this->reply : throw new Exception('Сообщение для ответа не инициализировано'), + default => throw new Exception("Свойство $name не найдено", 404) }; } /** * Получить информацию о сообщении по id - * + * * @param string $message_ids Идентификатор сообщения * * @return object Информация о сообщении diff --git a/hood/vk/system/api/settings.php b/hood/vk/system/api/settings.php new file mode 100644 index 0000000..227aa0c --- /dev/null +++ b/hood/vk/system/api/settings.php @@ -0,0 +1,278 @@ +_init(); + } + } + + /** + * Инициализация (безопасная) + * + * @var float|null $version Версия API + */ + public function init(float|null $version = null): self + { + if (isset($blocked)) { + // Блокировка найдена + + throw new Exception('Повторная инициализация запрещена', 500); + } + + // Блокировка + static $blocked = true; + + // Инициализация + try { + $this->_init($version); + } catch (Throwable $t) { + throw new Exception('Не удалось инициализировать API', 500, $t->getPrevious()); + } + + return $this; + } + + /** + * Реинициализация + * + * @var float|null $version Версия API + */ + public function reinit(float|null $version = null): self + { + // Буфер + $version = $version ?? $this->settings['v'] ?? null; + + // Деинициализация + $this->settings = []; + + // Инициализация + try { + $this->_init($version); + } catch (Throwable $t) { + throw new Exception('Не удалось инициализировать API', 500, $t->getPrevious()); + } + + return $this; + } + + /** + * Инициализация + * + * @var float $version Версия API + */ + protected function _init(float $version = 5.124): self + { + // Ключ + $this->settings['access_token'] = $this->robot->key; + + // Версия API + $this->settings['v'] = $version; + + return $this; + } + + /** + * Записать получателя + * + * Определяет получателей по входным параметрам + * + * @see hood\vk\api\methods\messages Сообщения + */ + public function writeDestination(string|array|int $destination): void + { + if (is_int($destination)) { + // Идентификатор + + $this->settings['peer_id'] = $destination; + } else if (is_array($destination)) { + // Идентификаторы + + $this->settings['user_ids'] = $destination; + } else if (is_string($destination)) { + // Домен + + $this->settings['domain'] = $destination; + } + + throw new Exception('Не удалось определить получателя', 500); + } + + /** + * Записать свойство + * + * @param string $name Название + * @param mixed $value Значение + */ + public function __set(string $name, mixed $value): void + { + match ($name) { + 'settings' => isset($this->settings) ? throw new Exception('Запрещено перезаписывать настройки', 500) : $this->settings = $value, + 'robot' => isset($this->robot) ? throw new Exception('Запрещено перезаписывать Робота', 500) : $this->robot = $value, + 'data' => $this->offsetSet('data', $value), + 'attachments' => $this->offsetSet('attachments', $value), + default => $this->offsetSet($name, $value) + }; + } + + /** + * Прочитать свойство + * + * @param string $name Название + */ + public function __get(string $name): mixed + { + return match ($name) { + 'settings' => $this->settings ?? throw new Exception('Настройки не инициализированы', 500), + 'robot' => $this->robot ?? throw new Exception('Робот не инициализирован', 500), + 'data' => $this->offsetGet('data'), + 'attachments' => $this->offsetGet('attachments'), + default => $this->offsetGet($name) + }; + } + + /** + * Записать по смещению + */ + public function offsetSet(mixed $offset, mixed $value): mixed + { + if (isset($this->settings)) { + if (strcasecmp($offset, 'settings') === 0) { + // Полная запись + + throw new Exception('Запрещено перезаписывать настройки', 500); + } else if ( + (strcasecmp($offset, 'data') === 0) + || (strcasecmp($offset, 'attachment') === 0) + || (strcasecmp($offset, 'attachments') === 0) + ) { + // Записать вложения + + if (is_array($value)) { + // Жесткая запись + + return $this->settings['attachments'] = $value; + } + + // Конкатенация + return $this->settings['attachments'][] = $value; + } else { + // Запись по ключу или смещению + + return $this->settings[$offset] = $value; + } + } + + throw new Exception('Настройки не инициализированы', 500); + } + + /** + * Прочитать по смещению + */ + public function &offsetGet(mixed $offset): mixed + { + if (isset($this->settings)) { + if (strcasecmp($offset, 'settings') === 0) { + // Полное чтение + + return $this->settings; + } else if (strcasecmp($offset, 'data') === 0 || strcasecmp($offset, 'attachments') === 0) { + // Прочитать вложения + + return $this->settings['attachments']; + } else if (array_key_exists($offset, $this->settings)) { + // Прочитать по ключу или смещению + + return $this->settings[$offset]; + } + + is_int($offset) ? throw new Exception("Смещение $offset не найдено", 404) : throw new Exception("Ключ $offset не найден", 404); + } + + throw new Exception('Настройки не инициализированы', 500); + } + + /** + * Проверка существования смещения + */ + public function offsetExists(mixed $offset): bool + { + if (isset($this->settings)) { + if (strcasecmp($offset, 'settings') === 0) { + // Полная проверка + + return isset($this->settings); + } else if (strcasecmp($offset, 'data') === 0 || strcasecmp($offset, 'attachments') === 0) { + // Проверка вложений + + return array_key_exists('attachments', $this->settings); + } else { + // Проверка по ключу или смещению + + return array_key_exists($offset, $this->settings); + } + } + + throw new Exception('Настройки не инициализированы', 500); + } + + /** + * Удалить по смещению + */ + public function offsetUnset(mixed $offset): void + { + if (isset($this->settings)) { + if (strcasecmp($offset, 'settings') === 0) { + // Полное удаление + + unset($this->settings); + + return; + } else if (strcasecmp($offset, 'data') === 0 || strcasecmp($offset, 'attachments') === 0) { + // Удаление вложений + + unset($this->settings['attachments']); + + return; + } else { + // Удаление по ключу или смещению + + unset($this->settings[$offset]); + + return; + } + } + + throw new Exception('Настройки не инициализированы', 500); + } +} diff --git a/hood/vk/system/core.php b/hood/vk/system/core.php index 9a4c4c6..1bd0190 100644 --- a/hood/vk/system/core.php +++ b/hood/vk/system/core.php @@ -4,10 +4,11 @@ declare(strict_types=1); namespace hood\vk; +use hood\vk\robots\robot; +use hood\vk\traits\singleton; +use hood\vk\loggers\jasmo; + use Exception; -use hood\vk\loggers\jasmo, - hood\vk\traits\singleton, - hood\vk\robots\robot; /** * Ядро @@ -23,13 +24,13 @@ use hood\vk\loggers\jasmo, * @method public function get($id = null) Чтение из реестра * * @package VK - * @author Арсен Мирзаев + * @author Арсен Мирзаев Татьяно-Мурадович */ final class core { use singleton; - /** + /** * Счётчик роботов * * @var int @@ -101,15 +102,25 @@ final class core * * @return void */ - public function set(int $id, robot $robot): void + public function write(int $id, robot $robot): void { - // if (empty($this->registry[$id])) { - // // Если нет сессий, то инициализировать - // $this->registry[$id] = []; - // } + try { + // Инициализация уникального идентификатора сессии - // Создать новую сессию и обновить счётчик роботов - $this->registry[$id][++$this->robots] = $robot; + $session = count($this->read($id)); + } catch (Exception $e) { + if ($e->getCode() === 404) { + // Робота или сессии не существует + + $session = 0; + } + } finally { + // Записать новую сессию + $this->registry[$id][$session] = $robot; + + // Прединкрементация счётчика роботов + ++$this->robots; + } } /** @@ -122,18 +133,35 @@ final class core * * @see hood\vk\traits\registry Модификация метода * - * @return mixed + * @return mixed Весь реестр, робота или сессию робота */ - public function get(int|null $id = null, int|null $session = null): mixed + public function read(int|null $id = null, int|null $session = null): mixed { - if (isset($id) && array_key_exists($id, $this->registry)) { - // Робот передан и найден - if (isset($session) && array_key_exists($session, $this->registry[$id])) { - // Сессия робота передана и найдена - return $this->registry[$id][$session]; + if (isset($id)) { + // Робот передан + + if (array_key_exists($id, $this->registry)) { + // Робот найден + + if (isset($session)) { + // Сессия робота передана + + if (array_key_exists($session, $this->registry[$id])) { + // Сессия робота найдена + + return $this->registry[$id][$session]; + } + + throw new Exception("Сессия $session робота с идентификатором $id не найдена", 404); + } + + return $this->registry[$id]; + } else { + + throw new Exception("Робот с идентификатором $id не найден", 404); } - return $this->registry[$id]; } + return $this->registry; } @@ -152,36 +180,40 @@ final class core if (isset($id)) { // Робот передан - if (!array_key_exists($id, $this->registry)) { - throw new Exception('Робот не найден'); - } + if (array_key_exists($id, $this->registry)) { + // Робот найден - if (isset($session)) { - // Сессия передана + if (isset($session)) { + // Сессия передана - if (!array_key_exists($session, $this->registry[$id])) { - throw new Exception('Сессия не найдена'); + if (array_key_exists($session, $this->registry[$id])) { + // Сессия найдена + + // Постдекрементация счётчика роботов + --$this->robots; + + // Удаление сессии + unset($this->registry[$id][$session]); + + return; + } + + throw new Exception("Сессия $session робота с идентификатором $id не найдена", 404); } - // Счётчик роботов - --$this->robots; + // Вычитание из счётчика количества сессий робота + $this->robots = $this->robots - count($this->registry[$id]); - // Удаление сессии - unset($this->registry[$id][$session]); + // Удаление робота и всех его сессий + unset($this->registry[$id]); return; } - // Счётчик роботов - $this->robots = $this->robots - count($this->registry[$id]); - - // Удаление робота и всех его сессий - unset($this->registry[$id]); - - return; + throw new Exception("Робот с идентификатором $id не найден", 404); } - // Удаление всех роботов и их сессий + // Полная очистка $this->registry = []; } @@ -196,10 +228,10 @@ final class core public function __set(mixed $name, mixed $value): void { match ($name) { - 'timezone' => !isset($this->timezone) ? $this->timezone = $value : throw new Exception('Запрещено переопределять часовой пояс'), - 'path_root' => !isset($this->path_root) ? $this->path_root = $value : throw new Exception('Запрещено переопределять корневой каталог'), - 'path_logs' => !isset($this->path_logs) ? $this->path_logs = $value : throw new Exception('Запрещено переопределять каталог журналов'), - 'path_temp' => !isset($this->path_temp) ? $this->path_temp = $value : throw new Exception('Запрещено переопределять каталог временных файлов') + 'timezone' => !isset($this->timezone) ? $this->timezone = $value : throw new Exception('Запрещено переопределять часовой пояс', 500), + 'path_root' => !isset($this->path_root) ? $this->path_root = $value : throw new Exception('Запрещено переопределять корневой каталог', 500), + 'path_logs' => !isset($this->path_logs) ? $this->path_logs = $value : throw new Exception('Запрещено переопределять каталог журналов', 500), + 'path_temp' => !isset($this->path_temp) ? $this->path_temp = $value : throw new Exception('Запрещено переопределять каталог временных файлов', 500) }; } @@ -239,7 +271,7 @@ final class core // Если найден класс реализующий запрошенного робота return new $robot(...$params); } else { - throw new Exception('Не найден робот: ' . $method); + throw new Exception("Робот $method не найден", 404); } } } diff --git a/hood/vk/system/robots/group.php b/hood/vk/system/robots/group.php index b1ff823..739e396 100644 --- a/hood/vk/system/robots/group.php +++ b/hood/vk/system/robots/group.php @@ -4,11 +4,11 @@ declare(strict_types=1); namespace hood\vk\robots; -use hood\vk\robots\robot, - hood\vk\api\longpoll; +use hood\vk\robots\robot; +use hood\vk\api\longpoll; -use Throwable, - Exception; +use Throwable; +use Exception; /** * Робот-группа diff --git a/hood/vk/system/robots/robot.php b/hood/vk/system/robots/robot.php index 605b981..9cf274b 100644 --- a/hood/vk/system/robots/robot.php +++ b/hood/vk/system/robots/robot.php @@ -11,7 +11,7 @@ use GuzzleHttp\Client as browser; use hood\vk\core; use hood\vk\proxies\proxy; use hood\vk\captcha\captcha; -use hood\vk\api\api; +use hood\vk\api\settings as api; use hood\vk\api\methods\method; use hood\accounts\vk as account; @@ -31,7 +31,7 @@ use hood\accounts\vk as account; * * @var int $messages_mode Режим отправки сообщений * - * @method public function __construct(int $id = null, float $version = null) Конструктор + * @method public function __construct(int $id = null) Конструктор * @method public function key(string $key) Инициализация ключа * @method public function account(account $account) Инициализация аккаунта * @method public function __set($name, $value) Запись свойства @@ -51,11 +51,6 @@ abstract class robot */ protected int $session; - /** - * @var string Ключ - */ - protected string $key; - /** * @var string Аккаунт */ @@ -84,22 +79,24 @@ abstract class robot /** * Конструктор * - * @param int $id Идентификатор + * @param int|null $id Идентификатор + * @param string|null $key Ключ */ public function __construct( protected int|null $id = null, + protected string|null $key = null ) { // Инициализация ядра $core = core::init(); // Идентификация робота - $this->id = empty($id) ? $core->robots + 1 : $id; + $this->id = $id ?? $core->robots + 1; // Регистрация робота в ядре - $core->set($this->id, $this); + $core->write($this->id, $this); // Идентификация сессии робота - $this->session = count($core->get($this->id)); + $this->session = count($core->read($this->id)); } /** @@ -111,11 +108,7 @@ abstract class robot */ public function key(string $key): self { - if (!isset($this->key)) { - $this->key = $key; - } else { - throw new Exception('Запрещено перезаписывать ключ'); - } + $this->__set('key', $key); return $this; } @@ -129,11 +122,7 @@ abstract class robot */ public function account(account $account): self { - if (!isset($this->account)) { - $this->account = $account; - } else { - throw new Exception('Запрещено перезаписывать аккаунт'); - } + $this->__set('account', $account); return $this; } @@ -147,7 +136,7 @@ abstract class robot */ public function proxy(proxy $proxy): self { - $this->proxy = $proxy; + $this->__set('proxy', $proxy); return $this; } @@ -161,7 +150,7 @@ abstract class robot */ public function captcha(captcha $captcha): self { - $this->captcha = $captcha; + $this->__set('captcha', $captcha); return $this; } @@ -177,16 +166,16 @@ abstract class robot public function __set(string $name, mixed $value): void { match ($name) { - 'id' => !isset($this->id) ? $this->id = (int) $value : throw new Exception('Запрещено перезаписывать идентификатор'), - 'session' => !isset($this->session) ? $this->session = (int) $value : throw new Exception('Запрещено перезаписывать сессию'), - 'key' => !isset($this->key) ? $this->key = (string) $value : throw new Exception('Запрещено перезаписывать ключ'), - 'api' => !isset($this->api) ? $this->api = $value : throw new Exception('Запрещено перезаписывать API'), - 'account' => !isset($this->account) && $value instanceof account ? $this->account = $value : throw new Exception('Запрещено перезаписывать аккаунт'), - 'browser' => !isset($this->browser) && $value instanceof browser ? $this->browser = $value : throw new Exception('Запрещено перезаписывать браузер'), + 'id' => isset($this->id) ? throw new Exception('Запрещено перезаписывать идентификатор', 500) : $this->id = (int) $value, + 'session' => isset($this->session) ? throw new Exception('Запрещено перезаписывать сессию', 500) : $this->session = (int) $value, + 'key' => isset($this->key) ? throw new Exception('Запрещено перезаписывать ключ', 500) : $this->key = (string) $value, + 'api' => isset($this->api) ? throw new Exception('Запрещено перезаписывать API', 500) : $this->api = $value, + 'account' => isset($this->account) ? throw new Exception('Запрещено перезаписывать аккаунт', 500) : $this->account = $value, + 'browser' => isset($this->browser) ? throw new Exception('Запрещено перезаписывать браузер', 500) : $this->browser = $value, 'proxy' => $this->proxy = $value, 'captcha' => $this->captcha = $value, 'messages_new' => $this->messages_new = (int) $value, - default => throw new Exception('Свойство не найдено: ' . $name) + default => throw new Exception("Свойство $name не найдено", 404) }; } @@ -200,11 +189,11 @@ abstract class robot public function __get(string $name): mixed { return match ($name) { - 'id' => $this->id ?? throw new Exception('Идентификатор не инициализирован'), - 'session' => $this->session ?? throw new Exception('Сессия не инициализирована'), - 'key' => $this->key ?? throw new Exception('Ключ не инициализирован'), + 'id' => $this->id ?? throw new Exception('Идентификатор не инициализирован', 500), + 'session' => $this->session ?? throw new Exception('Сессия не инициализирована', 500), + 'key' => $this->key ?? throw new Exception('Ключ не инициализирован', 500), 'api' => $this->api ?? $this->api = new api($this), - 'account' => $this->account ?? throw new Exception('Аккаунт не инициализирован'), + 'account' => $this->account ?? throw new Exception('Аккаунт не инициализирован', 500), 'browser' => $this->browser ?? $this->browser = new browser([ 'base_uri' => 'https://api.vk.com/method/', 'cookies' => true @@ -212,7 +201,7 @@ abstract class robot 'proxy' => $this->proxy, 'captcha' => $this->captcha, 'messages_new' => $this->messages_new, - default => throw new Exception('Свойство не найдено: ' . $name) + default => throw new Exception("Свойство $name не найдено", 404) }; } @@ -235,7 +224,7 @@ abstract class robot 'proxy' => isset($this->proxy), 'captcha' => isset($this->captcha), 'messages_new' => isset($this->messages_new), - default => throw new Exception('Свойство не найдено: ' . $name) + default => throw new Exception("Свойство $name не найдено", 404) }; } @@ -257,7 +246,7 @@ abstract class robot return new $class($this, ...$params); } - throw new Exception('Метод не найден: ' . $method); + throw new Exception("Метод $method не найден", 404); } /** @@ -277,7 +266,7 @@ abstract class robot return $class(self, ...$params); } - throw new Exception('Метод не найден: ' . $method); + throw new Exception("Метод $method не найден", 404); } /**