From ce92d44b8beb94f698990a356d0a78115255b8c4 Mon Sep 17 00:00:00 2001 From: RedHood Date: Sat, 26 Sep 2020 20:28:13 +1000 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20LongPoll.=20=D0=9F=D0=B5=D1=80=D0=B5=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=BA=D0=B0=20=D1=8F=D0=B4=D1=80=D0=B0,=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=81=D0=B1=D0=BE=D1=80=D1=89=D0=B8=D0=BA=D0=B0,=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + composer.lock | 1446 +++++++++++++------------ system/API/LongPoll.php | 295 ++++- system/API/LongPollAbstract.php | 11 - system/API/Methods/Message.php | 85 +- system/API/Methods/MethodAbstract.php | 53 +- system/API/Traits/Request.php | 36 - system/Browsers/BrowserAbstract.php | 105 +- system/Browsers/Curl.php | 99 +- system/Builder.php | 112 +- system/Core.php | 76 +- system/Robots/Group.php | 100 +- system/Robots/RobotAbstract.php | 135 ++- system/Traits/Registry.php | 2 +- system/Traits/Singleton.php | 20 +- 15 files changed, 1497 insertions(+), 1079 deletions(-) delete mode 100644 system/API/LongPollAbstract.php delete mode 100644 system/API/Traits/Request.php diff --git a/.gitignore b/.gitignore index a32ccf6..76cf2b9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /logs +/temp /vendor .env \ No newline at end of file diff --git a/composer.lock b/composer.lock index c12c96c..5105abc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,38 +4,36 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e2d1407a4027e8ec1fa6acdb99d1cd4a", + "content-hash": "031634121077f98f72f550b8b41f97c1", "packages": [ { - "name": "graham-campbell/result-type", - "version": "v1.0.1", + "name": "dragonmantank/cron-expression", + "version": "3.0.1", "source": { "type": "git", - "url": "https://github.com/GrahamCampbell/Result-Type.git", - "reference": "7e279d2cd5d7fbb156ce46daada972355cea27bb" + "url": "https://github.com/dragonmantank/cron-expression.git", + "reference": "fa4e95ff5a7f1d62c3fbc05c32729b7f3ca14b52" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/7e279d2cd5d7fbb156ce46daada972355cea27bb", - "reference": "7e279d2cd5d7fbb156ce46daada972355cea27bb", + "url": "https://api.github.com/repos/dragonmantank/cron-expression/zipball/fa4e95ff5a7f1d62c3fbc05c32729b7f3ca14b52", + "reference": "fa4e95ff5a7f1d62c3fbc05c32729b7f3ca14b52", "shasum": "" }, "require": { - "php": "^7.0|^8.0", - "phpoption/phpoption": "^1.7.3" + "php": "^7.1" + }, + "replace": { + "mtdowling/cron-expression": "^1.0" }, "require-dev": { - "phpunit/phpunit": "^6.5|^7.5|^8.5|^9.0" + "phpstan/phpstan": "^0.11", + "phpunit/phpunit": "^6.4|^7.0" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, "autoload": { "psr-4": { - "GrahamCampbell\\ResultType\\": "src/" + "Cron\\": "src/Cron/" } }, "notification-url": "https://packagist.org/downloads/", @@ -44,232 +42,23 @@ ], "authors": [ { - "name": "Graham Campbell", - "email": "graham@alt-three.com" + "name": "Chris Tankersley", + "email": "chris@ctankersley.com", + "homepage": "https://github.com/dragonmantank" } ], - "description": "An Implementation Of The Result Type", + "description": "CRON for PHP: Calculate the next or previous run date and determine if a CRON expression is due", "keywords": [ - "Graham Campbell", - "GrahamCampbell", - "Result Type", - "Result-Type", - "result" + "cron", + "schedule" ], "funding": [ { - "url": "https://github.com/GrahamCampbell", + "url": "https://github.com/dragonmantank", "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/graham-campbell/result-type", - "type": "tidelift" } ], - "time": "2020-04-13T13:17:36+00:00" - }, - { - "name": "guzzlehttp/guzzle", - "version": "7.0.1", - "source": { - "type": "git", - "url": "https://github.com/guzzle/guzzle.git", - "reference": "2d9d3c186a6637a43193e66b097c50e4451eaab2" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/2d9d3c186a6637a43193e66b097c50e4451eaab2", - "reference": "2d9d3c186a6637a43193e66b097c50e4451eaab2", - "shasum": "" - }, - "require": { - "ext-json": "*", - "guzzlehttp/promises": "^1.0", - "guzzlehttp/psr7": "^1.6.1", - "php": "^7.2.5", - "psr/http-client": "^1.0" - }, - "provide": { - "psr/http-client-implementation": "1.0" - }, - "require-dev": { - "ergebnis/composer-normalize": "^2.0", - "ext-curl": "*", - "php-http/client-integration-tests": "dev-phpunit8", - "phpunit/phpunit": "^8.5.5", - "psr/log": "^1.1" - }, - "suggest": { - "ext-curl": "Required for CURL handler support", - "ext-intl": "Required for Internationalized Domain Name (IDN) support", - "psr/log": "Required for using the Log middleware" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "7.0-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "Márk Sági-Kazár", - "email": "mark.sagikazar@gmail.com", - "homepage": "https://sagikazarmark.hu" - } - ], - "description": "Guzzle is a PHP HTTP client library", - "homepage": "http://guzzlephp.org/", - "keywords": [ - "client", - "curl", - "framework", - "http", - "http client", - "psr-18", - "psr-7", - "rest", - "web service" - ], - "time": "2020-06-27T10:33:25+00:00" - }, - { - "name": "guzzlehttp/promises", - "version": "v1.3.1", - "source": { - "type": "git", - "url": "https://github.com/guzzle/promises.git", - "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", - "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", - "shasum": "" - }, - "require": { - "php": ">=5.5.0" - }, - "require-dev": { - "phpunit/phpunit": "^4.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.4-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Promise\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - } - ], - "description": "Guzzle promises library", - "keywords": [ - "promise" - ], - "time": "2016-12-20T10:07:11+00:00" - }, - { - "name": "guzzlehttp/psr7", - "version": "1.6.1", - "source": { - "type": "git", - "url": "https://github.com/guzzle/psr7.git", - "reference": "239400de7a173fe9901b9ac7c06497751f00727a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/239400de7a173fe9901b9ac7c06497751f00727a", - "reference": "239400de7a173fe9901b9ac7c06497751f00727a", - "shasum": "" - }, - "require": { - "php": ">=5.4.0", - "psr/http-message": "~1.0", - "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" - }, - "provide": { - "psr/http-message-implementation": "1.0" - }, - "require-dev": { - "ext-zlib": "*", - "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" - }, - "suggest": { - "zendframework/zend-httphandlerrunner": "Emit PSR-7 responses" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.6-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Psr7\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "Tobias Schultze", - "homepage": "https://github.com/Tobion" - } - ], - "description": "PSR-7 message implementation that also provides common utility methods", - "keywords": [ - "http", - "message", - "psr-7", - "request", - "response", - "stream", - "uri", - "url" - ], - "time": "2019-07-01T23:21:34+00:00" + "time": "2020-08-21T02:30:13+00:00" }, { "name": "jasny/error-handler", @@ -407,120 +196,6 @@ ], "time": "2020-05-22T07:31:27+00:00" }, - { - "name": "phpoption/phpoption", - "version": "1.7.4", - "source": { - "type": "git", - "url": "https://github.com/schmittjoh/php-option.git", - "reference": "b2ada2ad5d8a32b89088b8adc31ecd2e3a13baf3" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/b2ada2ad5d8a32b89088b8adc31ecd2e3a13baf3", - "reference": "b2ada2ad5d8a32b89088b8adc31ecd2e3a13baf3", - "shasum": "" - }, - "require": { - "php": "^5.5.9 || ^7.0 || ^8.0" - }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.3", - "phpunit/phpunit": "^4.8.35 || ^5.0 || ^6.0 || ^7.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.7-dev" - } - }, - "autoload": { - "psr-4": { - "PhpOption\\": "src/PhpOption/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache-2.0" - ], - "authors": [ - { - "name": "Johannes M. Schmitt", - "email": "schmittjoh@gmail.com" - }, - { - "name": "Graham Campbell", - "email": "graham@alt-three.com" - } - ], - "description": "Option Type for PHP", - "keywords": [ - "language", - "option", - "php", - "type" - ], - "funding": [ - { - "url": "https://github.com/GrahamCampbell", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/phpoption/phpoption", - "type": "tidelift" - } - ], - "time": "2020-06-07T10:40:07+00:00" - }, - { - "name": "psr/http-client", - "version": "1.0.1", - "source": { - "type": "git", - "url": "https://github.com/php-fig/http-client.git", - "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", - "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", - "shasum": "" - }, - "require": { - "php": "^7.0 || ^8.0", - "psr/http-message": "^1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-4": { - "Psr\\Http\\Client\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "PHP-FIG", - "homepage": "http://www.php-fig.org/" - } - ], - "description": "Common interface for HTTP clients", - "homepage": "https://github.com/php-fig/http-client", - "keywords": [ - "http", - "http-client", - "psr", - "psr-18" - ], - "time": "2020-06-29T06:28:15+00:00" - }, { "name": "psr/http-message", "version": "1.0.1", @@ -617,355 +292,6 @@ "psr-3" ], "time": "2020-03-23T09:12:05+00:00" - }, - { - "name": "ralouphie/getallheaders", - "version": "3.0.3", - "source": { - "type": "git", - "url": "https://github.com/ralouphie/getallheaders.git", - "reference": "120b605dfeb996808c31b6477290a714d356e822" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", - "reference": "120b605dfeb996808c31b6477290a714d356e822", - "shasum": "" - }, - "require": { - "php": ">=5.6" - }, - "require-dev": { - "php-coveralls/php-coveralls": "^2.1", - "phpunit/phpunit": "^5 || ^6.5" - }, - "type": "library", - "autoload": { - "files": [ - "src/getallheaders.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ralph Khattar", - "email": "ralph.khattar@gmail.com" - } - ], - "description": "A polyfill for getallheaders.", - "time": "2019-03-08T08:55:37+00:00" - }, - { - "name": "symfony/polyfill-ctype", - "version": "v1.17.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "2edd75b8b35d62fd3eeabba73b26b8f1f60ce13d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/2edd75b8b35d62fd3eeabba73b26b8f1f60ce13d", - "reference": "2edd75b8b35d62fd3eeabba73b26b8f1f60ce13d", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "suggest": { - "ext-ctype": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.17-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Ctype\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Gert de Pagter", - "email": "BackEndTea@gmail.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for ctype functions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "ctype", - "polyfill", - "portable" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2020-06-06T08:46:27+00:00" - }, - { - "name": "symfony/polyfill-mbstring", - "version": "v1.17.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "7110338d81ce1cbc3e273136e4574663627037a7" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/7110338d81ce1cbc3e273136e4574663627037a7", - "reference": "7110338d81ce1cbc3e273136e4574663627037a7", - "shasum": "" - }, - "require": { - "php": ">=5.3.3" - }, - "suggest": { - "ext-mbstring": "For best performance" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.17-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Mbstring\\": "" - }, - "files": [ - "bootstrap.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill for the Mbstring extension", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "mbstring", - "polyfill", - "portable", - "shim" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2020-06-06T08:46:27+00:00" - }, - { - "name": "symfony/polyfill-php80", - "version": "v1.17.1", - "source": { - "type": "git", - "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "4a5b6bba3259902e386eb80dd1956181ee90b5b2" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/4a5b6bba3259902e386eb80dd1956181ee90b5b2", - "reference": "4a5b6bba3259902e386eb80dd1956181ee90b5b2", - "shasum": "" - }, - "require": { - "php": ">=7.0.8" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.17-dev" - }, - "thanks": { - "name": "symfony/polyfill", - "url": "https://github.com/symfony/polyfill" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Polyfill\\Php80\\": "" - }, - "files": [ - "bootstrap.php" - ], - "classmap": [ - "Resources/stubs" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ion Bazan", - "email": "ion.bazan@gmail.com" - }, - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", - "homepage": "https://symfony.com", - "keywords": [ - "compatibility", - "polyfill", - "portable", - "shim" - ], - "funding": [ - { - "url": "https://symfony.com/sponsor", - "type": "custom" - }, - { - "url": "https://github.com/fabpot", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", - "type": "tidelift" - } - ], - "time": "2020-06-06T08:46:27+00:00" - }, - { - "name": "vlucas/phpdotenv", - "version": "v5.0.0", - "source": { - "type": "git", - "url": "https://github.com/vlucas/phpdotenv.git", - "reference": "fbb6a5f65512f21d0db9e21bd49e67f70a9bbd5e" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/fbb6a5f65512f21d0db9e21bd49e67f70a9bbd5e", - "reference": "fbb6a5f65512f21d0db9e21bd49e67f70a9bbd5e", - "shasum": "" - }, - "require": { - "ext-pcre": "*", - "graham-campbell/result-type": "^1.0.1", - "php": "^7.1.3 || ^8.0", - "phpoption/phpoption": "^1.7.4", - "symfony/polyfill-ctype": "^1.17", - "symfony/polyfill-mbstring": "^1.17", - "symfony/polyfill-php80": "^1.17" - }, - "require-dev": { - "bamarni/composer-bin-plugin": "^1.4.1", - "ext-filter": "*", - "phpunit/phpunit": "^7.5.20 || ^8.5.2 || ^9.0" - }, - "suggest": { - "ext-filter": "Required to use the boolean validator." - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "5.0-dev" - } - }, - "autoload": { - "psr-4": { - "Dotenv\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Graham Campbell", - "email": "graham@alt-three.com", - "homepage": "https://gjcampbell.co.uk/" - }, - { - "name": "Vance Lucas", - "email": "vance@vancelucas.com", - "homepage": "https://vancelucas.com/" - } - ], - "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.", - "keywords": [ - "dotenv", - "env", - "environment" - ], - "funding": [ - { - "url": "https://github.com/GrahamCampbell", - "type": "github" - }, - { - "url": "https://tidelift.com/funding/github/packagist/vlucas/phpdotenv", - "type": "tidelift" - } - ], - "time": "2020-06-07T19:04:14+00:00" } ], "packages-dev": [ @@ -1446,6 +772,271 @@ ], "time": "2019-12-30T22:54:17+00:00" }, + { + "name": "graham-campbell/result-type", + "version": "v1.0.1", + "source": { + "type": "git", + "url": "https://github.com/GrahamCampbell/Result-Type.git", + "reference": "7e279d2cd5d7fbb156ce46daada972355cea27bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/7e279d2cd5d7fbb156ce46daada972355cea27bb", + "reference": "7e279d2cd5d7fbb156ce46daada972355cea27bb", + "shasum": "" + }, + "require": { + "php": "^7.0|^8.0", + "phpoption/phpoption": "^1.7.3" + }, + "require-dev": { + "phpunit/phpunit": "^6.5|^7.5|^8.5|^9.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "GrahamCampbell\\ResultType\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "graham@alt-three.com" + } + ], + "description": "An Implementation Of The Result Type", + "keywords": [ + "Graham Campbell", + "GrahamCampbell", + "Result Type", + "Result-Type", + "result" + ], + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/graham-campbell/result-type", + "type": "tidelift" + } + ], + "time": "2020-04-13T13:17:36+00:00" + }, + { + "name": "guzzlehttp/guzzle", + "version": "7.0.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "2d9d3c186a6637a43193e66b097c50e4451eaab2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/2d9d3c186a6637a43193e66b097c50e4451eaab2", + "reference": "2d9d3c186a6637a43193e66b097c50e4451eaab2", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/promises": "^1.0", + "guzzlehttp/psr7": "^1.6.1", + "php": "^7.2.5", + "psr/http-client": "^1.0" + }, + "provide": { + "psr/http-client-implementation": "1.0" + }, + "require-dev": { + "ergebnis/composer-normalize": "^2.0", + "ext-curl": "*", + "php-http/client-integration-tests": "dev-phpunit8", + "phpunit/phpunit": "^8.5.5", + "psr/log": "^1.1" + }, + "suggest": { + "ext-curl": "Required for CURL handler support", + "ext-intl": "Required for Internationalized Domain Name (IDN) support", + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.0-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "psr-18", + "psr-7", + "rest", + "web service" + ], + "time": "2020-06-27T10:33:25+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "v1.3.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "shasum": "" + }, + "require": { + "php": ">=5.5.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "time": "2016-12-20T10:07:11+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "1.6.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "239400de7a173fe9901b9ac7c06497751f00727a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/239400de7a173fe9901b9ac7c06497751f00727a", + "reference": "239400de7a173fe9901b9ac7c06497751f00727a", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0", + "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "ext-zlib": "*", + "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" + }, + "suggest": { + "zendframework/zend-httphandlerrunner": "Emit PSR-7 responses" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.6-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Schultze", + "homepage": "https://github.com/Tobion" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" + ], + "time": "2019-07-01T23:21:34+00:00" + }, { "name": "jms/metadata", "version": "1.7.0", @@ -2262,6 +1853,71 @@ ], "time": "2016-01-25T08:17:30+00:00" }, + { + "name": "phpoption/phpoption", + "version": "1.7.4", + "source": { + "type": "git", + "url": "https://github.com/schmittjoh/php-option.git", + "reference": "b2ada2ad5d8a32b89088b8adc31ecd2e3a13baf3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/b2ada2ad5d8a32b89088b8adc31ecd2e3a13baf3", + "reference": "b2ada2ad5d8a32b89088b8adc31ecd2e3a13baf3", + "shasum": "" + }, + "require": { + "php": "^5.5.9 || ^7.0 || ^8.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.3", + "phpunit/phpunit": "^4.8.35 || ^5.0 || ^6.0 || ^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.7-dev" + } + }, + "autoload": { + "psr-4": { + "PhpOption\\": "src/PhpOption/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Johannes M. Schmitt", + "email": "schmittjoh@gmail.com" + }, + { + "name": "Graham Campbell", + "email": "graham@alt-three.com" + } + ], + "description": "Option Type for PHP", + "keywords": [ + "language", + "option", + "php", + "type" + ], + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpoption/phpoption", + "type": "tidelift" + } + ], + "time": "2020-06-07T10:40:07+00:00" + }, { "name": "phpspec/prophecy", "version": "v1.10.3", @@ -2914,6 +2570,55 @@ ], "time": "2017-02-14T16:28:37+00:00" }, + { + "name": "psr/http-client", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-client.git", + "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", + "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621", + "shasum": "" + }, + "require": { + "php": "^7.0 || ^8.0", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP clients", + "homepage": "https://github.com/php-fig/http-client", + "keywords": [ + "http", + "http-client", + "psr", + "psr-18" + ], + "time": "2020-06-29T06:28:15+00:00" + }, { "name": "psr/simple-cache", "version": "1.0.1", @@ -2962,6 +2667,46 @@ ], "time": "2017-10-23T01:57:42+00:00" }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "time": "2019-03-08T08:55:37+00:00" + }, { "name": "sebastian/code-unit", "version": "1.0.5", @@ -4031,6 +3776,239 @@ "homepage": "https://symfony.com", "time": "2018-11-11T11:18:13+00:00" }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.17.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "2edd75b8b35d62fd3eeabba73b26b8f1f60ce13d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/2edd75b8b35d62fd3eeabba73b26b8f1f60ce13d", + "reference": "2edd75b8b35d62fd3eeabba73b26b8f1f60ce13d", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.17-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-06-06T08:46:27+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.17.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "7110338d81ce1cbc3e273136e4574663627037a7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/7110338d81ce1cbc3e273136e4574663627037a7", + "reference": "7110338d81ce1cbc3e273136e4574663627037a7", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.17-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-06-06T08:46:27+00:00" + }, + { + "name": "symfony/polyfill-php80", + "version": "v1.17.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php80.git", + "reference": "4a5b6bba3259902e386eb80dd1956181ee90b5b2" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/4a5b6bba3259902e386eb80dd1956181ee90b5b2", + "reference": "4a5b6bba3259902e386eb80dd1956181ee90b5b2", + "shasum": "" + }, + "require": { + "php": ">=7.0.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.17-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php80\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ion Bazan", + "email": "ion.bazan@gmail.com" + }, + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-06-06T08:46:27+00:00" + }, { "name": "symfony/process", "version": "v2.8.52", @@ -4371,6 +4349,82 @@ ], "time": "2020-02-11T05:59:23+00:00" }, + { + "name": "vlucas/phpdotenv", + "version": "v5.0.0", + "source": { + "type": "git", + "url": "https://github.com/vlucas/phpdotenv.git", + "reference": "fbb6a5f65512f21d0db9e21bd49e67f70a9bbd5e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/fbb6a5f65512f21d0db9e21bd49e67f70a9bbd5e", + "reference": "fbb6a5f65512f21d0db9e21bd49e67f70a9bbd5e", + "shasum": "" + }, + "require": { + "ext-pcre": "*", + "graham-campbell/result-type": "^1.0.1", + "php": "^7.1.3 || ^8.0", + "phpoption/phpoption": "^1.7.4", + "symfony/polyfill-ctype": "^1.17", + "symfony/polyfill-mbstring": "^1.17", + "symfony/polyfill-php80": "^1.17" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", + "ext-filter": "*", + "phpunit/phpunit": "^7.5.20 || ^8.5.2 || ^9.0" + }, + "suggest": { + "ext-filter": "Required to use the boolean validator." + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Dotenv\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "graham@alt-three.com", + "homepage": "https://gjcampbell.co.uk/" + }, + { + "name": "Vance Lucas", + "email": "vance@vancelucas.com", + "homepage": "https://vancelucas.com/" + } + ], + "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.", + "keywords": [ + "dotenv", + "env", + "environment" + ], + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/vlucas/phpdotenv", + "type": "tidelift" + } + ], + "time": "2020-06-07T19:04:14+00:00" + }, { "name": "webmozart/assert", "version": "1.9.0", diff --git a/system/API/LongPoll.php b/system/API/LongPoll.php index 858ca92..2fbe725 100644 --- a/system/API/LongPoll.php +++ b/system/API/LongPoll.php @@ -4,75 +4,268 @@ declare(strict_types=1); namespace VK\API; -class LongPoll extends LongPollAbstract +use \Exception; +use \VK\Core, + \VK\Robots\RobotAbstract; + +/** + * LongPoll + * + * @property string $key Ключ к серверу + * @property string $server Сервер + * @property string $ts Идентификатор последнего события + * + * @method public function __construct(object $robot) Инициализация + * @method public function get(int $wait = 25) Получить события + * @method public function handle(callable $function, int $wait = 25) Обработать события + * + * @see https://vk.com/dev/bots_longpoll + * @see https://vk.com/dev/groups.getLongPollServer + * @see https://vk.com/dev/groups.setLongPollSettings + * + * @package VK\API\LongPoll + * @author Арсен Мирзаев + * + * @todo Добавить обработку ошибок ($request['errors];) + */ +class LongPoll { /** - * Объект взаимодействия лонгпола - * - * @var object - */ - private $robot; - - /** - * Тип объекта: пользователь или группа + * Робот * * @var string */ - private $auth_type; + private RobotAbstract $robot; /** - * Ключ сессии + * Ключ к серверу + * + * @see $this->get() * * @var string */ - private $key; - - /** - * @var int - */ - private $user_id; - - /** - * @var int - */ - private $group_id; - - /** - * @var int - */ - private $ts; + private string $key; /** + * Сервер (URL) + * + * @see $this->get() + * * @var string */ - private $server; - - public function __construct(object $robot, array $params = []) + private string $server; + + /** + * Идентификатор последнего события + * + * От него отсчитываются новые, необработанные события + * + * @see $this->get() + * + * @var string + */ + private string $ts; + + /** + * Инициализация + * + * @param object $robot Робот + */ + public function __construct(object $robot) { - $this->robot = $robot; - if ($_ENV['ROBOT_TYPE']) { - $this->robot->auth_type = 'user'; - $this->user_id = $this->robot->request('users.get', [])['id']; - } else { - $this->robot->auth_type = 'group'; - $this->group_id = $this->robot->request('groups.getById', [])['id']; - $this->robot->request('groups.setLongPollSettings', [ - 'group_id' => $this->group_id, - 'enabled' => 1, - 'api_version' => $this->robot->version, - 'message_new' => 1, - ]); + // Инициализация робота + if (!$robot->id) { + throw new Exception('Роботу необходимо задать идентификатор ВКонтакте'); + } + if (!$robot->token) { + throw new Exception('Роботу необходимо задать токен для доступа к LongPoll'); + } + if (!$robot->version) { + throw new Exception('Роботу необходимо задать версию используемого API ВКонтакте'); + } + $this->robot = $robot; + + // Остановка процессов-дубликатов + if (!file_exists(Core::init()->path['temp'])) { + // Если не существует каталога temp, то создать + mkdir(Core::init()->path['temp'], 0775, true); + } + if (file_exists($lock = Core::init()->path['temp'] . '/' . $this->robot->id . '_' . (int) $this->robot->session . '.longpoll')) { + // Если существует файл-блокировщик, то удалить его + unlink($lock); } - $this->getLongPollServer(); } - - public function getLongPollServer() + + /** + * Установить настройки + * + * Полная настройка и активация LongPoll + * + * @param bool $status = true Активация или деактивация + * @param string ...$params Изменяемые параметры + * + * @return array + */ + public function post(bool $status = true, string ...$params): array { - if ($this->robot->auth_type == 'user') { - $data = $this->robot->request('messages.getLongPollServer', ['need_pts' => 1, 'lp_version' => 3]); - } else { - $data = $this->robot->request('groups.getLongPollServer', ['group_id' => $this->group_id]); + // Инициализация настроек + $settings = [ + 'group_id' => $this->robot->id, + 'access_token' => $this->robot->token, + 'v' => $this->robot->version, + 'api_version' => $this->robot->version + ]; + + // Установка переданных параметров + foreach ($params as $param) { + if ($param === 'group_id' || $param === 'access_token' || $param === 'v' || $param === 'api_version') { + // Блокировка параметров от изменения + continue; + } + + if ($status === true && !array_key_exists('enabled', $settings)) { + // Если запущена активация и не был передан параметр статуса LongPoll + + // Установка параметра активации LongPoll + $settings['enabled'] = 1; + } + + $status = (int) $status; + + if ($param === 'all') { + // Если передан параметр: установка ВСЕХ значений + $settings['message_new'] = $status; + $settings['message_reply'] = $status; + $settings['message_allow'] = $status; + $settings['message_deny'] = $status; + $settings['message_edit'] = $status; + $settings['message_typing_state'] = $status; + $settings['photo_new'] = $status; + $settings['audio_new'] = $status; + $settings['video_new'] = $status; + $settings['wall_reply_new'] = $status; + $settings['wall_reply_edit'] = $status; + $settings['wall_reply_delete'] = $status; + $settings['wall_reply_restore'] = $status; + $settings['wall_post_new'] = $status; + $settings['wall_repost'] = $status; + $settings['board_post_new'] = $status; + $settings['board_post_edit'] = $status; + $settings['board_post_restore'] = $status; + $settings['board_post_delete'] = $status; + $settings['photo_comment_new'] = $status; + $settings['photo_comment_edit'] = $status; + $settings['photo_comment_delete'] = $status; + $settings['photo_comment_restore'] = $status; + $settings['video_comment_new'] = $status; + $settings['video_comment_edit'] = $status; + $settings['video_comment_delete'] = $status; + $settings['video_comment_restore'] = $status; + $settings['market_comment_new'] = $status; + $settings['market_comment_edit'] = $status; + $settings['market_comment_delete'] = $status; + $settings['market_comment_restore'] = $status; + $settings['poll_vote_new'] = $status; + $settings['group_join'] = $status; + $settings['group_leave'] = $status; + $settings['group_change_settings'] = $status; + $settings['group_change_photo'] = $status; + $settings['group_officers_edit'] = $status; + $settings['user_block'] = $status; + $settings['user_unblock'] = $status; + $settings['like_add'] = $status; + $settings['like_remove'] = $status; + $settings['message_event'] = $status; + } else { + // Иначе + + // Установка значения + $settings[$param] = $status; + } + } - list($this->key, $this->server, $this->ts) = [$data['key'], $data['server'], $data['ts']]; + + return $this->robot->browser()->api('groups.setLongPollSettings', $settings); + } + + /** + * Получить события + * + * @param int $wait Время ожидания новых событий (в секундах) + * + * @return array + */ + public function get(int $wait = 25): array + { + if (empty($this->key) || empty($this->server) || empty($this->ts)) { + // Если не инициализирован LongPoll-сервер + + // Запрос на получение доступа и данных LongPoll-сервера + $response = $this->robot->browser()->api('groups.getLongPollServer', [ + 'group_id' => $this->robot->id, + 'access_token' => $this->robot->token, + 'v' => $this->robot->version + ])['response']; + + // Ключ доступа + $this->key = $response['key']; + + // Сервер хранящий события + $this->server = $response['server']; + + // Идентификатор последнего события + $this->ts = $response['ts']; + } + + // Запрос на получение событий + return $this->robot->browser()->post($this->server . '?act=a_check&key=' . $this->key . '&ts=' . $this->ts . '&wait=' . $wait); + } + + /** + * Обработать события + * + * Получает и обрабатывает события + * + * @param callable $function Обработка + * @param int $wait Время ожидания новых событий (в секундах) + * + * @return array + */ + public function handle(callable $function, int $wait = 25): array + { + // Файл-блокировщик и PID процесса + $lock = Core::init()->path['temp'] . '/' . $this->robot->id . '_' . (int) $this->robot->session . '.longpoll'; + $pid = getmypid(); + + // Создание или пересоздание файла-блокировщика + file_put_contents($lock, $pid); + + do { + // Выполняется пока существует файл-блокировщик + + // Запрос на получение событий + $request = $this->get($wait); + + // [ВНИМАНИЕ] Соединение будет открыто даже при создании нового процесса LongPoll + + if (!file_exists($lock) || (int) fread(fopen($lock, 'r'), filesize($lock)) !== $pid) { + // Проверка существования файла-блокировщика и соответствие его PID + + // Завершение работы + break; + } + + if (!empty($request['response']['updates'])) { + // Если получены необработанные события + + // Обработка событий + $function($request['response']); + } + + // Новый идентификатор последнего события + $this->ts = $request['response']['ts']; + } while (true); + + return $request; } } diff --git a/system/API/LongPollAbstract.php b/system/API/LongPollAbstract.php deleted file mode 100644 index 1bc7b71..0000000 --- a/system/API/LongPollAbstract.php +++ /dev/null @@ -1,11 +0,0 @@ - + * + * @todo Добавить обработку ошибок ($request['errors];) + */ class Message { - use Request; - - private const METHOD = 'messages.send'; - - public static function post($from, int $to, string $message, int $trolling) + /** + * Отправить сообщение + * + * @param $from Экземпляр робота + * @param int $to Идентификатор получателя + * @param string $message Текст сообщения + * @param int $mode Режим доставки сообщения + * + * @return array Ответ сервера + */ + public static function put(RobotAbstract $from, int $to, string $message, int $mode = 2): array { - if (is_int($from)) { - // Если получен идентификатор, а не экземпляр RobotAbstract + $random_id = time(); + $check = false; - // Поиск в регистре - $from = Core::init()->get($from); + // Режим доставки сообщений (усложнение по возрастанию) + if ($mode >= 1) { + // Дополнительное умножение + $random_id *= rand(); + + if ($mode >= 2) { + // Проверка отправки (по умолчанию) + $check = true; + } } - // Параметры - $params = [ - 'message' => $message, - 'peer_id' => $to, + // Запрос: отправить сообщение + $request = $from->browser()->api('messages.send', [ 'access_token' => $from->token, 'v' => $from->version, - 'random_id' => $trolling - ]; + 'peer_id' => $to, + 'message' => $message, + 'random_id' => $random_id + ]); - // Запрос - self::request(self::METHOD, $params, $from->getBrowser()); - } + if ($check) { + // Если активирована проверка отправленного сообщения - public static function get() - { - } + // Запрос: получить сообщение по ID + if ($from->browser()->api('messages.getById', [ + 'access_token' => $from->token, + 'v' => $from->version, + 'message_ids' => is_int($request["response"]) ? $request["response"] : $request["response"]['message_id'] + ])['response']['count'] === 0) { + // Если сообщения не существует, то повтор + self::put($from, $to, $message, $mode); + } + } - public static function delete() - { + return $request; } } diff --git a/system/API/Methods/MethodAbstract.php b/system/API/Methods/MethodAbstract.php index f906e47..c0c1014 100644 --- a/system/API/Methods/MethodAbstract.php +++ b/system/API/Methods/MethodAbstract.php @@ -4,9 +4,56 @@ declare(strict_types=1); namespace VK\API\Methods; +/** + * Абстракция метода API + * + * @method protected static put(string $url, ...$params) Создать + * @method protected static post(string $url, ...$params) Изменить + * @method protected static get(string $url, ...$params) Получить + * @method protected static delete(string $url, ...$params) Удалить + * + * @package VK\API\Methods + * @author Арсен Мирзаев + */ abstract class MethodAbstract { - abstract public static function post(); - abstract public static function get(); - abstract public static function delete(); + /** + * Создать + * + * @return array Ответ сервера + */ + public static function put(): array + { + return ['error' => 'Метод не поддерживается']; + } + + /** + * Изменить + * + * @return array Ответ сервера + */ + public static function post(): array + { + return ['error' => 'Метод не поддерживается']; + } + + /** + * Получить + * + * @return array Ответ сервера + */ + public static function get(): array + { + return ['error' => 'Метод не поддерживается']; + } + + /** + * Удалить + * + * @return array Ответ сервера + */ + public static function delete(): array + { + return ['error' => 'Метод не поддерживается']; + } } diff --git a/system/API/Traits/Request.php b/system/API/Traits/Request.php deleted file mode 100644 index 4307cd1..0000000 --- a/system/API/Traits/Request.php +++ /dev/null @@ -1,36 +0,0 @@ - $value) { - $post[$key] = $value; - } - - // while (True) { - // try { - return $browser::post($url, $post); - // } catch (Exception $e) { - // // if (in_array($e->getCode(), $this->request_ignore_error)) { - // // sleep(1); - // // continue; - // // } else - // // throw new Exception($e->getMessage(), $e->getCode()); - // throw new Exception('Жопа'); - // } - // } - return false; - } -} diff --git a/system/Browsers/BrowserAbstract.php b/system/Browsers/BrowserAbstract.php index ee79c4e..bb1af25 100644 --- a/system/Browsers/BrowserAbstract.php +++ b/system/Browsers/BrowserAbstract.php @@ -4,9 +4,108 @@ declare(strict_types=1); namespace VK\Browsers; + +/** + * Абстракция браузера + * + * @method public static api(string $method, ...$params) Запрос к API ВКонтакте + * @method protected static put(string $url, ...$params) Создать + * @method protected static post(string $url, ...$params) Изменить + * @method protected static get(string $url, ...$params) Получить + * @method protected static delete(string $url, ...$params) Удалить + * + * @package Browsers + * @author Arsen Mirzaev + */ abstract class BrowserAbstract { - abstract public static function post($method, $params = []); - abstract public static function getToken($url); - abstract protected static function checkSSL($domain); + /** + * Запрос к VK API + * + * @param string $method Метод VK API + * @param array $params Передаваемые параметры + * + * @return string + */ + public function api(string $method, array $params): array + { + $url = 'https://api.vk.com/method/' . $method; + + // while (True) { + // try { + return $this->post($url, $params); + // } catch (Exception $e) { + // // if (in_array($e->getCode(), $this->request_ignore_error)) { + // // sleep(1); + // // continue; + // // } else + // // throw new Exception($e->getMessage(), $e->getCode()); + // throw new Exception('Жопа'); + // } + // } + } + + /** + * Создать + * + * Для запросов на создание (REST) + * Реализация HTTP PUT + * + * @param string $url Запрашиваемая ссылка + * @param array $params Передаваемые параметры + * + * @return array Ответ сервера + */ + public static function put(string $url, array $params = null): array + { + return ['error' => 'Метод не поддерживается']; + } + + /** + * Изменить + * + * Для запросов на изменение (REST) + * Реализация HTTP POST + * + * @param string $url Запрашиваемая ссылка + * @param array $params Передаваемые параметры + * + * @return array Ответ сервера + */ + public static function post(string $url, array $params = null): array + { + return ['error' => 'Метод не поддерживается']; + } + + /** + * Получить + * + * Для запросов на получение (REST) + * Реализация HTTP GET + * + * @param string $url Запрашиваемая ссылка + * @param array $params Передаваемые параметры + * + * @return array Ответ сервера + */ + public static function get(string $url, array $params = null): array + { + return ['error' => 'Метод не поддерживается']; + } + + /** + * Удалить + * + * Для запросов на удаление (REST) + * Реализация HTTP DELETE + * + * @param string $url Запрашиваемая ссылка + * @param array $params Передаваемые параметры + * + * @return array Ответ сервера + */ + public static function delete(string $url, array $params = null): array + { + return ['error' => 'Метод не поддерживается']; + } } diff --git a/system/Browsers/Curl.php b/system/Browsers/Curl.php index 8d87fe4..91e19e7 100644 --- a/system/Browsers/Curl.php +++ b/system/Browsers/Curl.php @@ -6,92 +6,49 @@ namespace VK\Browsers; use VK\Core; use Exception; - +/** + * Реализация CURL + * + * @method protected static put(string $url, ...$params) Создать + * + * @package Browsers + * @author Arsen Mirzaev + */ class Curl extends BrowserAbstract { /** - * SSL шифрование + * Изменить * - * @var bool + * Для запросов на изменение (REST) + * Реализация HTTP POST + * + * @param string $url Запрашиваемая ссылка + * @param array $params Передаваемые параметры + * + * @return array Ответ сервера */ - private static bool $ssl = false; - - public static function post($url, $params = []) + public static function post(string $url, array $params = null): array { $c = curl_init(); curl_setopt($c, CURLOPT_HTTPHEADER, [ - "Content-Type:multipart/form-data" + 'Content-Type: multipart/form-data' ]); - curl_setopt($c, CURLOPT_URL, $url); + curl_setopt($c, CURLOPT_URL, $url); + curl_setopt($c, CURLOPT_POSTFIELDS, $params); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($c, CURLOPT_POSTFIELDS, $params); curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0); $result = json_decode(curl_exec($c), True); curl_close($c); - - if (isset($result['response'])) - return $result['response']; - else if (isset($result['error'])) - throw new Exception(json_encode($result), $result['error']['error_code']); - else if (!isset($result)) - self::post($url, $params); - else + + if (isset($result['response'])) { return $result; - } - - public static function getToken($url) - { - if (!self::checkSSL('localhost')) { - $core = Core::init(); - $core->logger->notice('Соединение не защищено. Необходимо включить SSL шифрование'); - } - - if ($curl = curl_init()) { - curl_setopt($curl, CURLOPT_URL, $url); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); - - curl_setopt($curl, CURLOPT_USERAGENT, $_ENV['USERAGENT']); - if (isset($post_values)) { - curl_setopt($curl, CURLOPT_POST, 1); - curl_setopt($curl, CURLOPT_POSTFIELDS, $post_values); - } - - if ($cookie and isset(self::$cookie)) { - $send_cookie = []; - foreach (self::$cookie as $cookie_name => $cookie_val) { - $send_cookie[] = "$cookie_name=$cookie_val"; - } - curl_setopt($curl, CURLOPT_COOKIE, join('; ', $send_cookie)); - } - - curl_setopt( - $curl, - CURLOPT_HEADERFUNCTION, - function ($curl, $header) use (&$headers) { - $len = strlen($header); - $header = explode(':', $header, 2); - if (count($header) < 2) // ignore invalid headers - return $len; - - $name = strtolower(trim($header[0])); - if (isset($headers) and !array_key_exists($name, $headers)) - $headers[$name] = [trim($header[1])]; - else - $headers[$name][] = trim($header[1]); - - return $len; - } - ); - - $out = curl_exec($curl); - - curl_close($curl); - //if (isset($headers['set-cookie'])) - // $this->parseCookie($headers['set-cookie']); - return ['header' => $headers, 'body' => $out]; + } else if (isset($result['error'])) { + throw new Exception(json_encode($result), $result['error']['error_code']); + } else if (!isset($result)) { + self::post($url, $params); + } else { + return ['response' => $result]; } } diff --git a/system/Builder.php b/system/Builder.php index e3108fd..19998fb 100644 --- a/system/Builder.php +++ b/system/Builder.php @@ -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 */ 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; - } } diff --git a/system/Core.php b/system/Core.php index a5f383b..353296d 100644 --- a/system/Core.php +++ b/system/Core.php @@ -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 Арсен Мирзаев */ 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; } } diff --git a/system/Robots/Group.php b/system/Robots/Group.php index e166a4a..b999e8e 100644 --- a/system/Robots/Group.php +++ b/system/Robots/Group.php @@ -4,64 +4,92 @@ declare(strict_types=1); namespace VK\Robots; -use VK\Browsers\BrowserAbstract; -use VK\Parsers\Curl; -use Exception; -use VK\API\LongPoll; +use \VK\Browsers\BrowserAbstract, + \VK\API\Methods\Message, + \VK\API\LongPoll; /** - * Робот: "Группа" + * Робот-группа ВКонтакте * * Класс реализовывающий работу от лица группы ВКонтакте * - * @package Robots - * @author Arsen Mirzaev + * @property LongPoll $longpoll LongPoll-сессия + * + * @method public function message(int $to, string $message, int $mode = 2) Отправить сообщение + * @method public function __set($name, $value) Магический метод-сеттер + * @method public function __get($name) Магический метод-геттер + * + * @package VK\Robots\Group + * @author Arsen Mirzaev + * + * @todo Вместо методов реализовать фабрику методов API, как было раньше */ class Group extends RobotAbstract { /** - * ВКонтакте: тип API + * LongPoll-сессия * - * @var string + * @var LongPoll */ - public string $api; + protected LongPoll $longpoll; /** - * ВКонтакте: активатор мобильной версии - * - * @var bool + * Отправить сообщение + * + * @param int $to Идентификатор получателя + * @param string $message Текст сообщения + * @param int $mode Режим доставки сообщения + * + * @return array */ - //protected bool $mobile = false; + public function message(int $to, string $message, int $mode = 2): array + { + return Message::put($this, $to, $message, $mode); + } /** - * ВКонтакте: идентификатор капчи + * Магический метод-сеттер * - * @var int + * @param mixed $name Название + * @param mixed $value Значение + * + * @see RobotAbstract Модификация наследуемого метода + * + * @return void */ - //protected int $captcha; - - public function postMethod($method, $params = []): BrowserAbstract + public function __set($name, $value): void { - $browser = __NAMESPACE__ . '\\Browsers\\' . ucfirst($_ENV['BROWSER_TYPE']); - return (new $browser)->post(); + parent::__set($name, $value); + + if ($name === 'longpoll') { + if ($value instanceof LongPoll) { + $this->longpoll = $value; + } else { + $this->longpoll = new LongPoll($this); + } + } } - public function longpoll(...$params): LongPoll + /** + * Магический метод-геттер + * + * @param mixed $name Название + * + * @see RobotAbstract Модификация наследуемого метода + * + * @return mixed + */ + public function __get($name) { - return new LongPoll($this, $params); - } + if (!empty($parent = parent::__get($name))) { + return $parent; + } - public function callback() - { - return new CallBack($this, $params); - } - - protected function genToken(): string - { - return 'test'; - } - protected function genTokenMobile(string $captcha_key, int $captcha_id): string - { - return 'test 2'; + if ($name === 'longpoll') { + if (empty($this->longpoll)) { + $this->longpoll = new LongPoll($this); + } + return $this->longpoll; + } } } diff --git a/system/Robots/RobotAbstract.php b/system/Robots/RobotAbstract.php index 70baf2d..719da1a 100644 --- a/system/Robots/RobotAbstract.php +++ b/system/Robots/RobotAbstract.php @@ -4,10 +4,33 @@ declare(strict_types=1); namespace VK\Robots; -use \VK\Browsers\BrowserAbstract; -use \VK\Proxies\ProxyAbstract; -use \VK\Proxies\CaptchaAbstract; +use \Exception; +use \VK\Browsers\BrowserAbstract, + \VK\Proxies\ProxyAbstract, + \VK\Captcha\CaptchaAbstract, + \VK\Core; +/** + * Абстракция робота + * + * @property int $id Идентификатор + * @property int $session Сессия + * @property string $token Токен + * @property float $version Версия API + * @property BrowserAbstract $browser Браузер + * @property ProxyAbstract $proxy Прокси + * @property CaptchaAbstract $captcha Обработчик капчи + * + * @method protected static function put(string $url, ...$params) Создать + * @method protected static function post(string $url, ...$params) Изменить + * @method protected static function get(string $url, ...$params) Получить + * @method protected static function delete(string $url, ...$params) Удалить + * @method public function __set($name, $value) Магический метод-сеттер + * @method public function __get($name) Магический метод-геттер + * + * @package API/Methods + * @author Арсен Мирзаев + */ abstract class RobotAbstract { /** @@ -17,6 +40,13 @@ abstract class RobotAbstract */ protected int $id; + /** + * Сессия + * + * @var int + */ + protected int $session; + /** * Токен * @@ -29,17 +59,17 @@ abstract class RobotAbstract * * @var float */ - public float $version = 5.103; + protected float $version = 5.124; /** - * Используемый браузер + * Браузер * * @var BrowserAbstract */ protected BrowserAbstract $browser; /** - * Прокси-сервер + * Прокси * * @var ProxyAbstract */ @@ -55,12 +85,17 @@ abstract class RobotAbstract /** * Магический сеттер * - * @return mixed + * @param mixed $name Название + * @param mixed $value Значение + * + * @return void */ - public function __set($name, $value) + public function __set($name, $value): void { if ($name === 'id' && empty($this->id)) { $this->id = $value; + } else if ($name === 'session' && empty($this->session)) { + $this->session = $value; } else if ($name === 'token' && empty($this->token)) { $this->token = $value; } else if ($name === 'version' && empty($this->version)) { @@ -77,12 +112,16 @@ abstract class RobotAbstract /** * Магический геттер * + * @param mixed $name Название + * * @return mixed */ public function __get($name) { if ($name === 'id') { return $this->id; + } else if ($name === 'session') { + return $this->session; } else if ($name === 'token') { return $this->token; } else if ($name === 'version') { @@ -97,7 +136,9 @@ abstract class RobotAbstract } /** - * Установка токена + * Токен + * + * @param string $token Токен * * @return RobotAbstract */ @@ -110,19 +151,30 @@ abstract class RobotAbstract /** - * Установка браузера + * Браузер * - * @return RobotAbstract + * @param BrowserAbstract $browser Браузер + * + * @return BrowserAbstract */ - public function browser(BrowserAbstract $browser): RobotAbstract + public function browser(BrowserAbstract $browser = null): BrowserAbstract { - $this->browser = $browser; - - return $this; + if (isset($this->browser) && $browser === null) { + // Если не передан браузер и свойство иниициализировано + return $this->browser; + } else if ($browser === null) { + // Иначе если не передан браузер свойство не инициализировано + return $this->browser = new \VK\Browsers\Curl(); + } else { + // Иначе полученный браузер записывается в свойство и возвращается + return $this->browser = $browser; + } } /** - * Установка прокси-сервера + * Установка прокси + * + * @param ProxyAbstract $proxy Прокси * * @return RobotAbstract */ @@ -134,7 +186,9 @@ abstract class RobotAbstract } /** - * Установка сервиса антикапчи + * Установка обработчика капчи + * + * @param CaptchaAbstract $captcha Обработчик капчи * * @return RobotAbstract */ @@ -145,38 +199,27 @@ abstract class RobotAbstract return $this; } - /** - * Получение браузера - * - * @return int - */ - public function getBrowser(): BrowserAbstract - { - // return $this->browser; - return new \VK\Browsers\Curl; - } + // /** + // * Метод получения токена аккаунта + // * + // * @return string + // */ + // public function getToken($captcha_key = null, $captcha_id = null): string + // { + // if (!empty($_ENV['ACCOUNT_TOKEN'])) { + // return $_ENV['ACCOUNT_TOKEN']; + // } else if ($this->mobile) { + // $this->token_access = $this->genTokenMobile($captcha_key, $this->captcha_id ?? $captcha_id); + // } else { + // $this->token_access = $this->genToken(); + // } - /** - * Метод получения токена аккаунта - * - * @return string - */ - public function getToken($captcha_key = null, $captcha_id = null): string - { - if (!empty($_ENV['ACCOUNT_TOKEN'])) { - return $_ENV['ACCOUNT_TOKEN']; - } else if ($this->mobile) { - $this->token_access = $this->genTokenMobile($captcha_key, $this->captcha_id ?? $captcha_id); - } else { - $this->token_access = $this->genToken(); - } - - return $this->token_access; - } + // return $this->token_access; + // } - abstract protected function genToken(): string; - abstract protected function genTokenMobile(string $captcha_key, int $captcha_id): string; + // abstract protected function genToken(): string; + // abstract protected function genTokenMobile(string $captcha_key, int $captcha_id): string; // /** // * @param null $access_groups diff --git a/system/Traits/Registry.php b/system/Traits/Registry.php index 5e3d325..bc4c809 100644 --- a/system/Traits/Registry.php +++ b/system/Traits/Registry.php @@ -49,7 +49,7 @@ trait Registry * * @param mixed $key * - * @return false|mixed + * @return mixed */ public static function get(int $key = null) { diff --git a/system/Traits/Singleton.php b/system/Traits/Singleton.php index 9ebc53d..cf7b9fd 100644 --- a/system/Traits/Singleton.php +++ b/system/Traits/Singleton.php @@ -10,48 +10,48 @@ namespace VK\Traits; trait Singleton { /** - * Экземпляр класса + * Экземпляр класса * - * @var LoggerAbstract + * @var object */ - protected static $instance; + protected static object $instance; /** - * Блокировка конструктора + * Заблокирован */ protected function __construct() { } /** - * Инициализатор экземпляра класса + * Инициализация * - * @return LoggerAbstract + * @return self */ public static function init(): self { - if (self::$instance === null) { + if (!isset(self::$instance)) { self::$instance = new self; } return self::$instance; } /** - * Блокировка магического метода __clone() + * Заблокирован */ private function __clone() { } /** - * Блокировка магического метода __sleep() + * Заблокирован */ private function __sleep() { } /** - * Блокировка магического метода __wakeup() + * Заблокирован */ private function __wakeup() {