From 1a07ae9fe840b19cb5632b1ea567b53ee49ae27c Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 14 Jun 2019 08:56:11 +0300 Subject: [PATCH 01/37] Response models --- .gitignore | 1 + composer.json | 3 +- composer.lock | 274 +++++++++++++++++- src/Bot/Client.php | 202 ++++++++++--- src/Bot/{Request.php => HttpClient.php} | 123 ++++---- src/Bot/Model/Entity/Channel/Channel.php | 184 ++++++++++++ .../Entity/Channel/ChannelProductSettings.php | 126 ++++++++ .../Model/Entity/Channel/ChannelSettings.php | 104 +++++++ .../Entity/Channel/ChannelSettingsStatus.php | 78 +++++ .../Entity/Channel/ChannelTextSettings.php | 126 ++++++++ src/Bot/Model/Entity/CommonFields.php | 106 +++++++ src/Bot/Model/Entity/Error.php | 56 ++++ src/Bot/Model/Entity/FileMeta.php | 81 ++++++ src/Bot/Model/Entity/Responsible.php | 102 +++++++ src/Bot/Model/Response/AssignResponse.php | 131 +++++++++ src/Bot/Model/Response/ErrorOnlyResponse.php | 31 ++ src/Bot/Model/Response/ErrorTrait.php | 66 +++++ src/Bot/Model/Response/FullFileResponse.php | 134 +++++++++ .../Model/Response/GenericListResponse.php | 57 ++++ .../Model/Response/MessageSendResponse.php | 83 ++++++ src/Bot/Model/Response/UploadFileResponse.php | 225 ++++++++++++++ src/Bot/Response.php | 229 --------------- src/Deserializer.php | 59 ++++ tests/Bot/Tests/ClientListTest.php | 8 +- 24 files changed, 2262 insertions(+), 327 deletions(-) rename src/Bot/{Request.php => HttpClient.php} (63%) create mode 100644 src/Bot/Model/Entity/Channel/Channel.php create mode 100644 src/Bot/Model/Entity/Channel/ChannelProductSettings.php create mode 100644 src/Bot/Model/Entity/Channel/ChannelSettings.php create mode 100644 src/Bot/Model/Entity/Channel/ChannelSettingsStatus.php create mode 100644 src/Bot/Model/Entity/Channel/ChannelTextSettings.php create mode 100644 src/Bot/Model/Entity/CommonFields.php create mode 100644 src/Bot/Model/Entity/Error.php create mode 100644 src/Bot/Model/Entity/FileMeta.php create mode 100644 src/Bot/Model/Entity/Responsible.php create mode 100644 src/Bot/Model/Response/AssignResponse.php create mode 100644 src/Bot/Model/Response/ErrorOnlyResponse.php create mode 100644 src/Bot/Model/Response/ErrorTrait.php create mode 100644 src/Bot/Model/Response/FullFileResponse.php create mode 100644 src/Bot/Model/Response/GenericListResponse.php create mode 100644 src/Bot/Model/Response/MessageSendResponse.php create mode 100644 src/Bot/Model/Response/UploadFileResponse.php delete mode 100644 src/Bot/Response.php create mode 100644 src/Deserializer.php diff --git a/.gitignore b/.gitignore index a9004ee..dd9286b 100644 --- a/.gitignore +++ b/.gitignore @@ -61,6 +61,7 @@ cmake-build-release/ # IntelliJ out/ +.idea/ # mpeltonen/sbt-idea plugin .idea_modules/ diff --git a/composer.json b/composer.json index 13565df..a680914 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,8 @@ "jms/serializer": "1.13.*", "symfony/validator": "^4.2", "doctrine/annotations": "^1.6", - "doctrine/cache": "^1.8" + "doctrine/cache": "^1.8", + "guzzlehttp/guzzle": "6.0" }, "require-dev": { "phpunit/phpunit": "6.5.*", diff --git a/composer.lock b/composer.lock index 3553733..330b61e 100644 --- a/composer.lock +++ b/composer.lock @@ -1,10 +1,10 @@ { "_readme": [ "This file locks the dependencies of your project to a known state", - "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "e2dc59137064db9a4933e3049f8e0c34", + "content-hash": "eecd765e939fea19d4d181bafd7384a2", "packages": [ { "name": "doctrine/annotations", @@ -259,6 +259,186 @@ ], "time": "2014-09-09T13:34:57+00:00" }, + { + "name": "guzzlehttp/guzzle", + "version": "6.0.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "df897ae757ad329d2affc38ffb5bbce782b2b510" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/df897ae757ad329d2affc38ffb5bbce782b2b510", + "reference": "df897ae757ad329d2affc38ffb5bbce782b2b510", + "shasum": "" + }, + "require": { + "guzzlehttp/promises": "^1.0.0", + "guzzlehttp/psr7": "^1.0.0", + "php": ">=5.5.0" + }, + "require-dev": { + "ext-curl": "*", + "phpunit/phpunit": "^4.0", + "psr/log": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.0-dev" + } + }, + "autoload": { + "files": [ + "src/functions.php" + ], + "psr-4": { + "GuzzleHttp\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "rest", + "web service" + ], + "time": "2015-05-26T18:22:06+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.5.2", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "9f83dded91781a01c63574e387eaa769be769115" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/9f83dded91781a01c63574e387eaa769be769115", + "reference": "9f83dded91781a01c63574e387eaa769be769115", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0", + "ralouphie/getallheaders": "^2.0.5" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.5-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": "2018-12-04T20:46:45+00:00" + }, { "name": "jms/metadata", "version": "1.7.0", @@ -531,6 +711,96 @@ ], "time": "2015-07-25T16:39:46+00:00" }, + { + "name": "psr/http-message", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/http-message.git", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363", + "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for HTTP messages", + "homepage": "https://github.com/php-fig/http-message", + "keywords": [ + "http", + "http-message", + "psr", + "psr-7", + "request", + "response" + ], + "time": "2016-08-06T14:39:51+00:00" + }, + { + "name": "ralouphie/getallheaders", + "version": "2.0.5", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/5601c8a83fbba7ef674a7369456d12f1e0d0eafa", + "reference": "5601c8a83fbba7ef674a7369456d12f1e0d0eafa", + "shasum": "" + }, + "require": { + "php": ">=5.3" + }, + "require-dev": { + "phpunit/phpunit": "~3.7.0", + "satooshi/php-coveralls": ">=1.0" + }, + "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": "2016-02-11T07:05:27+00:00" + }, { "name": "symfony/contracts", "version": "v1.0.2", diff --git a/src/Bot/Client.php b/src/Bot/Client.php index 59b9827..b8418f5 100644 --- a/src/Bot/Client.php +++ b/src/Bot/Client.php @@ -13,13 +13,17 @@ namespace RetailCrm\Mg\Bot; +use RetailCrm\Common\Deserializer; use RetailCrm\Common\Exception\CurlException; use RetailCrm\Common\Exception\InvalidJsonException; use RetailCrm\Common\Url; use RetailCrm\Common\Serializer; -use RetailCrm\Mg\Bot\Model; +use RetailCrm\Mg\Bot\Model\Response\AssignResponse; +use RetailCrm\Mg\Bot\Model\Response\GenericListResponse; +use RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse; use Exception; use InvalidArgumentException; +use RetailCrm\Mg\Bot\Model\Response\MessageSendResponse; /** * PHP version 7.0 @@ -35,6 +39,11 @@ class Client { const VERSION = 'v1'; + const ENTITY_CLASSPATH = 'RetailCrm\\Mg\\Bot\\Model\\Entity\\'; + const RESPONSE_MODEL_CLASSPATH = 'RetailCrm\\Mg\\Bot\\Model\\Response\\'; + const GENERIC_LIST_RESPONSE = self::RESPONSE_MODEL_CLASSPATH . 'GenericListResponse'; + const ERROR_ONLY_RESPONSE = self::RESPONSE_MODEL_CLASSPATH . 'ErrorOnlyResponse'; + protected $client; /** @@ -47,7 +56,40 @@ class Client public function __construct($url, $token, $debug = false) { $url = sprintf("%sapi/bot/%s", Url::normalizeUrl($url), self::VERSION); - $this->client = new Request($url, $token, $debug); + $this->client = new HttpClient($url, $token, $debug); + } + + /** + * @param string $path + * @param string $method + * @param object $request + * @param string $responseType + * @param int $serializeTo + * @param string $deserializeType + * + * @return object|null + * @throws \Exception + */ + private function getData( + $path, + $method, + $request, + $responseType = self::GENERIC_LIST_RESPONSE, + $serializeTo = Serializer::S_JSON, + $deserializeType = Deserializer::DS_JSON + ) { + $response = $this->client->makeRequest( + $path, + $method, + $request, + $serializeTo + ); + + return Deserializer::deserialize( + (string) $response->getBody(), + $responseType, + $deserializeType + ); } /** @@ -60,11 +102,17 @@ class Client * @throws InvalidJsonException * @throws Exception * - * @return Response + * @return array */ public function bots(Model\Request\BotsRequest $request) { - return $this->client->makeRequest('/bots', Request::METHOD_GET, $request, Serializer::S_ARRAY); + return $this->getData( + '/bots', + HttpClient::METHOD_GET, + $request, + self::GENERIC_LIST_RESPONSE, + Serializer::S_ARRAY + ); } /** @@ -77,11 +125,11 @@ class Client * @throws CurlException * @throws Exception * - * @return Response + * @return ErrorOnlyResponse|object|null */ public function info(Model\Request\InfoRequest $request) { - return $this->client->makeRequest('/my/info', Request::METHOD_PATCH, $request); + return $this->getData('/my/info', HttpClient::METHOD_PATCH, $request, self::ERROR_ONLY_RESPONSE); } /** @@ -89,12 +137,17 @@ class Client * * @param Model\Request\ChannelsRequest $request * - * @return Response + * @return array|object|null * @throws \Exception */ public function channels(Model\Request\ChannelsRequest $request) { - return $this->client->makeRequest('/channels', Request::METHOD_GET, $request, Serializer::S_ARRAY); + return $this->getData( + '/channels', + HttpClient::METHOD_GET, $request, + \sprintf("array<%s%s>", self::ENTITY_CLASSPATH, 'Channel\\Channel'), + Serializer::S_ARRAY + ); } /** @@ -107,11 +160,17 @@ class Client * @throws InvalidJsonException * @throws Exception * - * @return Response + * @return GenericListResponse|object|null */ public function chats(Model\Request\ChatsRequest $request) { - return $this->client->makeRequest('/chats', Request::METHOD_GET, $request, Serializer::S_ARRAY); + return $this->getData( + '/chats', + HttpClient::METHOD_GET, + $request, + self::GENERIC_LIST_RESPONSE, + Serializer::S_ARRAY + ); } /** @@ -124,11 +183,16 @@ class Client * @throws InvalidJsonException * @throws Exception * - * @return Response + * @return GenericListResponse|object|null */ public function commands(Model\Request\CommandsRequest $request) { - return $this->client->makeRequest('/my/commands', Request::METHOD_GET, $request, Serializer::S_ARRAY); + return $this->getData( + '/my/commands', + HttpClient::METHOD_GET, $request, + self::GENERIC_LIST_RESPONSE, + Serializer::S_ARRAY + ); } /** @@ -141,14 +205,15 @@ class Client * @throws InvalidJsonException * @throws Exception * - * @return Response + * @return ErrorOnlyResponse|object|null */ public function commandEdit(Model\Request\CommandEditRequest $request) { - return $this->client->makeRequest( + return $this->getData( sprintf("/my/commands/%s", $request->getName()), - Request::METHOD_PUT, - $request + HttpClient::METHOD_PUT, + $request, + self::ERROR_ONLY_RESPONSE ); } @@ -162,11 +227,17 @@ class Client * @throws InvalidJsonException * @throws Exception * - * @return Response + * @return ErrorOnlyResponse|object|null */ public function commandDelete(string $request) { - return $this->client->makeRequest(sprintf("/my/commands/%s", $request), Request::METHOD_DELETE); + $response = $this->client->makeRequest(sprintf("/my/commands/%s", $request), HttpClient::METHOD_DELETE); + + return Deserializer::deserialize( + $response->getResponse(), + self::ERROR_ONLY_RESPONSE, + Deserializer::DS_ARRAY + ); } /** @@ -179,11 +250,17 @@ class Client * @throws InvalidJsonException * @throws Exception * - * @return Response + * @return GenericListResponse|object|null */ public function customers(Model\Request\CustomersRequest $request) { - return $this->client->makeRequest('/customers', Request::METHOD_GET, $request, Serializer::S_ARRAY); + return $this->getData( + '/customers', + HttpClient::METHOD_GET, + $request, + self::GENERIC_LIST_RESPONSE, + Serializer::S_ARRAY + ); } /** @@ -196,11 +273,17 @@ class Client * @throws InvalidJsonException * @throws Exception * - * @return Response + * @return GenericListResponse|object|null */ public function dialogs(Model\Request\DialogsRequest $request) { - return $this->client->makeRequest('/dialogs', Request::METHOD_GET, $request, Serializer::S_ARRAY); + return $this->getData( + '/dialogs', + HttpClient::METHOD_GET, + $request, + self::GENERIC_LIST_RESPONSE, + Serializer::S_ARRAY + ); } /** @@ -213,14 +296,15 @@ class Client * @throws InvalidJsonException * @throws Exception * - * @return Response + * @return AssignResponse|object|null */ public function dialogAssign(Model\Request\DialogAssignRequest $request) { - return $this->client->makeRequest( + return $this->getData( sprintf("/dialogs/%d/assign", $request->getDialogId()), - Request::METHOD_PATCH, - $request + HttpClient::METHOD_PATCH, + $request, + self::RESPONSE_MODEL_CLASSPATH . 'AssignResponse' ); } @@ -234,11 +318,16 @@ class Client * @throws InvalidJsonException * @throws Exception * - * @return Response + * @return ErrorOnlyResponse|object|null */ public function dialogClose(string $request) { - return $this->client->makeRequest(sprintf("/dialogs/%d/close", $request), Request::METHOD_DELETE); + return $this->getData( + sprintf("/dialogs/%d/close", $request), + HttpClient::METHOD_DELETE, + null, + self::ERROR_ONLY_RESPONSE + ); } /** @@ -251,11 +340,17 @@ class Client * @throws InvalidJsonException * @throws Exception * - * @return Response + * @return GenericListResponse|object|null */ public function members(Model\Request\MembersRequest $request) { - return $this->client->makeRequest('/members', Request::METHOD_GET, $request, Serializer::S_ARRAY); + return $this->getData( + '/members', + HttpClient::METHOD_GET, + $request, + self::GENERIC_LIST_RESPONSE, + Serializer::S_ARRAY + ); } /** @@ -268,11 +363,17 @@ class Client * @throws InvalidJsonException * @throws Exception * - * @return Response + * @return GenericListResponse|object|null */ public function messages(Model\Request\MessagesRequest $request) { - return $this->client->makeRequest('/messages', Request::METHOD_GET, $request, Serializer::S_ARRAY); + return $this->getData( + '/messages', + HttpClient::METHOD_GET, + $request, + self::GENERIC_LIST_RESPONSE, + Serializer::S_ARRAY + ); } /** @@ -285,11 +386,16 @@ class Client * @throws InvalidJsonException * @throws Exception * - * @return Response + * @return MessageSendResponse|object|null */ public function messageSend(Model\Request\MessageSendRequest $request) { - return $this->client->makeRequest('/messages', Request::METHOD_POST, $request); + return $this->getData( + '/messages', + HttpClient::METHOD_POST, + $request, + self::RESPONSE_MODEL_CLASSPATH . 'MessageSendResponse' + ); } /** @@ -302,11 +408,16 @@ class Client * @throws InvalidJsonException * @throws Exception * - * @return Response + * @return MessageSendResponse|object|null */ public function messageEdit(Model\Request\MessageEditRequest $request) { - return $this->client->makeRequest('/messages/%d', Request::METHOD_PATCH, $request->getId()); + return $this->getData( + sprintf("/messages/%d", $request->getId()), + HttpClient::METHOD_PATCH, + $request, + self::RESPONSE_MODEL_CLASSPATH . 'MessageSendResponse' + ); } /** @@ -319,11 +430,16 @@ class Client * @throws InvalidJsonException * @throws Exception * - * @return Response + * @return ErrorOnlyResponse|object|null */ public function messageDelete(string $request) { - return $this->client->makeRequest(sprintf("/messages/%d", $request), Request::METHOD_DELETE); + return $this->getData( + sprintf("/messages/%d", $request), + HttpClient::METHOD_DELETE, + null, + self::ERROR_ONLY_RESPONSE + ); } /** @@ -336,10 +452,16 @@ class Client * @throws InvalidJsonException * @throws Exception * - * @return Response + * @return GenericListResponse|object|null */ public function users(Model\Request\UsersRequest $request) { - return $this->client->makeRequest('/users', Request::METHOD_GET, $request, Serializer::S_ARRAY); + return $this->getData( + '/users', + HttpClient::METHOD_GET, + $request, + self::GENERIC_LIST_RESPONSE, + Serializer::S_ARRAY + ); } } diff --git a/src/Bot/Request.php b/src/Bot/HttpClient.php similarity index 63% rename from src/Bot/Request.php rename to src/Bot/HttpClient.php index ea0b340..9f9dd93 100644 --- a/src/Bot/Request.php +++ b/src/Bot/HttpClient.php @@ -3,7 +3,7 @@ /** * PHP version 7.0 * - * Request + * HttpClient * * @package RetailCrm\Mg\Bot * @author retailCRM @@ -13,25 +13,30 @@ namespace RetailCrm\Mg\Bot; -use RetailCrm\Common\Exception\CurlException; +use RetailCrm\Common\Exception\InvalidJsonException; use RetailCrm\Common\Exception\LimitException; -use Exception; use InvalidArgumentException; use RetailCrm\Common\Serializer; use RetailCrm\Common\Url; use Symfony\Component\Validator\Validation; +use GuzzleHttp\Client; +use GuzzleHttp\HandlerStack; +use GuzzleHttp\Psr7\Request; +use GuzzleHttp\Exception\GuzzleException; +use Psr\Http\Message\ResponseInterface; +use function GuzzleHttp\Psr7\stream_for; /** * PHP version 7.0 * - * Request class + * HttpClient class * * @package RetailCrm\Mg\Bot * @author retailCRM * @license https://opensource.org/licenses/MIT MIT License * @link http://help.retailcrm.pro/docs/Developers */ -class Request +class HttpClient { const METHOD_GET = 'GET'; const METHOD_POST = 'POST'; @@ -39,30 +44,34 @@ class Request const METHOD_PATCH = 'PATCH'; const METHOD_DELETE = 'DELETE'; - protected $url; + protected $basePath; protected $token; - private $debug; private $allowedMethods; private $stdout; + private $client; /** * Client constructor. * * @param string $url api url * @param string $token api token - * @param bool $debug make request verbose * @param bool|resource $stdout default output for debug + * @param HandlerStack $handler */ - public function __construct($url, $token, $debug, $stdout = STDOUT) + public function __construct($url, $token, $stdout = STDOUT, $handler = null) { if (false === stripos($url, 'https://')) { throw new InvalidArgumentException('API schema requires HTTPS protocol'); } - $this->url = $url; + $this->basePath = parse_url($url, PHP_URL_PATH); $this->token = $token; - $this->debug = $debug; $this->stdout = $stdout; + $this->client = new Client(array_filter([ + 'base_uri' => Url::normalizeUrl($url), + 'timeout' => 60, + 'handler' => $handler + ])); $this->allowedMethods = [ self::METHOD_GET, self::METHOD_POST, @@ -80,7 +89,7 @@ class Request * @param mixed $request (default: null) * @param int $serializeTo * - * @return Response + * @return ResponseInterface * @throws \Exception */ public function makeRequest($path, $method, $request = null, $serializeTo = Serializer::S_JSON) @@ -91,40 +100,38 @@ class Request $this->validateRequest($request); } - $urlBuilder = new Url(); - $parameters = is_null($request) ? null : Serializer::serialize($request, $serializeTo); - $url = $method == self::METHOD_GET - ? $this->url . $urlBuilder->buildUrl($path, $parameters, Url::RFC_CUSTOM) - : $this->url . $path - ; - - $curlHandler = curl_init(); - curl_setopt($curlHandler, CURLOPT_URL, $url); - curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1); - curl_setopt($curlHandler, CURLOPT_FOLLOWLOCATION, 1); - curl_setopt($curlHandler, CURLOPT_FAILONERROR, false); - curl_setopt($curlHandler, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($curlHandler, CURLOPT_SSL_VERIFYHOST, false); - curl_setopt($curlHandler, CURLOPT_TIMEOUT, 60); - curl_setopt($curlHandler, CURLOPT_CONNECTTIMEOUT, 60); - curl_setopt($curlHandler, CURLOPT_VERBOSE, $this->debug); - curl_setopt($curlHandler, CURLOPT_STDERR, $this->stdout); - - curl_setopt($curlHandler, CURLOPT_HTTPHEADER, [ - 'Content-Type: application/json', - sprintf("X-Bot-Token: %s", $this->token) - ]); + $request = new Request( + $method, + \sprintf("%s%s", $this->basePath, $path), + [ + 'Content-Type' => 'application/json', + 'X-Bot-Token' => $this->token + ] + ); if (in_array($method, [self::METHOD_POST, self::METHOD_PUT, self::METHOD_PATCH, self::METHOD_DELETE])) { - curl_setopt($curlHandler, CURLOPT_CUSTOMREQUEST, $method); - curl_setopt($curlHandler, CURLOPT_POSTFIELDS, $parameters); + $request = $request->withBody(stream_for($parameters)); } - $responseBody = curl_exec($curlHandler); - $statusCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE); + $responseObject = null; - $response = Response::parseJSON($responseBody); + try { + $responseObject = $this->client->send( + $request, + [ + 'debug' => $this->stdout, + 'allow_redirects' => true, + 'http_errors' => false, + 'verify' => false + ] + ); + } catch (GuzzleException $exception) { + throw new \Exception($exception->getMessage(), $exception->getCode(), $exception); + } + + $statusCode = $responseObject->getStatusCode(); + $response = self::parseJSON((string) $responseObject->getBody()); $errorMessage = !empty($response['errorMsg']) ? $response['errorMsg'] : ''; $errorMessage = !empty($response['errors']) ? $this->getErrors($response['errors']) : $errorMessage; @@ -132,25 +139,15 @@ class Request * responses with 400 & 460 http codes contains extended error data * therefore they are not handled as exceptions */ - if (in_array($statusCode, [403, 404, 500])) { - throw new Exception($errorMessage); + throw new \Exception($errorMessage); } if ($statusCode == 503) { throw new LimitException($errorMessage); } - $errno = curl_errno($curlHandler); - $error = curl_error($curlHandler); - - curl_close($curlHandler); - - if ($errno) { - throw new CurlException($error, $errno); - } - - return new Response($statusCode, $responseBody); + return $responseObject; } /** @@ -202,4 +199,26 @@ class Request return $errorString; } + + /** + * @param string $responseBody + * + * @return array + */ + public static function parseJSON($responseBody): array + { + $result = []; + + if (!empty($responseBody)) { + $response = json_decode($responseBody, true); + + if (!$response && JSON_ERROR_NONE !== ($error = json_last_error())) { + throw new InvalidJsonException("Invalid JSON in the API response body. Error code #$error", $error); + } + + $result = $response; + } + + return $result; + } } diff --git a/src/Bot/Model/Entity/Channel/Channel.php b/src/Bot/Model/Entity/Channel/Channel.php new file mode 100644 index 0000000..119fbb0 --- /dev/null +++ b/src/Bot/Model/Entity/Channel/Channel.php @@ -0,0 +1,184 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Channel; + +use JMS\Serializer\Annotation as Serializer; +use JMS\Serializer\Annotation\SerializedName; +use JMS\Serializer\Annotation\Accessor; +use JMS\Serializer\Annotation\SkipWhenEmpty; +use JMS\Serializer\Annotation\Type; +use RetailCrm\Mg\Bot\Model\Entity\Channel\ChannelSettings; +use RetailCrm\Mg\Bot\Model\Entity\CommonFields; + +/** + * PHP version 7.0 + * + * Channel class + * + * @package RetailCrm\Mg\Bot\Model\Entity + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ +class Channel +{ + use CommonFields; + + /** + * @var \DateTime + * + * @Type("DateTime<'Y-m-d\TH:i:s.u\Z'>") + * @Accessor(setter="setActivatedAt", getter="getActivatedAt") + */ + private $activatedAt; + + /** + * @var \DateTime + * + * @Type("DateTime<'Y-m-d\TH:i:s.u\Z'>") + * @Accessor(setter="setDeactivatedAt", getter="getDeactivatedAt") + * @SkipWhenEmpty() + */ + private $deactivatedAt; + + /** + * @var bool + * + * @Type("bool") + * @Accessor(setter="getIsActive", getter="setIsActive") + * @SerializedName("is_active") + */ + private $isActive; + + /** + * @var array + * + * @Type("array") + * @Accessor(setter="setSettings", getter="getSettings") + */ + private $settings; + + /** + * @var string + * + * @Type("string") + * @Accessor(setter="setType", getter="getType") + */ + private $type; + + /** + * @var string + * + * @Type("string") + * @Accessor(setter="setName", getter="getName") + * @SkipWhenEmpty() + */ + private $name; + + /** + * @return \DateTime + */ + public function getActivatedAt(): \DateTime + { + return $this->activatedAt; + } + + /** + * @param \DateTime $activatedAt + */ + public function setActivatedAt(\DateTime $activatedAt) + { + $this->activatedAt = $activatedAt; + } + + /** + * @return \DateTime + */ + public function getDeactivatedAt(): \DateTime + { + return $this->deactivatedAt; + } + + /** + * @param \DateTime $deactivatedAt + */ + public function setDeactivatedAt($deactivatedAt) + { + $this->deactivatedAt = $deactivatedAt; + } + + /** + * @return bool + */ + public function getIsActive() + { + return $this->isActive; + } + + /** + * @param bool $isActive + */ + public function setIsActive(bool $isActive) + { + $this->isActive = $isActive; + } + + /** + * @return array + */ + public function getSettings(): array + { + return $this->settings; + } + + /** + * @param array $settings + */ + public function setSettings(array $settings) + { + $this->settings = $settings; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType(string $type) + { + $this->type = $type; + } + + /** + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Channel/ChannelProductSettings.php b/src/Bot/Model/Entity/Channel/ChannelProductSettings.php new file mode 100644 index 0000000..72b35e5 --- /dev/null +++ b/src/Bot/Model/Entity/Channel/ChannelProductSettings.php @@ -0,0 +1,126 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Channel; + +use JMS\Serializer\Annotation\Accessor; +use JMS\Serializer\Annotation\Type; + +/** + * PHP version 7.0 + * + * ChannelProductSettings class + * + * @package RetailCrm\Mg\Bot\Model\Entity + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ +class ChannelProductSettings +{ + /** + * @var string + * + * @Type("string") + * @Accessor(setter="setCreating", getter="getCreating") + */ + private $creating; + + /** + * @var string + * + * @Type("string") + * @Accessor(setter="setEditing", getter="getEditing") + */ + private $editing; + + /** + * @var string + * + * @Type("string") + * @Accessor(setter="setDeleting", getter="getDeleting") + */ + private $deleting; + + /** + * @var string + * + * @Type("string") + * @Accessor(setter="setQuoting", getter="getQuoting") + */ + private $quoting; + + /** + * @return string + */ + public function getCreating(): string + { + return $this->creating; + } + + /** + * @param string $creating + */ + public function setCreating(string $creating) + { + $this->creating = $creating; + } + + /** + * @return string + */ + public function getEditing(): string + { + return $this->editing; + } + + /** + * @param string $editing + */ + public function setEditing(string $editing) + { + $this->editing = $editing; + } + + /** + * @return string + */ + public function getDeleting(): string + { + return $this->deleting; + } + + /** + * @param string $deleting + */ + public function setDeleting(string $deleting) + { + $this->deleting = $deleting; + } + + /** + * @return string + */ + public function getQuoting(): string + { + return $this->quoting; + } + + /** + * @param string $quoting + */ + public function setQuoting(string $quoting) + { + $this->quoting = $quoting; + } +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Channel/ChannelSettings.php b/src/Bot/Model/Entity/Channel/ChannelSettings.php new file mode 100644 index 0000000..c92a1dc --- /dev/null +++ b/src/Bot/Model/Entity/Channel/ChannelSettings.php @@ -0,0 +1,104 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Channel; + +use JMS\Serializer\Annotation as Serializer; +use JMS\Serializer\Annotation\Accessor; +use JMS\Serializer\Annotation\SkipWhenEmpty; +use JMS\Serializer\Annotation\Type; + +/** + * PHP version 7.0 + * + * ChannelSettings class + * + * @package RetailCrm\Mg\Bot\Model\Entity + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ +class ChannelSettings +{ + /** + * @var int + * + * @Type("int") + * @Accessor(setter="setSpamAllowed", getter="getSpamAllowed") + */ + private $spamAllowed; + + /** + * @var ChannelSettingsStatus + * + * @Type("RetailCrm\Mg\Bot\Model\Entity\Channel\ChannelSettingsStatus") + * @Accessor(setter="setStatus", getter="getStatus") + */ + private $status; + + /** + * @var ChannelTextSettings + * + * @Type("RetailCrm\Mg\Bot\Model\Entity\Channel\ChannelTextSettings") + * @Accessor(setter="setText", getter="getText") + */ + private $text; + + /** + * @return int + */ + public function getSpamAllowed(): int + { + return $this->spamAllowed; + } + + /** + * @param int $spamAllowed + */ + public function setSpamAllowed(int $spamAllowed) + { + $this->spamAllowed = $spamAllowed; + } + + /** + * @return ChannelSettingsStatus + */ + public function getStatus(): ChannelSettingsStatus + { + return $this->status; + } + + /** + * @param ChannelSettingsStatus $status + */ + public function setStatus(ChannelSettingsStatus $status) + { + $this->status = $status; + } + + /** + * @return ChannelTextSettings + */ + public function getText(): ChannelTextSettings + { + return $this->text; + } + + /** + * @param ChannelTextSettings $text + */ + public function setText(ChannelTextSettings $text) + { + $this->text = $text; + } +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Channel/ChannelSettingsStatus.php b/src/Bot/Model/Entity/Channel/ChannelSettingsStatus.php new file mode 100644 index 0000000..5ffd89d --- /dev/null +++ b/src/Bot/Model/Entity/Channel/ChannelSettingsStatus.php @@ -0,0 +1,78 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Channel; + +use JMS\Serializer\Annotation\Accessor; +use JMS\Serializer\Annotation\Type; + +/** + * PHP version 7.0 + * + * ChannelSettingsStatus class + * + * @package RetailCrm\Mg\Bot\Model\Entity + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ +class ChannelSettingsStatus +{ + /** + * @var string + * + * @Type("string") + * @Accessor(setter="setDelivered", getter="getDelivered") + */ + private $delivered; + + /** + * @var string + * + * @Type("string") + * @Accessor(setter="setRead", getter="getRead") + */ + private $read; + + /** + * @return string + */ + public function getDelivered(): string + { + return $this->delivered; + } + + /** + * @param string $delivered + */ + public function setDelivered(string $delivered) + { + $this->delivered = $delivered; + } + + /** + * @return string + */ + public function getRead(): string + { + return $this->read; + } + + /** + * @param string $read + */ + public function setRead(string $read) + { + $this->read = $read; + } +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Channel/ChannelTextSettings.php b/src/Bot/Model/Entity/Channel/ChannelTextSettings.php new file mode 100644 index 0000000..2732302 --- /dev/null +++ b/src/Bot/Model/Entity/Channel/ChannelTextSettings.php @@ -0,0 +1,126 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Channel; + +use JMS\Serializer\Annotation\Accessor; +use JMS\Serializer\Annotation\Type; + +/** + * PHP version 7.0 + * + * ChannelTextSettings class + * + * @package RetailCrm\Mg\Bot\Model\Entity + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ +class ChannelTextSettings +{ + /** + * @var string + * + * @Type("string") + * @Accessor(setter="setCreating", getter="getCreating") + */ + private $creating; + + /** + * @var string + * + * @Type("string") + * @Accessor(setter="setEditing", getter="getEditing") + */ + private $editing; + + /** + * @var string + * + * @Type("string") + * @Accessor(setter="setDeleting", getter="getDeleting") + */ + private $deleting; + + /** + * @var string + * + * @Type("string") + * @Accessor(setter="setQuoting", getter="getQuoting") + */ + private $quoting; + + /** + * @return string + */ + public function getCreating(): string + { + return $this->creating; + } + + /** + * @param string $creating + */ + public function setCreating(string $creating) + { + $this->creating = $creating; + } + + /** + * @return string + */ + public function getEditing(): string + { + return $this->editing; + } + + /** + * @param string $editing + */ + public function setEditing(string $editing) + { + $this->editing = $editing; + } + + /** + * @return string + */ + public function getDeleting(): string + { + return $this->deleting; + } + + /** + * @param string $deleting + */ + public function setDeleting(string $deleting) + { + $this->deleting = $deleting; + } + + /** + * @return string + */ + public function getQuoting(): string + { + return $this->quoting; + } + + /** + * @param string $quoting + */ + public function setQuoting(string $quoting) + { + $this->quoting = $quoting; + } +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/CommonFields.php b/src/Bot/Model/Entity/CommonFields.php new file mode 100644 index 0000000..3b3b3a2 --- /dev/null +++ b/src/Bot/Model/Entity/CommonFields.php @@ -0,0 +1,106 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity; + +use JMS\Serializer\Annotation\Accessor; +use JMS\Serializer\Annotation\SkipWhenEmpty; +use JMS\Serializer\Annotation\Type; + +/** + * PHP version 7.0 + * + * CommonFields trait + * + * @package RetailCrm\Mg\Bot\Model\Entity + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ +trait CommonFields +{ + /** + * @var int + * + * @Type("int") + * @Accessor(setter="setId", getter="getId") + * @SkipWhenEmpty() + */ + private $id; + + /** + * @var DateTime + * + * @Type("DateTime<'Y-m-d\TH:i:s.u\Z'>") + * @Accessor(setter="setCreatedAt", getter="getCreatedAt") + * @SkipWhenEmpty() + */ + private $createdAt; + + /** + * @var string + * + * @Type("DateTime<'Y-m-d\TH:i:s.u\Z'>") + * @Accessor(setter="setUpdatedAt", getter="getUpdatedAt") + * @SkipWhenEmpty() + */ + private $updatedAt; + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $id + */ + public function setId(int $id) + { + $this->id = $id; + } + + /** + * @return \DateTime + */ + public function getCreatedAt(): \DateTime + { + return $this->createdAt; + } + + /** + * @param \DateTime $createdAt + */ + public function setCreatedAt(\DateTime $createdAt) + { + $this->createdAt = $createdAt; + } + + /** + * @return \DateTime + */ + public function getUpdatedAt(): \DateTime + { + return $this->updatedAt; + } + + /** + * @param \DateTime $updatedAt + */ + public function setUpdatedAt(\DateTime $updatedAt) + { + $this->updatedAt = $updatedAt; + } +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Error.php b/src/Bot/Model/Entity/Error.php new file mode 100644 index 0000000..e40c43b --- /dev/null +++ b/src/Bot/Model/Entity/Error.php @@ -0,0 +1,56 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity; + +use JMS\Serializer\Annotation as Serializer; +use JMS\Serializer\Annotation\Accessor; +use JMS\Serializer\Annotation\Type; + +/** + * PHP version 7.0 + * + * Error class + * + * @package RetailCrm\Mg\Bot\Model\Entity + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ +class Error +{ + /** + * @var array $messages + * + * @Type("array") + * @Accessor(getter="getMessages",setter="setMessages") + * @Serializer\SkipWhenEmpty() + */ + private $messages; + + /** + * @return array + */ + public function getMessages(): array + { + return $this->messages; + } + + /** + * @param array $messages + */ + public function setMessages(array $messages) + { + $this->messages = $messages; + } +} diff --git a/src/Bot/Model/Entity/FileMeta.php b/src/Bot/Model/Entity/FileMeta.php new file mode 100644 index 0000000..8de3e2a --- /dev/null +++ b/src/Bot/Model/Entity/FileMeta.php @@ -0,0 +1,81 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity; + +use JMS\Serializer\Annotation\SkipWhenEmpty; +use JMS\Serializer\Annotation\Accessor; +use JMS\Serializer\Annotation\Type; + +/** + * PHP version 7.0 + * + * Responsible class + * + * @package RetailCrm\Mg\Bot\Model\Entity + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ +class FileMeta +{ + /** + * @var int $height + * + * @Type("int") + * @Accessor(setter="setHeight", getter="getHeight") + * @SkipWhenEmpty() + */ + private $height; + + /** + * @var int $width + * + * @Type("int") + * @Accessor(setter="setWidth", getter="getWidth") + * @SkipWhenEmpty() + */ + private $width; + + /** + * @return int + */ + public function getHeight(): int + { + return $this->height; + } + + /** + * @param int $height + */ + public function setHeight(int $height) + { + $this->height = $height; + } + + /** + * @return int + */ + public function getWidth(): int + { + return $this->width; + } + + /** + * @param int $width + */ + public function setWidth(int $width) + { + $this->width = $width; + } +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Responsible.php b/src/Bot/Model/Entity/Responsible.php new file mode 100644 index 0000000..668fc7a --- /dev/null +++ b/src/Bot/Model/Entity/Responsible.php @@ -0,0 +1,102 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity; + +use JMS\Serializer\Annotation\Accessor; +use JMS\Serializer\Annotation\Type; + +/** + * PHP version 7.0 + * + * Responsible class + * + * @package RetailCrm\Mg\Bot\Model\Entity + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ +class Responsible +{ + /** + * @var string $assignedAt + * + * @Type("string") + * @Accessor(getter="getAssignedAt",setter="setAssignedAt") + */ + private $assignedAt; + + /** + * @var int $id + * + * @Type("int") + * @Accessor(getter="getId",setter="setId") + */ + private $id; + + /** + * @var string $type + * + * @Type("string") + * @Accessor(getter="getType",setter="setType") + */ + private $type; + + /** + * @return string + */ + public function getAssignedAt() + { + return $this->assignedAt; + } + + /** + * @param string $assignedAt + */ + public function setAssignedAt(string $assignedAt) + { + $this->assignedAt = $assignedAt; + } + + /** + * @return int + */ + public function getId(): int + { + return $this->id; + } + + /** + * @param int $id + */ + public function setId(int $id) + { + $this->id = $id; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType(string $type) + { + $this->type = $type; + } +} diff --git a/src/Bot/Model/Response/AssignResponse.php b/src/Bot/Model/Response/AssignResponse.php new file mode 100644 index 0000000..ca9251b --- /dev/null +++ b/src/Bot/Model/Response/AssignResponse.php @@ -0,0 +1,131 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Response; + +use JMS\Serializer\Annotation\Accessor; +use JMS\Serializer\Annotation\SkipWhenEmpty; +use JMS\Serializer\Annotation\Type; +use RetailCrm\Mg\Bot\Model\Entity\Responsible; +use RetailCrm\Mg\Bot\Model\Response\ErrorTrait; + +/** + * PHP version 7.0 + * + * AssignResponse class + * + * @package RetailCrm\Mg\Bot\Model\Response + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ +class AssignResponse +{ + use ErrorTrait; + + /** + * @var bool + * + * @Type("bool") + * @Accessor(setter="setIsReassign", getter="getIsReassign") + */ + private $isReassign; + + /** + * @var int + * + * @Type("int") + * @Accessor(setter="setLeftManagerId", getter="getLeftManagerId") + * @SkipWhenEmpty() + */ + private $leftManagerId; + + /** + * @var Responsible $previousResponsible + * + * @Accessor(setter="setPreviousResponsible", getter="getPreviousResponsible") + * @SkipWhenEmpty() + */ + private $previousResponsible; + + /** + * @var Responsible $responsible + * + * @Accessor(setter="setResponsible", getter="getResponsible") + */ + private $responsible; + + /** + * @return bool + */ + public function getIsReassign() + { + return $this->isReassign; + } + + /** + * @param bool $isReassign + */ + public function setIsReassign(bool $isReassign) + { + $this->isReassign = $isReassign; + } + + /** + * @return int + */ + public function getLeftManagerId(): int + { + return $this->leftManagerId; + } + + /** + * @param int $leftManagerId + */ + public function setLeftManagerId(int $leftManagerId) + { + $this->leftManagerId = $leftManagerId; + } + + /** + * @return Responsible + */ + public function getPreviousResponsible(): Responsible + { + return $this->previousResponsible; + } + + /** + * @param Responsible $previousResponsible + */ + public function setPreviousResponsible(Responsible $previousResponsible) + { + $this->previousResponsible = $previousResponsible; + } + + /** + * @return Responsible + */ + public function getResponsible(): Responsible + { + return $this->responsible; + } + + /** + * @param Responsible $responsible + */ + public function setResponsible(Responsible $responsible) + { + $this->responsible = $responsible; + } +} \ No newline at end of file diff --git a/src/Bot/Model/Response/ErrorOnlyResponse.php b/src/Bot/Model/Response/ErrorOnlyResponse.php new file mode 100644 index 0000000..6c5bf03 --- /dev/null +++ b/src/Bot/Model/Response/ErrorOnlyResponse.php @@ -0,0 +1,31 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Response; + +use RetailCrm\Mg\Bot\Model\Response\ErrorTrait; + +/** + * PHP version 7.0 + * + * ErrorOnlyResponse class + * + * @package RetailCrm\Mg\Bot\Model\Response + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ +class ErrorOnlyResponse +{ + use ErrorTrait; +} \ No newline at end of file diff --git a/src/Bot/Model/Response/ErrorTrait.php b/src/Bot/Model/Response/ErrorTrait.php new file mode 100644 index 0000000..7574c94 --- /dev/null +++ b/src/Bot/Model/Response/ErrorTrait.php @@ -0,0 +1,66 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Response; + +use JMS\Serializer\Annotation as Serializer; +use JMS\Serializer\Annotation\Accessor; +use JMS\Serializer\Annotation\SkipWhenEmpty; +use RetailCrm\Mg\Bot\Model\Entity\Error; + +/** + * PHP version 7.0 + * + * Error trait + * + * @package RetailCrm\Mg\Bot\Model\Response + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ +trait ErrorTrait +{ + /** + * @var array $error + * + * @Serializer\Type("array") + * @Accessor(setter="getError", setter="setError") + * @Serializer\SerializedName("errors") + * @SkipWhenEmpty() + */ + private $error; + + /** + * @return array + */ + public function getError() + { + return $this->error; + } + + /** + * @param array $error + */ + public function setError(array $error) + { + $this->error = $error; + } + + /** + * @return bool + */ + public function isError() + { + return !empty($this->error); + } +} \ No newline at end of file diff --git a/src/Bot/Model/Response/FullFileResponse.php b/src/Bot/Model/Response/FullFileResponse.php new file mode 100644 index 0000000..072b064 --- /dev/null +++ b/src/Bot/Model/Response/FullFileResponse.php @@ -0,0 +1,134 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Response; + +use JMS\Serializer\Annotation\SkipWhenEmpty; +use JMS\Serializer\Annotation\Accessor; +use JMS\Serializer\Annotation\Type; +use RetailCrm\Mg\Bot\Model\Response\ErrorTrait; + +/** + * PHP version 7.0 + * + * FullFileResponse class + * + * @package RetailCrm\Mg\Bot\Model\Response + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ +class FullFileResponse +{ + use ErrorTrait; + + /** + * @var string $id + * + * @Type("string") + * @Accessor(setter="setId", getter="getId") + * @SkipWhenEmpty() + */ + private $id; + + /** + * @var int $size + * + * @Type("int") + * @Accessor(setter="setSize", getter="getSize") + * @SkipWhenEmpty() + */ + private $size; + + /** + * @var string $type + * + * @Type("string") + * @Accessor(setter="setType", getter="getType") + * @SkipWhenEmpty() + */ + private $type; + + /** + * @var string $url + * + * @Type("string") + * @Accessor(setter="setUrl", getter="getUrl") + * @SkipWhenEmpty() + */ + private $url; + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $id + */ + public function setId(string $id) + { + $this->id = $id; + } + + /** + * @return int + */ + public function getSize(): int + { + return $this->size; + } + + /** + * @param int $size + */ + public function setSize(int $size) + { + $this->size = $size; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType(string $type) + { + $this->type = $type; + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->url; + } + + /** + * @param string $url + */ + public function setUrl(string $url) + { + $this->url = $url; + } +} \ No newline at end of file diff --git a/src/Bot/Model/Response/GenericListResponse.php b/src/Bot/Model/Response/GenericListResponse.php new file mode 100644 index 0000000..7210e00 --- /dev/null +++ b/src/Bot/Model/Response/GenericListResponse.php @@ -0,0 +1,57 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Response; + +use JMS\Serializer\Annotation\Accessor; +use JMS\Serializer\Annotation\Type; +use RetailCrm\Mg\Bot\Model\Response\ErrorTrait; + +/** + * PHP version 7.0 + * + * GenericListResponse class + * + * @package RetailCrm\Mg\Bot\Model\Response + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ +class GenericListResponse +{ + use ErrorTrait; + + /** + * @var array $result + * + * @Type("array") + * @Accessor(setter="setResult", getter="getResult") + */ + private $result; + + /** + * @return array + */ + public function getResult() + { + return $this->result; + } + + /** + * @param array $result + */ + public function setResult(array $result) + { + $this->result = $result; + } +} \ No newline at end of file diff --git a/src/Bot/Model/Response/MessageSendResponse.php b/src/Bot/Model/Response/MessageSendResponse.php new file mode 100644 index 0000000..353c8e6 --- /dev/null +++ b/src/Bot/Model/Response/MessageSendResponse.php @@ -0,0 +1,83 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Response; + +use JMS\Serializer\Annotation as Serializer; +use JMS\Serializer\Annotation\SkipWhenEmpty; +use JMS\Serializer\Annotation\Accessor; +use JMS\Serializer\Annotation\Type; +use RetailCrm\Mg\Bot\Model\Response\ErrorTrait; + +/** + * PHP version 7.0 + * + * MessageSendResponse class + * + * @package RetailCrm\Mg\Bot\Model\Response + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ +class MessageSendResponse +{ + /** + * @var int $messageId + * + * @Type("int") + * @Accessor(setter="setMessageId", getter="getMessageId") + * @SkipWhenEmpty() + */ + private $messageId; + + /** + * @var string $time + * + * @Type("string") + * @Accessor(setter="setTime", getter="getTime") + * @SkipWhenEmpty() + */ + private $time; + + /** + * @return int + */ + public function getMessageId(): int + { + return $this->messageId; + } + + /** + * @param int $messageId + */ + public function setMessageId(int $messageId) + { + $this->messageId = $messageId; + } + + /** + * @return string + */ + public function getTime(): string + { + return $this->time; + } + + /** + * @param string $time + */ + public function setTime(string $time) + { + $this->time = $time; + } +} \ No newline at end of file diff --git a/src/Bot/Model/Response/UploadFileResponse.php b/src/Bot/Model/Response/UploadFileResponse.php new file mode 100644 index 0000000..0d9ceef --- /dev/null +++ b/src/Bot/Model/Response/UploadFileResponse.php @@ -0,0 +1,225 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Response; + +use JMS\Serializer\Annotation\Accessor; +use JMS\Serializer\Annotation\Type; +use RetailCrm\Mg\Bot\Model\Response\ErrorTrait; +use RetailCrm\Mg\Bot\Model\Entity\FileMeta; + +/** + * PHP version 7.0 + * + * UploadFileResponse class + * + * @package RetailCrm\Mg\Bot\Model\Response + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ +class UploadFileResponse +{ + use ErrorTrait; + + /** + * @var string $createdAt + * + * @Type("string") + * @Accessor(setter="setCreatedAt", getter="getCreatedAt") + */ + private $createdAt; + + /** + * @var string $hash + * + * @Type("string") + * @Accessor(setter="setHash", getter="getHash") + */ + private $hash; + + /** + * @var string $id + * + * @Type("string") + * @Accessor(setter="setId", getter="getId") + */ + private $id; + + /** + * @var FileMeta + * + * @Accessor(setter="setMeta", getter="getMeta") + */ + private $meta; + + /** + * @var string $mimeType + * + * @Type("string") + * @Accessor(setter="setMimeType", getter="getMimeType") + */ + private $mimeType; + + /** + * @var int $size + * + * @Type("string") + * @Accessor(setter="setSize", getter="getSize") + */ + private $size; + + /** + * @var string $sourceUrl + * + * @Type("string") + * @Accessor(setter="setSourceUrl", getter="getSourceUrl") + */ + private $sourceUrl; + + /** + * @var string $type + * + * @Type("string") + * @Accessor(setter="setType", getter="getType") + */ + private $type; + + /** + * @return string + */ + public function getCreatedAt(): string + { + return $this->createdAt; + } + + /** + * @param string $createdAt + */ + public function setCreatedAt(string $createdAt) + { + $this->createdAt = $createdAt; + } + + /** + * @return string + */ + public function getHash(): string + { + return $this->hash; + } + + /** + * @param string $hash + */ + public function setHash(string $hash) + { + $this->hash = $hash; + } + + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + + /** + * @param string $id + */ + public function setId(string $id) + { + $this->id = $id; + } + + /** + * @return FileMeta + */ + public function getMeta(): FileMeta + { + return $this->meta; + } + + /** + * @param FileMeta $meta + */ + public function setMeta(FileMeta $meta) + { + $this->meta = $meta; + } + + /** + * @return string + */ + public function getMimeType(): string + { + return $this->mimeType; + } + + /** + * @param string $mimeType + */ + public function setMimeType(string $mimeType) + { + $this->mimeType = $mimeType; + } + + /** + * @return int + */ + public function getSize(): int + { + return $this->size; + } + + /** + * @param int $size + */ + public function setSize(int $size) + { + $this->size = $size; + } + + /** + * @return string + */ + public function getSourceUrl(): string + { + return $this->sourceUrl; + } + + /** + * @param string $sourceUrl + */ + public function setSourceUrl(string $sourceUrl) + { + $this->sourceUrl = $sourceUrl; + } + + /** + * @return string + */ + public function getType(): string + { + return $this->type; + } + + /** + * @param string $type + */ + public function setType(string $type) + { + $this->type = $type; + } +} \ No newline at end of file diff --git a/src/Bot/Response.php b/src/Bot/Response.php deleted file mode 100644 index daf4088..0000000 --- a/src/Bot/Response.php +++ /dev/null @@ -1,229 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ - -namespace RetailCrm\Mg\Bot; - -use ArrayAccess; -use BadMethodCallException; -use InvalidArgumentException; -use RetailCrm\Common\Exception\InvalidJsonException; - -/** - * PHP version 7.0 - * - * Request class - * - * @package RetailCrm\Mg\Bot - * @author retailCRM - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ -class Response implements ArrayAccess -{ - // HTTP response status code - protected $statusCode; - - // response assoc array - protected $response; - - // response body - protected $raw; - - /** - * ApiResponse constructor. - * - * @param int $statusCode HTTP status code - * @param mixed $responseBody HTTP body - * - * @throws InvalidJsonException - */ - public function __construct($statusCode, $responseBody = null) - { - $this->statusCode = $statusCode; - $this->raw = $responseBody; - $this->response = self::parseJSON($responseBody); - } - - /** - * Return raw HTTP response - * - * @return string|null - */ - public function getRawResponse() - { - return $this->raw; - } - - /** - * Return HTTP response - * - * @return array - */ - public function getResponse() - { - return $this->response; - } - - /** - * Return HTTP response status code - * - * @return int - */ - public function getStatusCode() - { - return $this->statusCode; - } - - /** - * HTTP request was successful - * - * @return bool - */ - public function isSuccessful() - { - return $this->statusCode < 400; - } - - /** - * Allow to access for the property throw class method - * - * @param string $name method name - * @param mixed $arguments method parameters - * - * @throws \InvalidArgumentException - * - * @return mixed - */ - public function __call($name, $arguments) - { - // convert getSomeProperty to someProperty - $propertyName = strtolower(substr($name, 3, 1)) . substr($name, 4); - - if (!isset($this->response[$propertyName])) { - throw new InvalidArgumentException("Method \"$name\" not found"); - } - - return $this->response[$propertyName]; - } - - /** - * Allow to access for the property throw object property - * - * @param string $name property name - * - * @throws \InvalidArgumentException - * - * @return mixed - */ - public function __get($name) - { - if (!isset($this->response[$name])) { - throw new InvalidArgumentException("Property \"$name\" not found"); - } - - return $this->response[$name]; - } - - /** - * Allow to check if the property exists through object property - * - * @param string $name property name - * - * @return bool - */ - public function __isset($name) - { - return isset($this->response[$name]); - } - - /** - * Offset set - * - * @param mixed $offset offset - * @param mixed $value value - * - * @throws BadMethodCallException - * @return void - */ - public function offsetSet($offset, $value) - { - $message = sprintf("This call not allowed. Offset given: %s. Value given: %s", $offset, $value); - throw new BadMethodCallException($message); - } - - /** - * Offset unset - * - * @param mixed $offset offset - * - * @throws BadMethodCallException - * @return void - */ - public function offsetUnset($offset) - { - $message = sprintf("This call not allowed. Offset given: %s", $offset); - throw new BadMethodCallException($message); - } - - /** - * Check offset - * - * @param mixed $offset offset - * - * @return bool - */ - public function offsetExists($offset) - { - return isset($this->response[$offset]); - } - - /** - * Get offset - * - * @param mixed $offset offset - * - * @throws \InvalidArgumentException - * - * @return mixed - */ - public function offsetGet($offset) - { - if (!isset($this->response[$offset])) { - throw new InvalidArgumentException("Property \"$offset\" not found"); - } - - return $this->response[$offset]; - } - - /** - * @param string $responseBody - * - * @return array - */ - public static function parseJSON($responseBody): array - { - $result = []; - - if (!empty($responseBody)) { - $response = json_decode($responseBody, true); - - if (!$response && JSON_ERROR_NONE !== ($error = json_last_error())) { - throw new InvalidJsonException("Invalid JSON in the API response body. Error code #$error", $error); - } - - $result = $response; - } - - return $result; - } -} diff --git a/src/Deserializer.php b/src/Deserializer.php new file mode 100644 index 0000000..a0feced --- /dev/null +++ b/src/Deserializer.php @@ -0,0 +1,59 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Common; + +use JMS\Serializer\SerializerBuilder; + +/** + * PHP version 7.0 + * + * Deserializer class + * + * @package RetailCrm\Common + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ +class Deserializer +{ + const DS_JSON = "json"; + const DS_XML = "xml"; + const DS_ARRAY = "array"; + + /** + * Serialize given object to JSON or Array + * + * @param array|string $data + * @param string $deserialize + * + * @return object + */ + public static function deserialize($data, $type, $deserialize = self::S_JSON) + { + $deserialized = null; + $serializer = SerializerBuilder::create()->build(); + + switch ($deserialize) { + case self::DS_ARRAY: + $deserialized = $serializer->fromArray($data, $type); + break; + case self::DS_JSON: + case self::DS_XML: + $deserialized = $serializer->deserialize($data, $type, $deserialize); + break; + } + + return $deserialized; + } +} diff --git a/tests/Bot/Tests/ClientListTest.php b/tests/Bot/Tests/ClientListTest.php index dea988a..89f037a 100644 --- a/tests/Bot/Tests/ClientListTest.php +++ b/tests/Bot/Tests/ClientListTest.php @@ -15,6 +15,7 @@ namespace RetailCrm\Mg\Bot\Tests; use RetailCrm\Mg\Bot\Model\Constants; use RetailCrm\Mg\Bot\Model\Request; +use RetailCrm\Mg\Bot\Model\Response; use RetailCrm\Mg\Bot\Test\TestCase; /** @@ -43,8 +44,9 @@ class ClientListTest extends TestCase $request->setTypes([Constants::CHANNEL_TYPE_FACEBOOK, Constants::CHANNEL_TYPE_INSTAGRAM]); $response = $client->channels($request); + var_dump($response[0]); - self::assertTrue($response->isSuccessful() == true); + //self::assertTrue($response->isSuccessful() == true); } /** @@ -122,9 +124,9 @@ class ClientListTest extends TestCase $request->setActive(1); $request->setRoles([Constants::BOT_ROLE_RESPONSIBLE]); - $response = $client->bots($request); + $data = $client->bots($request); - self::assertTrue($response->isSuccessful() == true); + self::assertTrue($data instanceof \RetailCrm\Mg\Bot\Model\Response\GenericListResponse); } /** From 78f167508001e1dc939811c6fbcfaf8e2467f4e2 Mon Sep 17 00:00:00 2001 From: Pavel Date: Fri, 14 Jun 2019 12:48:13 +0300 Subject: [PATCH 02/37] Better structure --- composer.json | 3 +- composer.lock | 94 +++++- src/Bot/Client.php | 274 +++++++++--------- src/Bot/Model/Entity/Bot/Bot.php | 60 ++++ src/Bot/Model/Entity/Channel/Channel.php | 181 ++---------- .../Entity/Channel/ChannelProductSettings.php | 126 -------- .../Model/Entity/Channel/ChannelSettings.php | 103 ++----- .../Entity/Channel/ChannelSettingsItem.php | 55 ++++ .../Entity/Channel/ChannelSettingsStatus.php | 78 ----- .../Entity/Channel/ChannelTextSettings.php | 126 -------- src/Bot/Model/Entity/Chat/Chat.php | 41 +++ src/Bot/Model/Entity/Chat/ChatLastMessage.php | 43 +++ src/Bot/Model/Entity/Chat/ChatMember.php | 45 +++ src/Bot/Model/Entity/Command.php | 37 +++ src/Bot/Model/Entity/CommonFields.php | 82 +----- src/Bot/Model/Entity/Cost.php | 82 ------ src/Bot/Model/Entity/Customer.php | 69 +++++ src/Bot/Model/Entity/Delivery.php | 133 --------- src/Bot/Model/Entity/Dialog.php | 57 ++++ src/Bot/Model/Entity/Error.php | 56 ---- src/Bot/Model/Entity/FileMeta.php | 63 +--- src/Bot/Model/Entity/Item.php | 81 ------ src/Bot/Model/Entity/Message/Item.php | 42 +++ src/Bot/Model/Entity/Message/Message.php | 76 +++++ src/Bot/Model/Entity/Message/MessageCost.php | 39 +++ .../Model/Entity/Message/MessageDelivery.php | 45 +++ src/Bot/Model/Entity/Message/MessageOrder.php | 50 ++++ .../Model/Entity/Message/MessageOrderItem.php | 48 +++ .../Message/MessageOrderPaymentStatus.php | 39 +++ .../Model/Entity/Message/MessagePayment.php | 42 +++ .../Model/Entity/Message/MessageProduct.php | 54 ++++ .../Model/Entity/Message/MessageQuantity.php | 39 +++ .../Model/Entity/Message/MessageStatus.php | 39 +++ src/Bot/Model/Entity/Order.php | 231 --------------- src/Bot/Model/Entity/OrderItem.php | 156 ---------- src/Bot/Model/Entity/Payment.php | 106 ------- src/Bot/Model/Entity/PaymentStatus.php | 81 ------ src/Bot/Model/Entity/Product.php | 206 ------------- src/Bot/Model/Entity/Quantity.php | 82 ------ src/Bot/Model/Entity/Responsible.php | 79 +---- src/Bot/Model/Entity/Status.php | 81 ------ src/Bot/Model/Entity/User.php | 55 ++++ src/Bot/Model/Response/AssignResponse.php | 118 +------- .../{ErrorTrait.php => CommonFields.php} | 36 +-- src/Bot/Model/Response/ErrorOnlyResponse.php | 7 +- src/Bot/Model/Response/FullFileResponse.php | 123 +------- .../Model/Response/GenericListResponse.php | 57 ---- src/Bot/Model/Response/ListResponse.php | 135 +++++++++ .../Model/Response/MessageSendResponse.php | 66 +---- src/Bot/Model/Response/UploadFileResponse.php | 223 ++------------ src/Deserializer.php | 59 ---- tests/Bot/Tests/ClientListTest.php | 20 +- 52 files changed, 1499 insertions(+), 2824 deletions(-) create mode 100644 src/Bot/Model/Entity/Bot/Bot.php delete mode 100644 src/Bot/Model/Entity/Channel/ChannelProductSettings.php create mode 100644 src/Bot/Model/Entity/Channel/ChannelSettingsItem.php delete mode 100644 src/Bot/Model/Entity/Channel/ChannelSettingsStatus.php delete mode 100644 src/Bot/Model/Entity/Channel/ChannelTextSettings.php create mode 100644 src/Bot/Model/Entity/Chat/Chat.php create mode 100644 src/Bot/Model/Entity/Chat/ChatLastMessage.php create mode 100644 src/Bot/Model/Entity/Chat/ChatMember.php create mode 100644 src/Bot/Model/Entity/Command.php delete mode 100644 src/Bot/Model/Entity/Cost.php create mode 100644 src/Bot/Model/Entity/Customer.php delete mode 100644 src/Bot/Model/Entity/Delivery.php create mode 100644 src/Bot/Model/Entity/Dialog.php delete mode 100644 src/Bot/Model/Entity/Error.php delete mode 100644 src/Bot/Model/Entity/Item.php create mode 100644 src/Bot/Model/Entity/Message/Item.php create mode 100644 src/Bot/Model/Entity/Message/Message.php create mode 100644 src/Bot/Model/Entity/Message/MessageCost.php create mode 100644 src/Bot/Model/Entity/Message/MessageDelivery.php create mode 100644 src/Bot/Model/Entity/Message/MessageOrder.php create mode 100644 src/Bot/Model/Entity/Message/MessageOrderItem.php create mode 100644 src/Bot/Model/Entity/Message/MessageOrderPaymentStatus.php create mode 100644 src/Bot/Model/Entity/Message/MessagePayment.php create mode 100644 src/Bot/Model/Entity/Message/MessageProduct.php create mode 100644 src/Bot/Model/Entity/Message/MessageQuantity.php create mode 100644 src/Bot/Model/Entity/Message/MessageStatus.php delete mode 100644 src/Bot/Model/Entity/Order.php delete mode 100644 src/Bot/Model/Entity/OrderItem.php delete mode 100644 src/Bot/Model/Entity/Payment.php delete mode 100644 src/Bot/Model/Entity/PaymentStatus.php delete mode 100644 src/Bot/Model/Entity/Product.php delete mode 100644 src/Bot/Model/Entity/Quantity.php delete mode 100644 src/Bot/Model/Entity/Status.php create mode 100644 src/Bot/Model/Entity/User.php rename src/Bot/Model/Response/{ErrorTrait.php => CommonFields.php} (61%) delete mode 100644 src/Bot/Model/Response/GenericListResponse.php create mode 100644 src/Bot/Model/Response/ListResponse.php delete mode 100644 src/Deserializer.php diff --git a/composer.json b/composer.json index a680914..38e6582 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,8 @@ "symfony/validator": "^4.2", "doctrine/annotations": "^1.6", "doctrine/cache": "^1.8", - "guzzlehttp/guzzle": "6.0" + "guzzlehttp/guzzle": "6.0", + "lazyjsonmapper/lazyjsonmapper": "^1.6" }, "require-dev": { "phpunit/phpunit": "6.5.*", diff --git a/composer.lock b/composer.lock index 330b61e..8d3ee74 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,50 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "eecd765e939fea19d4d181bafd7384a2", + "content-hash": "acac73ae68db3b7df3284c70aa591bbd", "packages": [ + { + "name": "corneltek/getoptionkit", + "version": "2.6.0", + "source": { + "type": "git", + "url": "https://github.com/c9s/GetOptionKit.git", + "reference": "995607ddf4fc90ebdb4a7d58fe972d581ad8495f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/c9s/GetOptionKit/zipball/995607ddf4fc90ebdb4a7d58fe972d581ad8495f", + "reference": "995607ddf4fc90ebdb4a7d58fe972d581ad8495f", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.6.x-dev" + } + }, + "autoload": { + "psr-4": { + "GetOptionKit\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Yo-An Lin", + "email": "yoanlin93@gmail.com" + } + ], + "description": "Powerful command-line option toolkit", + "homepage": "http://github.com/c9s/GetOptionKit", + "time": "2017-06-30T14:54:48+00:00" + }, { "name": "doctrine/annotations", "version": "v1.6.1", @@ -613,6 +655,56 @@ ], "time": "2018-07-25T13:58:54+00:00" }, + { + "name": "lazyjsonmapper/lazyjsonmapper", + "version": "v1.6.3", + "source": { + "type": "git", + "url": "https://github.com/lazyjsonmapper/lazyjsonmapper.git", + "reference": "51e093b50f4de15d2d64548b3ca743713eed6ee9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/lazyjsonmapper/lazyjsonmapper/zipball/51e093b50f4de15d2d64548b3ca743713eed6ee9", + "reference": "51e093b50f4de15d2d64548b3ca743713eed6ee9", + "shasum": "" + }, + "require": { + "corneltek/getoptionkit": "2.*", + "php": ">=5.6" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.7.1", + "phpunit/phpunit": "6.*" + }, + "bin": [ + "bin/lazydoctor" + ], + "type": "library", + "autoload": { + "psr-4": { + "LazyJsonMapper\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "SteveJobzniak", + "homepage": "https://github.com/SteveJobzniak", + "role": "Developer" + } + ], + "description": "Advanced, intelligent & automatic object-oriented JSON containers for PHP.", + "homepage": "https://github.com/SteveJobzniak/LazyJsonMapper", + "keywords": [ + "development", + "json" + ], + "time": "2018-05-02T16:57:09+00:00" + }, { "name": "phpcollection/phpcollection", "version": "0.5.0", diff --git a/src/Bot/Client.php b/src/Bot/Client.php index b8418f5..e248267 100644 --- a/src/Bot/Client.php +++ b/src/Bot/Client.php @@ -13,16 +13,12 @@ namespace RetailCrm\Mg\Bot; -use RetailCrm\Common\Deserializer; -use RetailCrm\Common\Exception\CurlException; use RetailCrm\Common\Exception\InvalidJsonException; use RetailCrm\Common\Url; use RetailCrm\Common\Serializer; use RetailCrm\Mg\Bot\Model\Response\AssignResponse; -use RetailCrm\Mg\Bot\Model\Response\GenericListResponse; use RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse; -use Exception; -use InvalidArgumentException; +use RetailCrm\Mg\Bot\Model\Response\ListResponse; use RetailCrm\Mg\Bot\Model\Response\MessageSendResponse; /** @@ -38,12 +34,11 @@ use RetailCrm\Mg\Bot\Model\Response\MessageSendResponse; class Client { const VERSION = 'v1'; + const ERROR_ONLY_RESPONSE = 'ErrorOnlyResponse'; - const ENTITY_CLASSPATH = 'RetailCrm\\Mg\\Bot\\Model\\Entity\\'; - const RESPONSE_MODEL_CLASSPATH = 'RetailCrm\\Mg\\Bot\\Model\\Response\\'; - const GENERIC_LIST_RESPONSE = self::RESPONSE_MODEL_CLASSPATH . 'GenericListResponse'; - const ERROR_ONLY_RESPONSE = self::RESPONSE_MODEL_CLASSPATH . 'ErrorOnlyResponse'; - + /** + * @var HttpClient + */ protected $client; /** @@ -65,18 +60,18 @@ class Client * @param object $request * @param string $responseType * @param int $serializeTo - * @param string $deserializeType + * @param bool $arrayOfObjects * - * @return object|null + * @return object|array|null * @throws \Exception */ private function getData( $path, $method, $request, - $responseType = self::GENERIC_LIST_RESPONSE, + $responseType, $serializeTo = Serializer::S_JSON, - $deserializeType = Deserializer::DS_JSON + $arrayOfObjects = false ) { $response = $this->client->makeRequest( $path, @@ -85,11 +80,54 @@ class Client $serializeTo ); - return Deserializer::deserialize( - (string) $response->getBody(), - $responseType, - $deserializeType - ); + $data = json_decode((string) $response->getBody(), true); + + if (json_last_error() == JSON_ERROR_NONE) { + if ($arrayOfObjects) { + return new ListResponse($responseType, $data); + } else { + return new $responseType($data); + } + } else { + throw new InvalidJsonException('Received invalid JSON', 1); + } + } + + /** + * @param bool $fromRoot + * @param string ...$classes + * + * @return string + */ + private static function concatClasspath($fromRoot, ...$classes) + { + $path = $fromRoot ? '\\' : ''; + + foreach($classes as $class) { + $path .= '\\' . $class; + } + + return str_replace('\\\\', '\\', $path); + } + + /** + * @param string ...$classes + * + * @return string + */ + private static function getEntityClass(...$classes) + { + return static::concatClasspath(true, 'RetailCrm', 'Mg', 'Bot', 'Model', 'Entity', ...$classes); + } + + /** + * @param string ...$classes + * + * @return string + */ + private static function getResponseClass(...$classes) + { + return static::concatClasspath(true, 'RetailCrm', 'Mg', 'Bot', 'Model', 'Response', ...$classes); } /** @@ -97,12 +135,8 @@ class Client * * @param Model\Request\BotsRequest $request * - * @throws InvalidArgumentException - * @throws CurlException - * @throws InvalidJsonException - * @throws Exception - * - * @return array + * @return ListResponse|object|null + * @throws \Exception */ public function bots(Model\Request\BotsRequest $request) { @@ -110,8 +144,9 @@ class Client '/bots', HttpClient::METHOD_GET, $request, - self::GENERIC_LIST_RESPONSE, - Serializer::S_ARRAY + static::getEntityClass('Bot', 'Bot'), + Serializer::S_ARRAY, + true ); } @@ -120,16 +155,17 @@ class Client * * @param Model\Request\InfoRequest $request * - * @throws InvalidArgumentException - * @throws CurlException - * @throws CurlException - * @throws Exception - * * @return ErrorOnlyResponse|object|null + * @throws \Exception */ public function info(Model\Request\InfoRequest $request) { - return $this->getData('/my/info', HttpClient::METHOD_PATCH, $request, self::ERROR_ONLY_RESPONSE); + return $this->getData( + '/my/info', + HttpClient::METHOD_PATCH, + $request, + static::getResponseClass(self::ERROR_ONLY_RESPONSE) + ); } /** @@ -137,16 +173,18 @@ class Client * * @param Model\Request\ChannelsRequest $request * - * @return array|object|null + * @return ListResponse|object|null * @throws \Exception */ public function channels(Model\Request\ChannelsRequest $request) { return $this->getData( '/channels', - HttpClient::METHOD_GET, $request, - \sprintf("array<%s%s>", self::ENTITY_CLASSPATH, 'Channel\\Channel'), - Serializer::S_ARRAY + HttpClient::METHOD_GET, + $request, + static::getEntityClass('Channel', 'Channel'), + Serializer::S_ARRAY, + true ); } @@ -155,12 +193,8 @@ class Client * * @param Model\Request\ChatsRequest $request * - * @throws InvalidArgumentException - * @throws CurlException - * @throws InvalidJsonException - * @throws Exception - * - * @return GenericListResponse|object|null + * @return ListResponse|object|null + * @throws \Exception */ public function chats(Model\Request\ChatsRequest $request) { @@ -168,8 +202,9 @@ class Client '/chats', HttpClient::METHOD_GET, $request, - self::GENERIC_LIST_RESPONSE, - Serializer::S_ARRAY + static::getEntityClass('Chat', 'Chat'), + Serializer::S_ARRAY, + true ); } @@ -178,20 +213,18 @@ class Client * * @param Model\Request\CommandsRequest $request * - * @throws InvalidArgumentException - * @throws CurlException - * @throws InvalidJsonException - * @throws Exception - * - * @return GenericListResponse|object|null + * @return ListResponse|object|null + * @throws \Exception */ public function commands(Model\Request\CommandsRequest $request) { return $this->getData( '/my/commands', - HttpClient::METHOD_GET, $request, - self::GENERIC_LIST_RESPONSE, - Serializer::S_ARRAY + HttpClient::METHOD_GET, + $request, + static::getEntityClass('Command'), + Serializer::S_ARRAY, + true ); } @@ -200,12 +233,8 @@ class Client * * @param Model\Request\CommandEditRequest $request * - * @throws InvalidArgumentException - * @throws CurlException - * @throws InvalidJsonException - * @throws Exception - * * @return ErrorOnlyResponse|object|null + * @throws \Exception */ public function commandEdit(Model\Request\CommandEditRequest $request) { @@ -213,7 +242,8 @@ class Client sprintf("/my/commands/%s", $request->getName()), HttpClient::METHOD_PUT, $request, - self::ERROR_ONLY_RESPONSE + static::getResponseClass(self::ERROR_ONLY_RESPONSE), + true ); } @@ -222,21 +252,17 @@ class Client * * @param string $request * - * @throws InvalidArgumentException - * @throws CurlException - * @throws InvalidJsonException - * @throws Exception - * * @return ErrorOnlyResponse|object|null + * @throws \Exception */ public function commandDelete(string $request) { - $response = $this->client->makeRequest(sprintf("/my/commands/%s", $request), HttpClient::METHOD_DELETE); - - return Deserializer::deserialize( - $response->getResponse(), - self::ERROR_ONLY_RESPONSE, - Deserializer::DS_ARRAY + return $this->getData( + sprintf("/my/commands/%s", $request), + HttpClient::METHOD_DELETE, + null, + static::getResponseClass(self::ERROR_ONLY_RESPONSE), + Serializer::S_JSON ); } @@ -245,12 +271,8 @@ class Client * * @param Model\Request\CustomersRequest $request * - * @throws InvalidArgumentException - * @throws CurlException - * @throws InvalidJsonException - * @throws Exception - * - * @return GenericListResponse|object|null + * @return ListResponse|object|null + * @throws \Exception */ public function customers(Model\Request\CustomersRequest $request) { @@ -258,8 +280,9 @@ class Client '/customers', HttpClient::METHOD_GET, $request, - self::GENERIC_LIST_RESPONSE, - Serializer::S_ARRAY + static::getEntityClass('Customer'), + Serializer::S_ARRAY, + true ); } @@ -268,12 +291,8 @@ class Client * * @param Model\Request\DialogsRequest $request * - * @throws InvalidArgumentException - * @throws CurlException - * @throws InvalidJsonException - * @throws Exception - * - * @return GenericListResponse|object|null + * @return ListResponse|object|null + * @throws \Exception */ public function dialogs(Model\Request\DialogsRequest $request) { @@ -281,8 +300,9 @@ class Client '/dialogs', HttpClient::METHOD_GET, $request, - self::GENERIC_LIST_RESPONSE, - Serializer::S_ARRAY + static::getEntityClass('Dialog'), + Serializer::S_ARRAY, + true ); } @@ -291,12 +311,8 @@ class Client * * @param Model\Request\DialogAssignRequest $request * - * @throws InvalidArgumentException - * @throws CurlException - * @throws InvalidJsonException - * @throws Exception - * * @return AssignResponse|object|null + * @throws \Exception */ public function dialogAssign(Model\Request\DialogAssignRequest $request) { @@ -304,7 +320,8 @@ class Client sprintf("/dialogs/%d/assign", $request->getDialogId()), HttpClient::METHOD_PATCH, $request, - self::RESPONSE_MODEL_CLASSPATH . 'AssignResponse' + static::getResponseClass('AssignResponse'), + Serializer::S_JSON ); } @@ -313,12 +330,8 @@ class Client * * @param string $request * - * @throws InvalidArgumentException - * @throws CurlException - * @throws InvalidJsonException - * @throws Exception - * * @return ErrorOnlyResponse|object|null + * @throws \Exception */ public function dialogClose(string $request) { @@ -326,7 +339,7 @@ class Client sprintf("/dialogs/%d/close", $request), HttpClient::METHOD_DELETE, null, - self::ERROR_ONLY_RESPONSE + static::getResponseClass(self::ERROR_ONLY_RESPONSE) ); } @@ -335,12 +348,8 @@ class Client * * @param Model\Request\MembersRequest $request * - * @throws InvalidArgumentException - * @throws CurlException - * @throws InvalidJsonException - * @throws Exception - * - * @return GenericListResponse|object|null + * @return ListResponse|object|null + * @throws \Exception */ public function members(Model\Request\MembersRequest $request) { @@ -348,8 +357,9 @@ class Client '/members', HttpClient::METHOD_GET, $request, - self::GENERIC_LIST_RESPONSE, - Serializer::S_ARRAY + static::getEntityClass('Chat', 'ChatMember'), + Serializer::S_ARRAY, + true ); } @@ -358,12 +368,8 @@ class Client * * @param Model\Request\MessagesRequest $request * - * @throws InvalidArgumentException - * @throws CurlException - * @throws InvalidJsonException - * @throws Exception - * - * @return GenericListResponse|object|null + * @return ListResponse|object|null + * @throws \Exception */ public function messages(Model\Request\MessagesRequest $request) { @@ -371,8 +377,9 @@ class Client '/messages', HttpClient::METHOD_GET, $request, - self::GENERIC_LIST_RESPONSE, - Serializer::S_ARRAY + self::getEntityClass('Message', 'Message'), + Serializer::S_ARRAY, + true ); } @@ -381,12 +388,8 @@ class Client * * @param Model\Request\MessageSendRequest $request * - * @throws InvalidArgumentException - * @throws CurlException - * @throws InvalidJsonException - * @throws Exception - * * @return MessageSendResponse|object|null + * @throws \Exception */ public function messageSend(Model\Request\MessageSendRequest $request) { @@ -394,7 +397,7 @@ class Client '/messages', HttpClient::METHOD_POST, $request, - self::RESPONSE_MODEL_CLASSPATH . 'MessageSendResponse' + static::getResponseClass('MessageSendResponse') ); } @@ -403,12 +406,8 @@ class Client * * @param Model\Request\MessageEditRequest $request * - * @throws InvalidArgumentException - * @throws CurlException - * @throws InvalidJsonException - * @throws Exception - * * @return MessageSendResponse|object|null + * @throws \Exception */ public function messageEdit(Model\Request\MessageEditRequest $request) { @@ -416,7 +415,7 @@ class Client sprintf("/messages/%d", $request->getId()), HttpClient::METHOD_PATCH, $request, - self::RESPONSE_MODEL_CLASSPATH . 'MessageSendResponse' + static::getResponseClass('MessageSendResponse') ); } @@ -425,12 +424,8 @@ class Client * * @param string $request * - * @throws InvalidArgumentException - * @throws CurlException - * @throws InvalidJsonException - * @throws Exception - * * @return ErrorOnlyResponse|object|null + * @throws \Exception */ public function messageDelete(string $request) { @@ -438,7 +433,7 @@ class Client sprintf("/messages/%d", $request), HttpClient::METHOD_DELETE, null, - self::ERROR_ONLY_RESPONSE + static::getResponseClass(self::ERROR_ONLY_RESPONSE) ); } @@ -447,12 +442,8 @@ class Client * * @param Model\Request\UsersRequest $request * - * @throws InvalidArgumentException - * @throws CurlException - * @throws InvalidJsonException - * @throws Exception - * - * @return GenericListResponse|object|null + * @return ListResponse|object|null + * @throws \Exception */ public function users(Model\Request\UsersRequest $request) { @@ -460,8 +451,9 @@ class Client '/users', HttpClient::METHOD_GET, $request, - self::GENERIC_LIST_RESPONSE, - Serializer::S_ARRAY + self::getEntityClass('User'), + Serializer::S_ARRAY, + true ); } } diff --git a/src/Bot/Model/Entity/Bot/Bot.php b/src/Bot/Model/Entity/Bot/Bot.php new file mode 100644 index 0000000..fd5318b --- /dev/null +++ b/src/Bot/Model/Entity/Bot/Bot.php @@ -0,0 +1,60 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Bot; + +use RetailCrm\Mg\Bot\Model\Entity\CommonFields; + +/** + * PHP version 7.0 + * + * Bot class + * + * @package RetailCrm\Mg\Bot\Model\Entity\Bot + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + * @method string getName() + * @method $this setName(string $value) + * @method array getEvents() + * @method $this setEvents(array $value) + * @method string getClientId() + * @method $this setClientId(string $value) + * @method string getAvatarUrl() + * @method $this setAvatarUrl(string $value) + * @method array getRoles() + * @method $this setRoles(array $value) + * @method string getDeactivatedAt() + * @method $this setDeactivatedAt(string $value) + * @method bool getIsActive() + * @method $this setIsActive(bool $value) + * @method bool getIsSelf() + * @method $this setIsSelf(bool $value) + * @method bool getIsSystem() + * @method $this setIsSystem(bool $value) + */ +class Bot extends CommonFields +{ + const JSON_PROPERTY_MAP = [ + 'name' => 'string', + 'events' => '[]', + 'client_id' => 'string', + 'avatar_url' => 'string', + 'roles' => '[]', + 'deactivated_at' => 'string', + 'is_active' => 'bool', + 'is_self' => 'bool', + 'is_system' => 'bool' + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Channel/Channel.php b/src/Bot/Model/Entity/Channel/Channel.php index 119fbb0..394ec3f 100644 --- a/src/Bot/Model/Entity/Channel/Channel.php +++ b/src/Bot/Model/Entity/Channel/Channel.php @@ -5,7 +5,7 @@ * * Channel entity * - * @package RetailCrm\Mg\Bot\Model\Entity + * @package RetailCrm\Mg\Bot\Model\Entity\Channel * @author retailCRM * @license https://opensource.org/licenses/MIT MIT License * @link http://help.retailcrm.pro/docs/Developers @@ -13,12 +13,6 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Channel; -use JMS\Serializer\Annotation as Serializer; -use JMS\Serializer\Annotation\SerializedName; -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\SkipWhenEmpty; -use JMS\Serializer\Annotation\Type; -use RetailCrm\Mg\Bot\Model\Entity\Channel\ChannelSettings; use RetailCrm\Mg\Bot\Model\Entity\CommonFields; /** @@ -26,159 +20,32 @@ use RetailCrm\Mg\Bot\Model\Entity\CommonFields; * * Channel class * - * @package RetailCrm\Mg\Bot\Model\Entity + * @package RetailCrm\Mg\Bot\Model\Entity\Channel * @author retailCRM * @license https://opensource.org/licenses/MIT MIT License * @link http://help.retailcrm.pro/docs/Developers + * + * @method string getActivatedAt() + * @method $this setActivatedAt(string $value) + * @method string getDeactivatedAt() + * @method $this setDeactivatedAt(string $value) + * @method bool getIsActive(bool $value) + * @method $this setIsActive() + * @method ChannelSettings getChannelSettings() + * @method $this setChannelSettings(ChannelSettings $value) + * @method string getType() + * @method $this setType(string $value) + * @method string getName() + * @method $this setName(string $value) */ -class Channel +class Channel extends CommonFields { - use CommonFields; - - /** - * @var \DateTime - * - * @Type("DateTime<'Y-m-d\TH:i:s.u\Z'>") - * @Accessor(setter="setActivatedAt", getter="getActivatedAt") - */ - private $activatedAt; - - /** - * @var \DateTime - * - * @Type("DateTime<'Y-m-d\TH:i:s.u\Z'>") - * @Accessor(setter="setDeactivatedAt", getter="getDeactivatedAt") - * @SkipWhenEmpty() - */ - private $deactivatedAt; - - /** - * @var bool - * - * @Type("bool") - * @Accessor(setter="getIsActive", getter="setIsActive") - * @SerializedName("is_active") - */ - private $isActive; - - /** - * @var array - * - * @Type("array") - * @Accessor(setter="setSettings", getter="getSettings") - */ - private $settings; - - /** - * @var string - * - * @Type("string") - * @Accessor(setter="setType", getter="getType") - */ - private $type; - - /** - * @var string - * - * @Type("string") - * @Accessor(setter="setName", getter="getName") - * @SkipWhenEmpty() - */ - private $name; - - /** - * @return \DateTime - */ - public function getActivatedAt(): \DateTime - { - return $this->activatedAt; - } - - /** - * @param \DateTime $activatedAt - */ - public function setActivatedAt(\DateTime $activatedAt) - { - $this->activatedAt = $activatedAt; - } - - /** - * @return \DateTime - */ - public function getDeactivatedAt(): \DateTime - { - return $this->deactivatedAt; - } - - /** - * @param \DateTime $deactivatedAt - */ - public function setDeactivatedAt($deactivatedAt) - { - $this->deactivatedAt = $deactivatedAt; - } - - /** - * @return bool - */ - public function getIsActive() - { - return $this->isActive; - } - - /** - * @param bool $isActive - */ - public function setIsActive(bool $isActive) - { - $this->isActive = $isActive; - } - - /** - * @return array - */ - public function getSettings(): array - { - return $this->settings; - } - - /** - * @param array $settings - */ - public function setSettings(array $settings) - { - $this->settings = $settings; - } - - /** - * @return string - */ - public function getType(): string - { - return $this->type; - } - - /** - * @param string $type - */ - public function setType(string $type) - { - $this->type = $type; - } - - /** - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * @param string $name - */ - public function setName($name) - { - $this->name = $name; - } + const JSON_PROPERTY_MAP = [ + 'activated_at' => 'string', + 'deactivated_at' => 'string', + 'is_active' => 'bool', + 'settings' => 'ChannelSettings', + 'type' => 'string', + 'name' => 'string' + ]; } \ No newline at end of file diff --git a/src/Bot/Model/Entity/Channel/ChannelProductSettings.php b/src/Bot/Model/Entity/Channel/ChannelProductSettings.php deleted file mode 100644 index 72b35e5..0000000 --- a/src/Bot/Model/Entity/Channel/ChannelProductSettings.php +++ /dev/null @@ -1,126 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ - -namespace RetailCrm\Mg\Bot\Model\Entity\Channel; - -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\Type; - -/** - * PHP version 7.0 - * - * ChannelProductSettings class - * - * @package RetailCrm\Mg\Bot\Model\Entity - * @author retailCRM - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ -class ChannelProductSettings -{ - /** - * @var string - * - * @Type("string") - * @Accessor(setter="setCreating", getter="getCreating") - */ - private $creating; - - /** - * @var string - * - * @Type("string") - * @Accessor(setter="setEditing", getter="getEditing") - */ - private $editing; - - /** - * @var string - * - * @Type("string") - * @Accessor(setter="setDeleting", getter="getDeleting") - */ - private $deleting; - - /** - * @var string - * - * @Type("string") - * @Accessor(setter="setQuoting", getter="getQuoting") - */ - private $quoting; - - /** - * @return string - */ - public function getCreating(): string - { - return $this->creating; - } - - /** - * @param string $creating - */ - public function setCreating(string $creating) - { - $this->creating = $creating; - } - - /** - * @return string - */ - public function getEditing(): string - { - return $this->editing; - } - - /** - * @param string $editing - */ - public function setEditing(string $editing) - { - $this->editing = $editing; - } - - /** - * @return string - */ - public function getDeleting(): string - { - return $this->deleting; - } - - /** - * @param string $deleting - */ - public function setDeleting(string $deleting) - { - $this->deleting = $deleting; - } - - /** - * @return string - */ - public function getQuoting(): string - { - return $this->quoting; - } - - /** - * @param string $quoting - */ - public function setQuoting(string $quoting) - { - $this->quoting = $quoting; - } -} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Channel/ChannelSettings.php b/src/Bot/Model/Entity/Channel/ChannelSettings.php index c92a1dc..97b2c4e 100644 --- a/src/Bot/Model/Entity/Channel/ChannelSettings.php +++ b/src/Bot/Model/Entity/Channel/ChannelSettings.php @@ -5,7 +5,7 @@ * * ChannelSettings entity * - * @package RetailCrm\Mg\Bot\Model\Entity + * @package RetailCrm\Mg\Bot\Model\Entity\Channel * @author retailCRM * @license https://opensource.org/licenses/MIT MIT License * @link http://help.retailcrm.pro/docs/Developers @@ -13,92 +13,39 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Channel; -use JMS\Serializer\Annotation as Serializer; -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\SkipWhenEmpty; -use JMS\Serializer\Annotation\Type; +use LazyJsonMapper\LazyJsonMapper; /** * PHP version 7.0 * * ChannelSettings class * - * @package RetailCrm\Mg\Bot\Model\Entity + * @package RetailCrm\Mg\Bot\Model\Entity\Channel * @author retailCRM * @license https://opensource.org/licenses/MIT MIT License * @link http://help.retailcrm.pro/docs/Developers + * + * @method ChannelSettingsItem getStatus() + * @method $this setStatus(ChannelSettingsItem $value) + * @method ChannelSettingsItem getText() + * @method $this setText(ChannelSettingsItem $value) + * @method ChannelSettingsItem getProduct() + * @method $this setProduct(ChannelSettingsItem $value) + * @method ChannelSettingsItem getOrder() + * @method $this setOrder(ChannelSettingsItem $value) + * @method ChannelSettingsItem getImage() + * @method $this setImage(ChannelSettingsItem $value) + * @method ChannelSettingsItem getFile() + * @method $this setFile(ChannelSettingsItem $value) */ -class ChannelSettings +class ChannelSettings extends LazyJsonMapper { - /** - * @var int - * - * @Type("int") - * @Accessor(setter="setSpamAllowed", getter="getSpamAllowed") - */ - private $spamAllowed; - - /** - * @var ChannelSettingsStatus - * - * @Type("RetailCrm\Mg\Bot\Model\Entity\Channel\ChannelSettingsStatus") - * @Accessor(setter="setStatus", getter="getStatus") - */ - private $status; - - /** - * @var ChannelTextSettings - * - * @Type("RetailCrm\Mg\Bot\Model\Entity\Channel\ChannelTextSettings") - * @Accessor(setter="setText", getter="getText") - */ - private $text; - - /** - * @return int - */ - public function getSpamAllowed(): int - { - return $this->spamAllowed; - } - - /** - * @param int $spamAllowed - */ - public function setSpamAllowed(int $spamAllowed) - { - $this->spamAllowed = $spamAllowed; - } - - /** - * @return ChannelSettingsStatus - */ - public function getStatus(): ChannelSettingsStatus - { - return $this->status; - } - - /** - * @param ChannelSettingsStatus $status - */ - public function setStatus(ChannelSettingsStatus $status) - { - $this->status = $status; - } - - /** - * @return ChannelTextSettings - */ - public function getText(): ChannelTextSettings - { - return $this->text; - } - - /** - * @param ChannelTextSettings $text - */ - public function setText(ChannelTextSettings $text) - { - $this->text = $text; - } + const JSON_PROPERTY_MAP = [ + 'status' => 'ChannelSettingsItem', + 'text' => 'ChannelSettingsItem', + 'product' => 'ChannelSettingsItem', + 'order' => 'ChannelSettingsItem', + 'image' => 'ChannelSettingsItem', + 'file' => 'ChannelSettingsItem' + ]; } \ No newline at end of file diff --git a/src/Bot/Model/Entity/Channel/ChannelSettingsItem.php b/src/Bot/Model/Entity/Channel/ChannelSettingsItem.php new file mode 100644 index 0000000..ff90775 --- /dev/null +++ b/src/Bot/Model/Entity/Channel/ChannelSettingsItem.php @@ -0,0 +1,55 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Channel; + +use JMS\Serializer\Annotation as Serializer; +use JMS\Serializer\Annotation\Accessor; +use JMS\Serializer\Annotation\SkipWhenEmpty; +use JMS\Serializer\Annotation\Type; +use LazyJsonMapper\LazyJsonMapper; + +/** + * PHP version 7.0 + * + * ChannelSettingsItem class + * + * @package RetailCrm\Mg\Bot\Model\Entity\Channel + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + * @method string getCreating() + * @method $this setCreating(string $value) + * @method string getEditing() + * @method $this setEditing(string $value) + * @method string getQuoting() + * @method $this setQuoting(string $value) + * @method string getDeleting() + * @method $this setDeleting(string $value) + * @method string getDelivered() + * @method $this setDelivered(string $value) + * @method int getMaxItemsCount() + * @method $this setMaxItemsCount(int $value) + */ +class ChannelSettingsItem extends LazyJsonMapper +{ + const JSON_PROPERTY_MAP = [ + 'creating' => 'string', + 'editing' => 'string', + 'quoting' => 'string', + 'deleting' => 'string', + 'delivered' => 'string', + 'max_items_count' => 'int' + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Channel/ChannelSettingsStatus.php b/src/Bot/Model/Entity/Channel/ChannelSettingsStatus.php deleted file mode 100644 index 5ffd89d..0000000 --- a/src/Bot/Model/Entity/Channel/ChannelSettingsStatus.php +++ /dev/null @@ -1,78 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ - -namespace RetailCrm\Mg\Bot\Model\Entity\Channel; - -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\Type; - -/** - * PHP version 7.0 - * - * ChannelSettingsStatus class - * - * @package RetailCrm\Mg\Bot\Model\Entity - * @author retailCRM - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ -class ChannelSettingsStatus -{ - /** - * @var string - * - * @Type("string") - * @Accessor(setter="setDelivered", getter="getDelivered") - */ - private $delivered; - - /** - * @var string - * - * @Type("string") - * @Accessor(setter="setRead", getter="getRead") - */ - private $read; - - /** - * @return string - */ - public function getDelivered(): string - { - return $this->delivered; - } - - /** - * @param string $delivered - */ - public function setDelivered(string $delivered) - { - $this->delivered = $delivered; - } - - /** - * @return string - */ - public function getRead(): string - { - return $this->read; - } - - /** - * @param string $read - */ - public function setRead(string $read) - { - $this->read = $read; - } -} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Channel/ChannelTextSettings.php b/src/Bot/Model/Entity/Channel/ChannelTextSettings.php deleted file mode 100644 index 2732302..0000000 --- a/src/Bot/Model/Entity/Channel/ChannelTextSettings.php +++ /dev/null @@ -1,126 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ - -namespace RetailCrm\Mg\Bot\Model\Entity\Channel; - -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\Type; - -/** - * PHP version 7.0 - * - * ChannelTextSettings class - * - * @package RetailCrm\Mg\Bot\Model\Entity - * @author retailCRM - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ -class ChannelTextSettings -{ - /** - * @var string - * - * @Type("string") - * @Accessor(setter="setCreating", getter="getCreating") - */ - private $creating; - - /** - * @var string - * - * @Type("string") - * @Accessor(setter="setEditing", getter="getEditing") - */ - private $editing; - - /** - * @var string - * - * @Type("string") - * @Accessor(setter="setDeleting", getter="getDeleting") - */ - private $deleting; - - /** - * @var string - * - * @Type("string") - * @Accessor(setter="setQuoting", getter="getQuoting") - */ - private $quoting; - - /** - * @return string - */ - public function getCreating(): string - { - return $this->creating; - } - - /** - * @param string $creating - */ - public function setCreating(string $creating) - { - $this->creating = $creating; - } - - /** - * @return string - */ - public function getEditing(): string - { - return $this->editing; - } - - /** - * @param string $editing - */ - public function setEditing(string $editing) - { - $this->editing = $editing; - } - - /** - * @return string - */ - public function getDeleting(): string - { - return $this->deleting; - } - - /** - * @param string $deleting - */ - public function setDeleting(string $deleting) - { - $this->deleting = $deleting; - } - - /** - * @return string - */ - public function getQuoting(): string - { - return $this->quoting; - } - - /** - * @param string $quoting - */ - public function setQuoting(string $quoting) - { - $this->quoting = $quoting; - } -} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Chat/Chat.php b/src/Bot/Model/Entity/Chat/Chat.php new file mode 100644 index 0000000..f26efd1 --- /dev/null +++ b/src/Bot/Model/Entity/Chat/Chat.php @@ -0,0 +1,41 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Chat; + +use RetailCrm\Mg\Bot\Model\Entity\CommonFields; + +/** + * PHP version 7.0 + * + * Chat class + * + * @package RetailCrm\Mg\Bot\Model\Entity\Chat + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + */ +class Chat extends CommonFields +{ + const JSON_PROPERTY_MAP = [ + 'avatar' => 'string', + 'name' => 'string', + 'channel' => '\RetailCrm\Mg\Bot\Model\Entity\Channel\Channel', + 'members' => 'ChatMember[]', + 'customer' => '\RetailCrm\Mg\Bot\Model\Entity\Customer', + 'author_id' => 'int', + 'last_message' => 'ChatLastMessage', + 'last_activity' => 'string' + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Chat/ChatLastMessage.php b/src/Bot/Model/Entity/Chat/ChatLastMessage.php new file mode 100644 index 0000000..0c0e557 --- /dev/null +++ b/src/Bot/Model/Entity/Chat/ChatLastMessage.php @@ -0,0 +1,43 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Chat; + + +use LazyJsonMapper\LazyJsonMapper; + +/** + * PHP version 7.0 + * + * ChatLastMessage class + * + * @package RetailCrm\Mg\Bot\Model\Entity\Chat + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + * @method int getId() + * @method $this setId(int $value) + * @method string getTime() + * @method $this setTime(string $value) + * @method string getType() + * @method $this setType(string $value) + */ +class ChatLastMessage extends LazyJsonMapper +{ + const JSON_PROPERTY_MAP = [ + 'id' => 'int', + 'time' => 'string', + 'type' => 'string' + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Chat/ChatMember.php b/src/Bot/Model/Entity/Chat/ChatMember.php new file mode 100644 index 0000000..2d1fc32 --- /dev/null +++ b/src/Bot/Model/Entity/Chat/ChatMember.php @@ -0,0 +1,45 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Chat; + +use RetailCrm\Mg\Bot\Model\Entity\CommonFields; + +/** + * PHP version 7.0 + * + * ChatMember class + * + * @package RetailCrm\Mg\Bot\Model\Entity\Chat + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + * @method int getChatId() + * @method $this setChatId(int $value) + * @method int getUserId() + * @method $this setUserId(int $value) + * @method bool getIsAuthor() + * @method $this setIsAuthor(bool $value) + * @method string getState() + * @method $this setState(string $value) + */ +class ChatMember extends CommonFields +{ + const JSON_PROPERTY_MAP = [ + 'chat_id' => 'int', + 'user_id' => 'int', + 'is_author' => 'bool', + 'state' => 'string' + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Command.php b/src/Bot/Model/Entity/Command.php new file mode 100644 index 0000000..e3c1391 --- /dev/null +++ b/src/Bot/Model/Entity/Command.php @@ -0,0 +1,37 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity; + +/** + * PHP version 7.0 + * + * Command class + * + * @package RetailCrm\Mg\Bot\Model\Entity + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + * @method string getName() + * @method $this setName(string $value) + * @method string getDescription() + * @method $this setDescription(string $value) + */ +class Command extends CommonFields +{ + const JSON_PROPERTY_MAP = [ + 'name' => 'string', + 'description' => 'string' + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/CommonFields.php b/src/Bot/Model/Entity/CommonFields.php index 3b3b3a2..630a952 100644 --- a/src/Bot/Model/Entity/CommonFields.php +++ b/src/Bot/Model/Entity/CommonFields.php @@ -16,6 +16,7 @@ namespace RetailCrm\Mg\Bot\Model\Entity; use JMS\Serializer\Annotation\Accessor; use JMS\Serializer\Annotation\SkipWhenEmpty; use JMS\Serializer\Annotation\Type; +use LazyJsonMapper\LazyJsonMapper; /** * PHP version 7.0 @@ -27,80 +28,11 @@ use JMS\Serializer\Annotation\Type; * @license https://opensource.org/licenses/MIT MIT License * @link http://help.retailcrm.pro/docs/Developers */ -trait CommonFields +class CommonFields extends LazyJsonMapper { - /** - * @var int - * - * @Type("int") - * @Accessor(setter="setId", getter="getId") - * @SkipWhenEmpty() - */ - private $id; - - /** - * @var DateTime - * - * @Type("DateTime<'Y-m-d\TH:i:s.u\Z'>") - * @Accessor(setter="setCreatedAt", getter="getCreatedAt") - * @SkipWhenEmpty() - */ - private $createdAt; - - /** - * @var string - * - * @Type("DateTime<'Y-m-d\TH:i:s.u\Z'>") - * @Accessor(setter="setUpdatedAt", getter="getUpdatedAt") - * @SkipWhenEmpty() - */ - private $updatedAt; - - /** - * @return int - */ - public function getId(): int - { - return $this->id; - } - - /** - * @param int $id - */ - public function setId(int $id) - { - $this->id = $id; - } - - /** - * @return \DateTime - */ - public function getCreatedAt(): \DateTime - { - return $this->createdAt; - } - - /** - * @param \DateTime $createdAt - */ - public function setCreatedAt(\DateTime $createdAt) - { - $this->createdAt = $createdAt; - } - - /** - * @return \DateTime - */ - public function getUpdatedAt(): \DateTime - { - return $this->updatedAt; - } - - /** - * @param \DateTime $updatedAt - */ - public function setUpdatedAt(\DateTime $updatedAt) - { - $this->updatedAt = $updatedAt; - } + const JSON_PROPERTY_MAP = [ + 'id' => 'int', + 'created_at' => 'string', + 'updated_at' => 'string' + ]; } \ No newline at end of file diff --git a/src/Bot/Model/Entity/Cost.php b/src/Bot/Model/Entity/Cost.php deleted file mode 100644 index 2727732..0000000 --- a/src/Bot/Model/Entity/Cost.php +++ /dev/null @@ -1,82 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ - -namespace RetailCrm\Mg\Bot\Model\Entity; - -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\SkipWhenEmpty; -use JMS\Serializer\Annotation\Type; - -/** - * PHP version 7.0 - * - * Cost class - * - * @package RetailCrm\Mg\Bot\Model\Entity - * @author retailCRM - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ -class Cost -{ - /** - * @var float $value - * - * @Type("float") - * @Accessor(getter="getValue",setter="setValue") - * @SkipWhenEmpty() - */ - private $value; - - /** - * @var string $currency - * - * @Type("string") - * @Accessor(getter="getCurrency",setter="setCurrency") - * - * @Assert\Currency - */ - private $currency; - - /** - * @return float - */ - public function getValue() - { - return $this->value; - } - - /** - * @param float $value - */ - public function setValue(float $value) - { - $this->value = $value; - } - - /** - * @return string - */ - public function getCurrency() - { - return $this->currency; - } - - /** - * @param string $currency - */ - public function setCurrency(string $currency) - { - $this->currency = $currency; - } -} diff --git a/src/Bot/Model/Entity/Customer.php b/src/Bot/Model/Entity/Customer.php new file mode 100644 index 0000000..0238e38 --- /dev/null +++ b/src/Bot/Model/Entity/Customer.php @@ -0,0 +1,69 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity; + +use RetailCrm\Mg\Bot\Model\Entity\CommonFields; + +/** + * PHP version 7.0 + * + * Customer class + * + * @package RetailCrm\Mg\Bot\Model\Entity + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + * @method string getExternalId() + * @method $this setExternalId(string $value) + * @method int getChannelId() + * @method $this setChannelId(int $value) + * @method string getUsername() + * @method $this setUsername(string $value) + * @method string getFirstName() + * @method $this setFirstName(string $value) + * @method string getLastName() + * @method $this setLastName(string $value) + * @method string getAvatarUrl() + * @method $this setAvatarUrl(string $value) + * @method string getProfileUrl() + * @method $this setProfileUrl(string $value) + * @method string getRevokedAt() + * @method $this setRevokedAt(string $value) + * @method string getCountry() + * @method $this setCountry(string $value) + * @method string getLanguage() + * @method $this setLanguage(string $value) + * @method string getPhone() + * @method $this setPhone(string $value) + * @method string getEmail() + * @method $this setEmail(string $value) + */ +class Customer extends CommonFields +{ + const JSON_PROPERTY_MAP = [ + 'external_id' => 'string', + 'channel_id' => 'int', + 'username' => 'string', + 'first_name' => 'string', + 'last_name' => 'string', + 'avatar_url' => 'string', + 'profile_url' => 'string', + 'revoked_at' => 'string', + 'country' => 'string', + 'language' => 'string', + 'phone' => 'string', + 'email' => 'string' + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Delivery.php b/src/Bot/Model/Entity/Delivery.php deleted file mode 100644 index 2de1bbc..0000000 --- a/src/Bot/Model/Entity/Delivery.php +++ /dev/null @@ -1,133 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ - -namespace RetailCrm\Mg\Bot\Model\Entity; - -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\SkipWhenEmpty; -use JMS\Serializer\Annotation\Type; - -/** - * PHP version 7.0 - * - * Delivery class - * - * @package RetailCrm\Mg\Bot\Model\Entity - * @author retailCRM - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ -class Delivery -{ - /** - * @var string $name - * - * @Type("string") - * @Accessor(getter="getName",setter="setName") - * - * @Assert\NotBlank - */ - private $name; - - /** - * @var Cost $price - * - * @Type("Cost") - * @Accessor(getter="getPrice",setter="setPrice") - * - * @Assert\Currency - */ - private $price; - - /** - * @var string $address - * - * @Type("string") - * @Accessor(getter="getAddress",setter="setAddress") - * @SkipWhenEmpty() - */ - private $address; - - /** - * @var string $comment - * - * @Type("string") - * @Accessor(getter="getComment",setter="setComment") - * @SkipWhenEmpty() - */ - private $comment; - - /** - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * @param string $name - */ - public function setName(string $name) - { - $this->name = $name; - } - - /** - * @return Cost - */ - public function getPrice() - { - return $this->price; - } - - /** - * @param Cost $price - */ - public function setPrice(Cost $price) - { - $this->price = $price; - } - - /** - * @return string - */ - public function getAddress() - { - return $this->address; - } - - /** - * @param string $address - */ - public function setAddress(string $address) - { - $this->address = $address; - } - - /** - * @return string - */ - public function getComment() - { - return $this->comment; - } - - /** - * @param string $comment - */ - public function setComment(string $comment) - { - $this->comment = $comment; - } -} diff --git a/src/Bot/Model/Entity/Dialog.php b/src/Bot/Model/Entity/Dialog.php new file mode 100644 index 0000000..f54f46b --- /dev/null +++ b/src/Bot/Model/Entity/Dialog.php @@ -0,0 +1,57 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity; + +use RetailCrm\Mg\Bot\Model\Entity\CommonFields; + +/** + * PHP version 7.0 + * + * Dialog class + * + * @package RetailCrm\Mg\Bot\Model\Entity + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + * @method int getBotId() + * @method $this setBotId(int $value) + * @method int getChatId() + * @method $this setChatId(int $value) + * @method int getBeginMessageId() + * @method $this setBeginMessageId(int $value) + * @method int getEndingMessageId() + * @method $this setEndingMessageId(int $value) + * @method string getClosedAt() + * @method $this setClosedAt(string $value) + * @method bool getIsAssigned() + * @method $this setIsAssigned(bool $value) + * @method Responsible getResponsible() + * @method $this setResponsible(Responsible $value) + * @method bool getIsActive() + * @method $this setIsActive(bool $value) + */ +class Dialog extends CommonFields +{ + const JSON_PROPERTY_MAP = [ + 'bot_id' => 'int', + 'chat_id' => 'int', + 'begin_message_id' => 'int', + 'ending_message_id' => 'int', + 'closed_at' => 'string', + 'is_assigned' => 'bool', + 'responsible' => 'Responsible', + 'is_active' => 'bool' + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Error.php b/src/Bot/Model/Entity/Error.php deleted file mode 100644 index e40c43b..0000000 --- a/src/Bot/Model/Entity/Error.php +++ /dev/null @@ -1,56 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ - -namespace RetailCrm\Mg\Bot\Model\Entity; - -use JMS\Serializer\Annotation as Serializer; -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\Type; - -/** - * PHP version 7.0 - * - * Error class - * - * @package RetailCrm\Mg\Bot\Model\Entity - * @author retailCRM - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ -class Error -{ - /** - * @var array $messages - * - * @Type("array") - * @Accessor(getter="getMessages",setter="setMessages") - * @Serializer\SkipWhenEmpty() - */ - private $messages; - - /** - * @return array - */ - public function getMessages(): array - { - return $this->messages; - } - - /** - * @param array $messages - */ - public function setMessages(array $messages) - { - $this->messages = $messages; - } -} diff --git a/src/Bot/Model/Entity/FileMeta.php b/src/Bot/Model/Entity/FileMeta.php index 8de3e2a..1450628 100644 --- a/src/Bot/Model/Entity/FileMeta.php +++ b/src/Bot/Model/Entity/FileMeta.php @@ -3,7 +3,7 @@ /** * PHP version 7.0 * - * Responsible entity + * FileMeta entity * * @package RetailCrm\Mg\Bot\Model\Entity * @author retailCRM @@ -13,69 +13,22 @@ namespace RetailCrm\Mg\Bot\Model\Entity; -use JMS\Serializer\Annotation\SkipWhenEmpty; -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\Type; +use LazyJsonMapper\LazyJsonMapper; /** * PHP version 7.0 * - * Responsible class + * FileMeta class * * @package RetailCrm\Mg\Bot\Model\Entity * @author retailCRM * @license https://opensource.org/licenses/MIT MIT License * @link http://help.retailcrm.pro/docs/Developers */ -class FileMeta +class FileMeta extends LazyJsonMapper { - /** - * @var int $height - * - * @Type("int") - * @Accessor(setter="setHeight", getter="getHeight") - * @SkipWhenEmpty() - */ - private $height; - - /** - * @var int $width - * - * @Type("int") - * @Accessor(setter="setWidth", getter="getWidth") - * @SkipWhenEmpty() - */ - private $width; - - /** - * @return int - */ - public function getHeight(): int - { - return $this->height; - } - - /** - * @param int $height - */ - public function setHeight(int $height) - { - $this->height = $height; - } - - /** - * @return int - */ - public function getWidth(): int - { - return $this->width; - } - - /** - * @param int $width - */ - public function setWidth(int $width) - { - $this->width = $width; - } + const JSON_PROPERTY_MAP = [ + 'height' => 'int', + 'width' => 'int' + ]; } \ No newline at end of file diff --git a/src/Bot/Model/Entity/Item.php b/src/Bot/Model/Entity/Item.php deleted file mode 100644 index 9e6ad82..0000000 --- a/src/Bot/Model/Entity/Item.php +++ /dev/null @@ -1,81 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ - -namespace RetailCrm\Mg\Bot\Model\Entity; - -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\SkipWhenEmpty; -use JMS\Serializer\Annotation\Type; - -/** - * PHP version 7.0 - * - * Item class - * - * @package RetailCrm\Mg\Bot\Model\Entity - * @author retailCRM - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ -class Item -{ - /** - * @var string $id - * - * @Type("string") - * @Accessor(getter="getId",setter="setId") - * @SkipWhenEmpty() - */ - private $id; - - /** - * @var string $caption - * - * @Type("string") - * @Accessor(getter="getCaption",setter="setCaption") - * @SkipWhenEmpty() - */ - private $caption; - - /** - * @return string - */ - public function getId() - { - return $this->id; - } - - /** - * @param string $id - */ - public function setId(string $id) - { - $this->id = $id; - } - - /** - * @return string - */ - public function getCaption() - { - return $this->caption; - } - - /** - * @param string $caption - */ - public function setCaption(string $caption) - { - $this->caption = $caption; - } -} diff --git a/src/Bot/Model/Entity/Message/Item.php b/src/Bot/Model/Entity/Message/Item.php new file mode 100644 index 0000000..6dc129b --- /dev/null +++ b/src/Bot/Model/Entity/Message/Item.php @@ -0,0 +1,42 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Message; + +use RetailCrm\Mg\Bot\Model\Entity\CommonFields; + +/** + * PHP version 7.0 + * + * Item class + * + * @package RetailCrm\Mg\Bot\Model\Entity\Message + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + * @method int getId() + * @method $this setId(int $value) + * @method int getSize() + * @method $this setSize(int $value) + * @method string getCaption() + * @method $this setCaption(string $value) + */ +class Item extends CommonFields +{ + const JSON_PROPERTY_MAP = [ + 'id' => 'int', + 'size' => 'int', + 'caption' => 'string' + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Message/Message.php b/src/Bot/Model/Entity/Message/Message.php new file mode 100644 index 0000000..6de19d9 --- /dev/null +++ b/src/Bot/Model/Entity/Message/Message.php @@ -0,0 +1,76 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Message; + +use RetailCrm\Mg\Bot\Model\Entity\CommonFields; + +/** + * PHP version 7.0 + * + * Message class + * + * @package RetailCrm\Mg\Bot\Model\Entity\Message + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + * @method string getTime() + * @method $this setTime(string $value) + * @method string getType() + * @method $this setType(string $value) + * @method string getScope() + * @method $this setScope(string $value) + * @method int getChatId() + * @method $this setChatId(int $value) + * @method string getContent() + * @method $this setContent(string $value) + * @method bool getIsRead() + * @method $this setIsRead(bool $value) + * @method bool getIsEdit() + * @method $this setIsEdit(bool $value) + * @method string getStatus() + * @method $this setStatus(string $value) + * @method string getAction() + * @method $this setAction(string $value) + * @method int getChannelId() + * @method $this setChannelId(int $value) + * @method string getChannelSentAt() + * @method $this setChannelSentAt(string $value) + * @method MessageOrder getOrder() + * @method $this setOrder(MessageOrder $value) + * @method MessageProduct getProduct() + * @method $this setProduct(MessageProduct $value) + */ +class Message extends CommonFields +{ + const JSON_PROPERTY_MAP = [ + 'actions' => '[]', + 'items' => 'Item[]', + 'from' => '\RetailCrm\Mg\Bot\Model\Entity\User', + 'time' => 'string', + 'type' => 'string', + 'scope' => 'string', + 'chat_id' => 'int', + 'content' => 'string', + 'is_read' => 'bool', + 'is_edit' => 'bool', + 'status' => 'string', + 'action' => 'string', + 'dialog' => '\RetailCrm\Mg\Bot\Model\Entity\Dialog', + 'channel_id' => 'int', + 'channel_sent_at' => 'string', + 'order' => 'MessageOrder', + 'product' => 'MessageProduct', + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Message/MessageCost.php b/src/Bot/Model/Entity/Message/MessageCost.php new file mode 100644 index 0000000..1e35d09 --- /dev/null +++ b/src/Bot/Model/Entity/Message/MessageCost.php @@ -0,0 +1,39 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Message; + +use LazyJsonMapper\LazyJsonMapper; + +/** + * PHP version 7.0 + * + * MessageCost class + * + * @package RetailCrm\Mg\Bot\Model\Entity\Message + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + * @method string getCurrency() + * @method $this setCurrency(string $value) + * @method float getValue() + * @method $this setValue(float $value) + */ +class MessageCost extends LazyJsonMapper +{ + const JSON_PROPERTY_MAP = [ + 'currency' => 'string', + 'value' => 'float' + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Message/MessageDelivery.php b/src/Bot/Model/Entity/Message/MessageDelivery.php new file mode 100644 index 0000000..6c00993 --- /dev/null +++ b/src/Bot/Model/Entity/Message/MessageDelivery.php @@ -0,0 +1,45 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Message; + +use LazyJsonMapper\LazyJsonMapper; + +/** + * PHP version 7.0 + * + * MessageDelivery class + * + * @package RetailCrm\Mg\Bot\Model\Entity\Message + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + * @method string getAddress() + * @method $this setAddress(string $value) + * @method string getComment() + * @method $this setComment(string $value) + * @method string getName() + * @method $this setName(string $value) + * @method MessageCost getPrice() + * @method $this setPrice(MessageCost $value) + */ +class MessageDelivery extends LazyJsonMapper +{ + const JSON_PROPERTY_MAP = [ + 'address' => 'string', + 'comment' => 'string', + 'name' => 'string', + 'price' => 'MessageCost' + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Message/MessageOrder.php b/src/Bot/Model/Entity/Message/MessageOrder.php new file mode 100644 index 0000000..cd05092 --- /dev/null +++ b/src/Bot/Model/Entity/Message/MessageOrder.php @@ -0,0 +1,50 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Message; + +use LazyJsonMapper\LazyJsonMapper; + +/** + * PHP version 7.0 + * + * MessageOrder class + * + * @package RetailCrm\Mg\Bot\Model\Entity\Message + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + * @method MessageCost getCost() + * @method $this setCost(MessageCost $value) + * @method string getDate() + * @method $this setDate(string $value) + * @method MessageDelivery getDelivery() + * @method $this setDelivery(MessageDelivery $value) + * @method string getNumber() + * @method $this setNumber(string $value) + * @method MessageStatus getStatus() + * @method $this setStatus(MessageStatus $value) + */ +class MessageOrder extends LazyJsonMapper +{ + const JSON_PROPERTY_MAP = [ + 'cost' => 'MessageCost', + 'date' => 'string', + 'delivery' => 'MessageDelivery', + 'items' => 'MessageOrderItem[]', + 'number' => 'string', + 'payments' => 'MessagePayment[]', + 'status' => 'MessageStatus' + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Message/MessageOrderItem.php b/src/Bot/Model/Entity/Message/MessageOrderItem.php new file mode 100644 index 0000000..fcc3bed --- /dev/null +++ b/src/Bot/Model/Entity/Message/MessageOrderItem.php @@ -0,0 +1,48 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Message; + +use LazyJsonMapper\LazyJsonMapper; + +/** + * PHP version 7.0 + * + * MessageOrderItem class + * + * @package RetailCrm\Mg\Bot\Model\Entity\Message + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + * @method string getImg() + * @method $this setImg(string $value) + * @method string getName() + * @method $this setName(string $value) + * @method MessageCost getPrice() + * @method $this setPrice(MessageCost $value) + * @method MessageQuantity getQuantity() + * @method $this setQuantity(MessageQuantity $value) + * @method string getUrl() + * @method $this setUrl(string $value) + */ +class MessageOrderItem extends LazyJsonMapper +{ + const JSON_PROPERTY_MAP = [ + 'img' => 'string', + 'name' => 'string', + 'price' => 'MessageCost', + 'quantity' => 'MessageQuantity', + 'url' => 'string' + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Message/MessageOrderPaymentStatus.php b/src/Bot/Model/Entity/Message/MessageOrderPaymentStatus.php new file mode 100644 index 0000000..1f0e48b --- /dev/null +++ b/src/Bot/Model/Entity/Message/MessageOrderPaymentStatus.php @@ -0,0 +1,39 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Message; + +use RetailCrm\Mg\Bot\Model\Entity\CommonFields; + +/** + * PHP version 7.0 + * + * MessageOrderPaymentStatus class + * + * @package RetailCrm\Mg\Bot\Model\Entity\Message + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + * @method string getName() + * @method $this setName(string $value) + * @method bool getPayed() + * @method $this setPayed(bool $value) + */ +class MessageOrderPaymentStatus extends CommonFields +{ + const JSON_PROPERTY_MAP = [ + 'name' => 'string', + 'payed' => 'bool' + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Message/MessagePayment.php b/src/Bot/Model/Entity/Message/MessagePayment.php new file mode 100644 index 0000000..9c22702 --- /dev/null +++ b/src/Bot/Model/Entity/Message/MessagePayment.php @@ -0,0 +1,42 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Message; + +use RetailCrm\Mg\Bot\Model\Entity\CommonFields; + +/** + * PHP version 7.0 + * + * MessagePayment class + * + * @package RetailCrm\Mg\Bot\Model\Entity\Message + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + * @method MessageCost getAmount() + * @method $this setAmount(MessageCost $value) + * @method string getName() + * @method $this setName(string $value) + * @method MessageOrderPaymentStatus getStatus() + * @method $this setStatus(MessageOrderPaymentStatus $value) + */ +class MessagePayment extends CommonFields +{ + const JSON_PROPERTY_MAP = [ + 'amount' => 'MessageCost', + 'name' => 'string', + 'status' => 'MessageOrderPaymentStatus' + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Message/MessageProduct.php b/src/Bot/Model/Entity/Message/MessageProduct.php new file mode 100644 index 0000000..0f1d651 --- /dev/null +++ b/src/Bot/Model/Entity/Message/MessageProduct.php @@ -0,0 +1,54 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Message; + +use LazyJsonMapper\LazyJsonMapper; + +/** + * PHP version 7.0 + * + * MessageProduct class + * + * @package RetailCrm\Mg\Bot\Model\Entity\Message + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + * @method string getArticle() + * @method $this setArticle(string $value) + * @method MessageCost getCost() + * @method $this setCost(MessageCost $value) + * @method int getId() + * @method $this setId(int $value) + * @method string getImg() + * @method $this setImg(string $value) + * @method string getName() + * @method $this setName(string $value) + * @method MessageQuantity getQuantity() + * @method $this setQuantity(MessageQuantity $value) + * @method string getUrl() + * @method $this setUrl(string $value) + */ +class MessageProduct extends LazyJsonMapper +{ + const JSON_PROPERTY_MAP = [ + 'article' => 'string', + 'cost' => 'MessageCost', + 'id' => 'int', + 'img' => 'string', + 'name' => 'string', + 'quantity' => 'MessageQuantity', + 'url' => 'string' + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Message/MessageQuantity.php b/src/Bot/Model/Entity/Message/MessageQuantity.php new file mode 100644 index 0000000..0e1fe0b --- /dev/null +++ b/src/Bot/Model/Entity/Message/MessageQuantity.php @@ -0,0 +1,39 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Message; + +use RetailCrm\Mg\Bot\Model\Entity\CommonFields; + +/** + * PHP version 7.0 + * + * MessageQuantity class + * + * @package RetailCrm\Mg\Bot\Model\Entity\Message + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + * @method string getUnit() + * @method $this setUnit(string $value) + * @method float getValue() + * @method $this setValue(float $value) + */ +class MessageQuantity extends CommonFields +{ + const JSON_PROPERTY_MAP = [ + 'unit' => 'string', + 'value' => 'float' + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Message/MessageStatus.php b/src/Bot/Model/Entity/Message/MessageStatus.php new file mode 100644 index 0000000..3d94de2 --- /dev/null +++ b/src/Bot/Model/Entity/Message/MessageStatus.php @@ -0,0 +1,39 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity\Message; + +use LazyJsonMapper\LazyJsonMapper; + +/** + * PHP version 7.0 + * + * MessageStatus class + * + * @package RetailCrm\Mg\Bot\Model\Entity\Message + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + * @method string getCode() + * @method $this setCode(string $value) + * @method float getName() + * @method $this setName(float $value) + */ +class MessageStatus extends LazyJsonMapper +{ + const JSON_PROPERTY_MAP = [ + 'code' => 'string', + 'name' => 'string' + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Entity/Order.php b/src/Bot/Model/Entity/Order.php deleted file mode 100644 index ffa27de..0000000 --- a/src/Bot/Model/Entity/Order.php +++ /dev/null @@ -1,231 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ - -namespace RetailCrm\Mg\Bot\Model\Entity; - -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\SkipWhenEmpty; -use JMS\Serializer\Annotation\Type; - -/** - * PHP version 7.0 - * - * Order class - * - * @package RetailCrm\Mg\Bot\Model\Entity - * @author retailCRM - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ -class Order -{ - /** - * @var string $number - * - * @Type("string") - * @Accessor(getter="getNumber",setter="setNumber") - * @SkipWhenEmpty() - */ - private $number; - - /** - * @var string $url - * - * @Type("string") - * @Accessor(getter="getUrl",setter="setUrl") - * @SkipWhenEmpty() - */ - private $url; - - /** - * @var string $date - * - * @Type("string") - * @Accessor(getter="getDate",setter="setDate") - * @SkipWhenEmpty() - */ - private $date; - - /** - * @var Cost $cost - * - * @Type("Cost") - * @Accessor(getter="getCost",setter="setCost") - * @SkipWhenEmpty() - */ - private $cost; - - /** - * @var Status $status - * - * @Type("Status") - * @Accessor(getter="getStatus",setter="setStatus") - * @SkipWhenEmpty() - */ - private $status; - - /** - * @var Delivery $delivery - * - * @Type("Delivery") - * @Accessor(getter="getDelivery",setter="setDelivery") - * @SkipWhenEmpty() - */ - private $delivery; - - /** - * @var array $items - * - * @Type("array") - * @Accessor(getter="getItems",setter="setItems") - * @SkipWhenEmpty() - */ - private $items; - - /** - * @var array $payments - * - * @Type("array") - * @Accessor(getter="getPayments",setter="setPayments") - * @SkipWhenEmpty() - */ - private $payments; - - /** - * @return string - */ - public function getNumber() - { - return $this->number; - } - - /** - * @param string $number - */ - public function setNumber(string $number) - { - $this->number = $number; - } - - /** - * @return string - */ - public function getUrl() - { - return $this->url; - } - - /** - * @param string $url - */ - public function setUrl(string $url) - { - $this->url = $url; - } - - /** - * @return string - */ - public function getDate() - { - return $this->date; - } - - /** - * @param string $date - */ - public function setDate(string $date) - { - $this->date = $date; - } - - /** - * @return Cost - */ - public function getCost() - { - return $this->cost; - } - - /** - * @param Cost $cost - */ - public function setCost(Cost $cost) - { - $this->cost = $cost; - } - - /** - * @return Status - */ - public function getStatus() - { - return $this->status; - } - - /** - * @param Status $status - */ - public function setStatus(Status $status) - { - $this->status = $status; - } - - /** - * @return Delivery - */ - public function getDelivery() - { - return $this->delivery; - } - - /** - * @param Delivery $delivery - */ - public function setDelivery(Delivery $delivery) - { - $this->delivery = $delivery; - } - - /** - * @return array - */ - public function getItems() - { - return $this->items; - } - - /** - * @param array $items - */ - public function setItems(array $items) - { - $this->items = $items; - } - - /** - * @return array - */ - public function getPayments() - { - return $this->payments; - } - - /** - * @param array $payments - */ - public function setPayments(array $payments) - { - $this->payments = $payments; - } -} diff --git a/src/Bot/Model/Entity/OrderItem.php b/src/Bot/Model/Entity/OrderItem.php deleted file mode 100644 index dba54ce..0000000 --- a/src/Bot/Model/Entity/OrderItem.php +++ /dev/null @@ -1,156 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ - -namespace RetailCrm\Mg\Bot\Model\Entity; - -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\SkipWhenEmpty; -use JMS\Serializer\Annotation\Type; - -/** - * PHP version 7.0 - * - * OrderItem class - * - * @package RetailCrm\Mg\Bot\Model\Entity - * @author retailCRM - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ -class OrderItem -{ - /** - * @var string $name - * - * @Type("string") - * @Accessor(getter="getName",setter="setName") - * @SkipWhenEmpty() - */ - private $name; - - /** - * @var string $url - * - * @Type("string") - * @Accessor(getter="getUrl",setter="setUrl") - * @SkipWhenEmpty() - */ - private $url; - - /** - * @var string $img - * - * @Type("string") - * @Accessor(getter="getImg",setter="setImg") - * @SkipWhenEmpty() - */ - private $img; - - /** - * @var Cost $price - * - * @Type("Cost") - * @Accessor(getter="getPrice",setter="setPrice") - * @SkipWhenEmpty() - */ - private $price; - - /** - * @var Quantity $quantity - * - * @Type("Quantity") - * @Accessor(getter="getQuantity",setter="setQuantity) - * @SkipWhenEmpty() - */ - private $quantity; - - /** - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * @param string $name - */ - public function setName(string $name) - { - $this->name = $name; - } - - /** - * @return string - */ - public function getUrl() - { - return $this->url; - } - - /** - * @param string $url - */ - public function setUrl(string $url) - { - $this->url = $url; - } - - /** - * @return string - */ - public function getImg() - { - return $this->img; - } - - /** - * @param string $img - */ - public function setImg(string $img) - { - $this->img = $img; - } - - /** - * @return Cost - */ - public function getPrice() - { - return $this->price; - } - - /** - * @param Cost $price - */ - public function setPrice(Cost $price) - { - $this->price = $price; - } - - /** - * @return Quantity - */ - public function getQuantity() - { - return $this->quantity; - } - - /** - * @param Quantity $quantity - */ - public function setQuantity(Quantity $quantity) - { - $this->quantity = $quantity; - } -} diff --git a/src/Bot/Model/Entity/Payment.php b/src/Bot/Model/Entity/Payment.php deleted file mode 100644 index b5709c9..0000000 --- a/src/Bot/Model/Entity/Payment.php +++ /dev/null @@ -1,106 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ - -namespace RetailCrm\Mg\Bot\Model\Entity; - -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\SkipWhenEmpty; -use JMS\Serializer\Annotation\Type; - -/** - * PHP version 7.0 - * - * Payment class - * - * @package RetailCrm\Mg\Bot\Model\Entity - * @author retailCRM - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ -class Payment -{ - /** - * @var string $name - * - * @Type("string") - * @Accessor(getter="getName",setter="setName") - * @SkipWhenEmpty() - */ - private $name; - - /** - * @var PaymentStatus $status - * - * @Type("PaymentStatus") - * @Accessor(getter="getStatus",setter="setStatus") - * @SkipWhenEmpty() - */ - private $status; - - /** - * @var Cost $amount - * - * @Type("Cost") - * @Accessor(getter="getAmount",setter="setAmount") - * @SkipWhenEmpty() - */ - private $amount; - - /** - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * @param string $name - */ - public function setName(string $name) - { - $this->name = $name; - } - - /** - * @return PaymentStatus - */ - public function getStatus() - { - return $this->status; - } - - /** - * @param PaymentStatus $status - */ - public function setStatus(PaymentStatus $status) - { - $this->status = $status; - } - - /** - * @return Cost - */ - public function getAmount() - { - return $this->amount; - } - - /** - * @param Cost $amount - */ - public function setAmount(Cost $amount) - { - $this->amount = $amount; - } -} diff --git a/src/Bot/Model/Entity/PaymentStatus.php b/src/Bot/Model/Entity/PaymentStatus.php deleted file mode 100644 index 7a20f46..0000000 --- a/src/Bot/Model/Entity/PaymentStatus.php +++ /dev/null @@ -1,81 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ - -namespace RetailCrm\Mg\Bot\Model\Entity; - -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\SkipWhenEmpty; -use JMS\Serializer\Annotation\Type; - -/** - * PHP version 7.0 - * - * PaymentStatus class - * - * @package RetailCrm\Mg\Bot\Model\Entity - * @author retailCRM - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ -class PaymentStatus -{ - /** - * @var string $name - * - * @Type("string") - * @Accessor(getter="getName",setter="setName") - * @SkipWhenEmpty() - */ - private $name; - - /** - * @var bool $payed - * - * @Type("bool") - * @Accessor(getter="getPayed",setter="setPayed") - * @SkipWhenEmpty() - */ - private $payed; - - /** - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * @param string $name - */ - public function setName(string $name) - { - $this->name = $name; - } - - /** - * @return bool - */ - public function isPayed() - { - return $this->payed; - } - - /** - * @param bool $payed - */ - public function setPayed(bool $payed) - { - $this->payed = $payed; - } -} diff --git a/src/Bot/Model/Entity/Product.php b/src/Bot/Model/Entity/Product.php deleted file mode 100644 index 5c9c9f4..0000000 --- a/src/Bot/Model/Entity/Product.php +++ /dev/null @@ -1,206 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ - -namespace RetailCrm\Mg\Bot\Model\Entity; - -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\SkipWhenEmpty; -use JMS\Serializer\Annotation\Type; - -/** - * PHP version 7.0 - * - * Product class - * - * @package RetailCrm\Mg\Bot\Model\Entity - * @author retailCRM - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ -class Product -{ - /** - * @var int $id - * - * @Type("int") - * @Accessor(getter="getId",setter="setId") - * @SkipWhenEmpty() - */ - private $id; - - /** - * @var string $name - * - * @Type("string") - * @Accessor(getter="getName",setter="setName") - * @SkipWhenEmpty() - */ - private $name; - - /** - * @var string $article - * - * @Type("string") - * @Accessor(getter="getArticle",setter="setArticle") - * @SkipWhenEmpty() - */ - private $article; - - /** - * @var string $url - * - * @Type("string") - * @Accessor(getter="getUrl",setter="setUrl") - * @SkipWhenEmpty() - */ - private $url; - - /** - * @var string $img - * - * @Type("string") - * @Accessor(getter="getImg",setter="setImg") - * @SkipWhenEmpty() - */ - private $img; - - /** - * @var Cost $cost - * - * @Type("Cost") - * @Accessor(getter="getCost",setter="setCost") - * @SkipWhenEmpty() - */ - private $cost; - - /** - * @var Quantity $quantity - * - * @Type("Quantity") - * @Accessor(getter="getQuantity",setter="setQuantity) - * @SkipWhenEmpty() - */ - private $quantity; - - /** - * @return int - */ - public function getId(): int - { - return $this->id; - } - - /** - * @param int $id - */ - public function setId(int $id) - { - $this->id = $id; - } - - /** - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * @param string $name - */ - public function setName(string $name) - { - $this->name = $name; - } - - /** - * @return string - */ - public function getArticle() - { - return $this->article; - } - - /** - * @param string $article - */ - public function setArticle(string $article) - { - $this->article = $article; - } - - /** - * @return string - */ - public function getUrl() - { - return $this->url; - } - - /** - * @param string $url - */ - public function setUrl(string $url) - { - $this->url = $url; - } - - /** - * @return string - */ - public function getImg() - { - return $this->img; - } - - /** - * @param string $img - */ - public function setImg(string $img) - { - $this->img = $img; - } - - /** - * @return Cost - */ - public function getCost() - { - return $this->cost; - } - - /** - * @param Cost $cost - */ - public function setCost(Cost $cost) - { - $this->cost = $cost; - } - - /** - * @return Quantity - */ - public function getQuantity() - { - return $this->quantity; - } - - /** - * @param Quantity $quantity - */ - public function setQuantity(Quantity $quantity) - { - $this->quantity = $quantity; - } -} diff --git a/src/Bot/Model/Entity/Quantity.php b/src/Bot/Model/Entity/Quantity.php deleted file mode 100644 index d74d4c4..0000000 --- a/src/Bot/Model/Entity/Quantity.php +++ /dev/null @@ -1,82 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ - -namespace RetailCrm\Mg\Bot\Model\Entity; - -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\SkipWhenEmpty; -use JMS\Serializer\Annotation\Type; - -/** - * PHP version 7.0 - * - * Quantity class - * - * @package RetailCrm\Mg\Bot\Model\Entity - * @author retailCRM - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ -class Quantity -{ - /** - * @var float $value - * - * @Type("float") - * @Accessor(getter="getValue",setter="setValue") - * @SkipWhenEmpty() - */ - private $value; - - /** - * @var string $unit - * - * @Type("string") - * @Accessor(getter="getUnit",setter="setUnit") - * - * @Assert\Currency - */ - private $unit; - - /** - * @return float - */ - public function getValue() - { - return $this->value; - } - - /** - * @param float $value - */ - public function setValue(float $value) - { - $this->value = $value; - } - - /** - * @return string - */ - public function getUnit() - { - return $this->unit; - } - - /** - * @param string $unit - */ - public function setUnit(string $unit) - { - $this->unit = $unit; - } -} diff --git a/src/Bot/Model/Entity/Responsible.php b/src/Bot/Model/Entity/Responsible.php index 668fc7a..e2622a6 100644 --- a/src/Bot/Model/Entity/Responsible.php +++ b/src/Bot/Model/Entity/Responsible.php @@ -15,6 +15,7 @@ namespace RetailCrm\Mg\Bot\Model\Entity; use JMS\Serializer\Annotation\Accessor; use JMS\Serializer\Annotation\Type; +use LazyJsonMapper\LazyJsonMapper; /** * PHP version 7.0 @@ -26,77 +27,11 @@ use JMS\Serializer\Annotation\Type; * @license https://opensource.org/licenses/MIT MIT License * @link http://help.retailcrm.pro/docs/Developers */ -class Responsible +class Responsible extends LazyJsonMapper { - /** - * @var string $assignedAt - * - * @Type("string") - * @Accessor(getter="getAssignedAt",setter="setAssignedAt") - */ - private $assignedAt; - - /** - * @var int $id - * - * @Type("int") - * @Accessor(getter="getId",setter="setId") - */ - private $id; - - /** - * @var string $type - * - * @Type("string") - * @Accessor(getter="getType",setter="setType") - */ - private $type; - - /** - * @return string - */ - public function getAssignedAt() - { - return $this->assignedAt; - } - - /** - * @param string $assignedAt - */ - public function setAssignedAt(string $assignedAt) - { - $this->assignedAt = $assignedAt; - } - - /** - * @return int - */ - public function getId(): int - { - return $this->id; - } - - /** - * @param int $id - */ - public function setId(int $id) - { - $this->id = $id; - } - - /** - * @return string - */ - public function getType(): string - { - return $this->type; - } - - /** - * @param string $type - */ - public function setType(string $type) - { - $this->type = $type; - } + const JSON_PROPERTY_MAP = [ + 'assigned_at' => 'string', + 'id' => 'int', + 'type' => 'string' + ]; } diff --git a/src/Bot/Model/Entity/Status.php b/src/Bot/Model/Entity/Status.php deleted file mode 100644 index 4564290..0000000 --- a/src/Bot/Model/Entity/Status.php +++ /dev/null @@ -1,81 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ - -namespace RetailCrm\Mg\Bot\Model\Entity; - -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\SkipWhenEmpty; -use JMS\Serializer\Annotation\Type; - -/** - * PHP version 7.0 - * - * Status class - * - * @package RetailCrm\Mg\Bot\Model\Entity - * @author retailCRM - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ -class Status -{ - /** - * @var string $code - * - * @Type("string") - * @Accessor(getter="getCode",setter="setCode") - * @SkipWhenEmpty() - */ - private $code; - - /** - * @var string $name - * - * @Type("string") - * @Accessor(getter="getName",setter="setName") - * @SkipWhenEmpty() - */ - private $name; - - /** - * @return string - */ - public function getCode() - { - return $this->code; - } - - /** - * @param string $code - */ - public function setCode(string $code) - { - $this->code = $code; - } - - /** - * @return string - */ - public function getName() - { - return $this->name; - } - - /** - * @param string $name - */ - public function setName(string $name) - { - $this->name = $name; - } -} diff --git a/src/Bot/Model/Entity/User.php b/src/Bot/Model/Entity/User.php new file mode 100644 index 0000000..1ab13bd --- /dev/null +++ b/src/Bot/Model/Entity/User.php @@ -0,0 +1,55 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Entity; + +/** + * PHP version 7.0 + * + * User class + * + * @package RetailCrm\Mg\Bot\Model\Entity + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + * + * @method int getId() + * @method $this setId(int $value) + * @method string getType() + * @method $this setType(string $value) + * @method string getAvatar() + * @method $this setAvatar(string $value) + * @method string getName() + * @method $this setName(string $value) + * @method string getUsername() + * @method $this setUsername(string $value) + * @method string getFirstName() + * @method $this setFirstName(string $value) + * @method string getLastName() + * @method $this setLastName(string $value) + */ +class User extends CommonFields +{ + const JSON_PROPERTY_MAP = [ + 'external_id' => 'string', + 'type' => 'string', + 'avatar' => 'string', + 'name' => 'string', + 'username' => 'string', + 'first_name' => 'string', + 'last_name' => 'string', + 'is_active' => 'bool', + 'is_online' => 'bool', + 'revoked_at' => 'string' + ]; +} \ No newline at end of file diff --git a/src/Bot/Model/Response/AssignResponse.php b/src/Bot/Model/Response/AssignResponse.php index ca9251b..41eea26 100644 --- a/src/Bot/Model/Response/AssignResponse.php +++ b/src/Bot/Model/Response/AssignResponse.php @@ -13,11 +13,7 @@ namespace RetailCrm\Mg\Bot\Model\Response; -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\SkipWhenEmpty; -use JMS\Serializer\Annotation\Type; use RetailCrm\Mg\Bot\Model\Entity\Responsible; -use RetailCrm\Mg\Bot\Model\Response\ErrorTrait; /** * PHP version 7.0 @@ -28,104 +24,22 @@ use RetailCrm\Mg\Bot\Model\Response\ErrorTrait; * @author retailCRM * @license https://opensource.org/licenses/MIT MIT License * @link http://help.retailcrm.pro/docs/Developers + * + * @method bool getIsReassign() + * @method $this setIsReassign(bool $value) + * @method int getLeftManagerId() + * @method $this setLeftManagerId(int $value) + * @method Responsible getPreviousResponsible() + * @method $this setPreviousResponsible(Responsible $value) + * @method Responsible getResponsible() + * @method $this setResponsible(Responsible $value) */ -class AssignResponse +class AssignResponse extends CommonFields { - use ErrorTrait; - - /** - * @var bool - * - * @Type("bool") - * @Accessor(setter="setIsReassign", getter="getIsReassign") - */ - private $isReassign; - - /** - * @var int - * - * @Type("int") - * @Accessor(setter="setLeftManagerId", getter="getLeftManagerId") - * @SkipWhenEmpty() - */ - private $leftManagerId; - - /** - * @var Responsible $previousResponsible - * - * @Accessor(setter="setPreviousResponsible", getter="getPreviousResponsible") - * @SkipWhenEmpty() - */ - private $previousResponsible; - - /** - * @var Responsible $responsible - * - * @Accessor(setter="setResponsible", getter="getResponsible") - */ - private $responsible; - - /** - * @return bool - */ - public function getIsReassign() - { - return $this->isReassign; - } - - /** - * @param bool $isReassign - */ - public function setIsReassign(bool $isReassign) - { - $this->isReassign = $isReassign; - } - - /** - * @return int - */ - public function getLeftManagerId(): int - { - return $this->leftManagerId; - } - - /** - * @param int $leftManagerId - */ - public function setLeftManagerId(int $leftManagerId) - { - $this->leftManagerId = $leftManagerId; - } - - /** - * @return Responsible - */ - public function getPreviousResponsible(): Responsible - { - return $this->previousResponsible; - } - - /** - * @param Responsible $previousResponsible - */ - public function setPreviousResponsible(Responsible $previousResponsible) - { - $this->previousResponsible = $previousResponsible; - } - - /** - * @return Responsible - */ - public function getResponsible(): Responsible - { - return $this->responsible; - } - - /** - * @param Responsible $responsible - */ - public function setResponsible(Responsible $responsible) - { - $this->responsible = $responsible; - } + const JSON_PROPERTY_MAP = [ + 'is_reassign' => 'bool', + 'left_manager_id' => 'int', + 'previous_responsible' => 'Responsible', + 'responsible' => 'Responsible' + ]; } \ No newline at end of file diff --git a/src/Bot/Model/Response/ErrorTrait.php b/src/Bot/Model/Response/CommonFields.php similarity index 61% rename from src/Bot/Model/Response/ErrorTrait.php rename to src/Bot/Model/Response/CommonFields.php index 7574c94..8fd9b26 100644 --- a/src/Bot/Model/Response/ErrorTrait.php +++ b/src/Bot/Model/Response/CommonFields.php @@ -16,6 +16,7 @@ namespace RetailCrm\Mg\Bot\Model\Response; use JMS\Serializer\Annotation as Serializer; use JMS\Serializer\Annotation\Accessor; use JMS\Serializer\Annotation\SkipWhenEmpty; +use LazyJsonMapper\LazyJsonMapper; use RetailCrm\Mg\Bot\Model\Entity\Error; /** @@ -27,40 +28,21 @@ use RetailCrm\Mg\Bot\Model\Entity\Error; * @author retailCRM * @license https://opensource.org/licenses/MIT MIT License * @link http://help.retailcrm.pro/docs/Developers + * + * @method array getErrors() + * @method $this setErrors(array $value) */ -trait ErrorTrait +class CommonFields extends LazyJsonMapper { - /** - * @var array $error - * - * @Serializer\Type("array") - * @Accessor(setter="getError", setter="setError") - * @Serializer\SerializedName("errors") - * @SkipWhenEmpty() - */ - private $error; - - /** - * @return array - */ - public function getError() - { - return $this->error; - } - - /** - * @param array $error - */ - public function setError(array $error) - { - $this->error = $error; - } + const JSON_PROPERTY_MAP = [ + 'errors' => 'string[]' + ]; /** * @return bool */ public function isError() { - return !empty($this->error); + return !empty($this->getErrors()); } } \ No newline at end of file diff --git a/src/Bot/Model/Response/ErrorOnlyResponse.php b/src/Bot/Model/Response/ErrorOnlyResponse.php index 6c5bf03..62adb6f 100644 --- a/src/Bot/Model/Response/ErrorOnlyResponse.php +++ b/src/Bot/Model/Response/ErrorOnlyResponse.php @@ -13,8 +13,6 @@ namespace RetailCrm\Mg\Bot\Model\Response; -use RetailCrm\Mg\Bot\Model\Response\ErrorTrait; - /** * PHP version 7.0 * @@ -25,7 +23,4 @@ use RetailCrm\Mg\Bot\Model\Response\ErrorTrait; * @license https://opensource.org/licenses/MIT MIT License * @link http://help.retailcrm.pro/docs/Developers */ -class ErrorOnlyResponse -{ - use ErrorTrait; -} \ No newline at end of file +class ErrorOnlyResponse extends CommonFields {} \ No newline at end of file diff --git a/src/Bot/Model/Response/FullFileResponse.php b/src/Bot/Model/Response/FullFileResponse.php index 072b064..ef141b1 100644 --- a/src/Bot/Model/Response/FullFileResponse.php +++ b/src/Bot/Model/Response/FullFileResponse.php @@ -13,11 +13,6 @@ namespace RetailCrm\Mg\Bot\Model\Response; -use JMS\Serializer\Annotation\SkipWhenEmpty; -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\Type; -use RetailCrm\Mg\Bot\Model\Response\ErrorTrait; - /** * PHP version 7.0 * @@ -27,108 +22,22 @@ use RetailCrm\Mg\Bot\Model\Response\ErrorTrait; * @author retailCRM * @license https://opensource.org/licenses/MIT MIT License * @link http://help.retailcrm.pro/docs/Developers + * + * @method string getId() + * @method $this setId(string $value) + * @method int getSize() + * @method $this setSize(int $value) + * @method string getType() + * @method $this setType(string $value) + * @method string getUrl() + * @method $this setUrl(string $value) */ -class FullFileResponse +class FullFileResponse extends CommonFields { - use ErrorTrait; - - /** - * @var string $id - * - * @Type("string") - * @Accessor(setter="setId", getter="getId") - * @SkipWhenEmpty() - */ - private $id; - - /** - * @var int $size - * - * @Type("int") - * @Accessor(setter="setSize", getter="getSize") - * @SkipWhenEmpty() - */ - private $size; - - /** - * @var string $type - * - * @Type("string") - * @Accessor(setter="setType", getter="getType") - * @SkipWhenEmpty() - */ - private $type; - - /** - * @var string $url - * - * @Type("string") - * @Accessor(setter="setUrl", getter="getUrl") - * @SkipWhenEmpty() - */ - private $url; - - /** - * @return string - */ - public function getId(): string - { - return $this->id; - } - - /** - * @param string $id - */ - public function setId(string $id) - { - $this->id = $id; - } - - /** - * @return int - */ - public function getSize(): int - { - return $this->size; - } - - /** - * @param int $size - */ - public function setSize(int $size) - { - $this->size = $size; - } - - /** - * @return string - */ - public function getType(): string - { - return $this->type; - } - - /** - * @param string $type - */ - public function setType(string $type) - { - $this->type = $type; - } - - /** - * @return string - */ - public function getUrl(): string - { - return $this->url; - } - - /** - * @param string $url - */ - public function setUrl(string $url) - { - $this->url = $url; - } + const JSON_PROPERTY_MAP = [ + 'id' => 'string', + 'size' => 'int', + 'type' => 'string', + 'url' => 'string' + ]; } \ No newline at end of file diff --git a/src/Bot/Model/Response/GenericListResponse.php b/src/Bot/Model/Response/GenericListResponse.php deleted file mode 100644 index 7210e00..0000000 --- a/src/Bot/Model/Response/GenericListResponse.php +++ /dev/null @@ -1,57 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ - -namespace RetailCrm\Mg\Bot\Model\Response; - -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\Type; -use RetailCrm\Mg\Bot\Model\Response\ErrorTrait; - -/** - * PHP version 7.0 - * - * GenericListResponse class - * - * @package RetailCrm\Mg\Bot\Model\Response - * @author retailCRM - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ -class GenericListResponse -{ - use ErrorTrait; - - /** - * @var array $result - * - * @Type("array") - * @Accessor(setter="setResult", getter="getResult") - */ - private $result; - - /** - * @return array - */ - public function getResult() - { - return $this->result; - } - - /** - * @param array $result - */ - public function setResult(array $result) - { - $this->result = $result; - } -} \ No newline at end of file diff --git a/src/Bot/Model/Response/ListResponse.php b/src/Bot/Model/Response/ListResponse.php new file mode 100644 index 0000000..725c6de --- /dev/null +++ b/src/Bot/Model/Response/ListResponse.php @@ -0,0 +1,135 @@ + + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ + +namespace RetailCrm\Mg\Bot\Model\Response; + +/** + * PHP version 7.0 + * + * ListResponse class + * + * @package RetailCrm\Mg\Bot\Model\Response + * @author retailCRM + * @license https://opensource.org/licenses/MIT MIT License + * @link http://help.retailcrm.pro/docs/Developers + */ +class ListResponse implements \Iterator { + /** + * @var array + */ + private $items = []; + + /** + * @var array + */ + private $errors = []; + + /** + * @var int + */ + private $position = 0; + + /** + * ListResponse constructor. + * + * @param $responseType + * @param $data + */ + public function __construct($responseType, $data) + { + if (isset($data['errors'])) { + $this->errors = $data['errors']; + } else { + foreach($data as $item) { + $this->items[] = new $responseType($item); + } + } + } + + /** + * @return bool + */ + public function isSuccessful() + { + return empty($this->errors); + } + + /** + * @return array + */ + public function getErrors() + { + return $this->errors; + } + + /** + * @param $name + * + * @return mixed + */ + public function get($name) + { + return $this->items[$name]; + } + + /** + * @param $name + * + * @return mixed + */ + public function __get($name) + { + return $this->items[$name]; + } + + /** + * Implements rewind() for Iterable + */ + public function rewind() { + $this->position = 0; + } + + /** + * Implements current() for Iterable + * + * @return mixed + */ + public function current() { + return $this->items[$this->position]; + } + + /** + * Implements key() for Iterable + * + * @return int|mixed + */ + public function key() { + return $this->position; + } + + /** + * Implements next() for Iterable + */ + public function next() { + ++$this->position; + } + + /** + * Implements valid() for Iterable + * + * @return bool + */ + public function valid() { + return isset($this->items[$this->position]); + } +} \ No newline at end of file diff --git a/src/Bot/Model/Response/MessageSendResponse.php b/src/Bot/Model/Response/MessageSendResponse.php index 353c8e6..3625df4 100644 --- a/src/Bot/Model/Response/MessageSendResponse.php +++ b/src/Bot/Model/Response/MessageSendResponse.php @@ -13,12 +13,6 @@ namespace RetailCrm\Mg\Bot\Model\Response; -use JMS\Serializer\Annotation as Serializer; -use JMS\Serializer\Annotation\SkipWhenEmpty; -use JMS\Serializer\Annotation\Accessor; -use JMS\Serializer\Annotation\Type; -use RetailCrm\Mg\Bot\Model\Response\ErrorTrait; - /** * PHP version 7.0 * @@ -28,56 +22,16 @@ use RetailCrm\Mg\Bot\Model\Response\ErrorTrait; * @author retailCRM * @license https://opensource.org/licenses/MIT MIT License * @link http://help.retailcrm.pro/docs/Developers + * + * @method int getMessageId() + * @method $this setMessageId(int $value) + * @method string getTime() + * @method $this setTime(string $value) */ -class MessageSendResponse +class MessageSendResponse extends CommonFields { - /** - * @var int $messageId - * - * @Type("int") - * @Accessor(setter="setMessageId", getter="getMessageId") - * @SkipWhenEmpty() - */ - private $messageId; - - /** - * @var string $time - * - * @Type("string") - * @Accessor(setter="setTime", getter="getTime") - * @SkipWhenEmpty() - */ - private $time; - - /** - * @return int - */ - public function getMessageId(): int - { - return $this->messageId; - } - - /** - * @param int $messageId - */ - public function setMessageId(int $messageId) - { - $this->messageId = $messageId; - } - - /** - * @return string - */ - public function getTime(): string - { - return $this->time; - } - - /** - * @param string $time - */ - public function setTime(string $time) - { - $this->time = $time; - } + const JSON_PROPERTY_MAP = [ + 'message_id' => 'int', + 'time' => 'string' + ]; } \ No newline at end of file diff --git a/src/Bot/Model/Response/UploadFileResponse.php b/src/Bot/Model/Response/UploadFileResponse.php index 0d9ceef..7759d9f 100644 --- a/src/Bot/Model/Response/UploadFileResponse.php +++ b/src/Bot/Model/Response/UploadFileResponse.php @@ -15,7 +15,7 @@ namespace RetailCrm\Mg\Bot\Model\Response; use JMS\Serializer\Annotation\Accessor; use JMS\Serializer\Annotation\Type; -use RetailCrm\Mg\Bot\Model\Response\ErrorTrait; +use RetailCrm\Mg\Bot\Model\Response\CommonFields; use RetailCrm\Mg\Bot\Model\Entity\FileMeta; /** @@ -27,199 +27,34 @@ use RetailCrm\Mg\Bot\Model\Entity\FileMeta; * @author retailCRM * @license https://opensource.org/licenses/MIT MIT License * @link http://help.retailcrm.pro/docs/Developers + * + * @method string getCreatedAt() + * @method $this setCreatedAt(string $value) + * @method string getHash() + * @method $this setHash(string $value) + * @method string getId() + * @method $this setId(string $value) + * @method FileMeta getMeta() + * @method $this setMeta(FileMeta $value) + * @method string getMimeType() + * @method $this setMimeType(string $value) + * @method int getSize() + * @method $this setSize(int $value) + * @method string getSourceUrl() + * @method $this setSourceUrl(string $value) + * @method string getType() + * @method $this setType(string $value) */ -class UploadFileResponse +class UploadFileResponse extends CommonFields { - use ErrorTrait; - - /** - * @var string $createdAt - * - * @Type("string") - * @Accessor(setter="setCreatedAt", getter="getCreatedAt") - */ - private $createdAt; - - /** - * @var string $hash - * - * @Type("string") - * @Accessor(setter="setHash", getter="getHash") - */ - private $hash; - - /** - * @var string $id - * - * @Type("string") - * @Accessor(setter="setId", getter="getId") - */ - private $id; - - /** - * @var FileMeta - * - * @Accessor(setter="setMeta", getter="getMeta") - */ - private $meta; - - /** - * @var string $mimeType - * - * @Type("string") - * @Accessor(setter="setMimeType", getter="getMimeType") - */ - private $mimeType; - - /** - * @var int $size - * - * @Type("string") - * @Accessor(setter="setSize", getter="getSize") - */ - private $size; - - /** - * @var string $sourceUrl - * - * @Type("string") - * @Accessor(setter="setSourceUrl", getter="getSourceUrl") - */ - private $sourceUrl; - - /** - * @var string $type - * - * @Type("string") - * @Accessor(setter="setType", getter="getType") - */ - private $type; - - /** - * @return string - */ - public function getCreatedAt(): string - { - return $this->createdAt; - } - - /** - * @param string $createdAt - */ - public function setCreatedAt(string $createdAt) - { - $this->createdAt = $createdAt; - } - - /** - * @return string - */ - public function getHash(): string - { - return $this->hash; - } - - /** - * @param string $hash - */ - public function setHash(string $hash) - { - $this->hash = $hash; - } - - /** - * @return string - */ - public function getId(): string - { - return $this->id; - } - - /** - * @param string $id - */ - public function setId(string $id) - { - $this->id = $id; - } - - /** - * @return FileMeta - */ - public function getMeta(): FileMeta - { - return $this->meta; - } - - /** - * @param FileMeta $meta - */ - public function setMeta(FileMeta $meta) - { - $this->meta = $meta; - } - - /** - * @return string - */ - public function getMimeType(): string - { - return $this->mimeType; - } - - /** - * @param string $mimeType - */ - public function setMimeType(string $mimeType) - { - $this->mimeType = $mimeType; - } - - /** - * @return int - */ - public function getSize(): int - { - return $this->size; - } - - /** - * @param int $size - */ - public function setSize(int $size) - { - $this->size = $size; - } - - /** - * @return string - */ - public function getSourceUrl(): string - { - return $this->sourceUrl; - } - - /** - * @param string $sourceUrl - */ - public function setSourceUrl(string $sourceUrl) - { - $this->sourceUrl = $sourceUrl; - } - - /** - * @return string - */ - public function getType(): string - { - return $this->type; - } - - /** - * @param string $type - */ - public function setType(string $type) - { - $this->type = $type; - } + const JSON_PROPERTY_MAP = [ + 'created_at' => 'string', + 'hash' => 'string', + 'id' => 'string', + 'meta' => 'FileMeta', + 'mime_type' => 'string', + 'size' => 'int', + 'source_url' => 'string', + 'type' => 'string' + ]; } \ No newline at end of file diff --git a/src/Deserializer.php b/src/Deserializer.php deleted file mode 100644 index a0feced..0000000 --- a/src/Deserializer.php +++ /dev/null @@ -1,59 +0,0 @@ - - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ - -namespace RetailCrm\Common; - -use JMS\Serializer\SerializerBuilder; - -/** - * PHP version 7.0 - * - * Deserializer class - * - * @package RetailCrm\Common - * @author retailCRM - * @license https://opensource.org/licenses/MIT MIT License - * @link http://help.retailcrm.pro/docs/Developers - */ -class Deserializer -{ - const DS_JSON = "json"; - const DS_XML = "xml"; - const DS_ARRAY = "array"; - - /** - * Serialize given object to JSON or Array - * - * @param array|string $data - * @param string $deserialize - * - * @return object - */ - public static function deserialize($data, $type, $deserialize = self::S_JSON) - { - $deserialized = null; - $serializer = SerializerBuilder::create()->build(); - - switch ($deserialize) { - case self::DS_ARRAY: - $deserialized = $serializer->fromArray($data, $type); - break; - case self::DS_JSON: - case self::DS_XML: - $deserialized = $serializer->deserialize($data, $type, $deserialize); - break; - } - - return $deserialized; - } -} diff --git a/tests/Bot/Tests/ClientListTest.php b/tests/Bot/Tests/ClientListTest.php index 89f037a..9518b32 100644 --- a/tests/Bot/Tests/ClientListTest.php +++ b/tests/Bot/Tests/ClientListTest.php @@ -14,6 +14,7 @@ namespace RetailCrm\Mg\Bot\Tests; use RetailCrm\Mg\Bot\Model\Constants; +use RetailCrm\Mg\Bot\Model\Entity\Dialog; use RetailCrm\Mg\Bot\Model\Request; use RetailCrm\Mg\Bot\Model\Response; use RetailCrm\Mg\Bot\Test\TestCase; @@ -44,9 +45,8 @@ class ClientListTest extends TestCase $request->setTypes([Constants::CHANNEL_TYPE_FACEBOOK, Constants::CHANNEL_TYPE_INSTAGRAM]); $response = $client->channels($request); - var_dump($response[0]); - //self::assertTrue($response->isSuccessful() == true); + print_r($response->get(0)); } /** @@ -62,7 +62,7 @@ class ClientListTest extends TestCase $response = $client->chats($request); - self::assertTrue($response->isSuccessful() == true); + print_r($response); } /** @@ -77,7 +77,7 @@ class ClientListTest extends TestCase $response = $client->members($request); - self::assertTrue($response->isSuccessful() == true); + print_r($response); } /** @@ -94,7 +94,7 @@ class ClientListTest extends TestCase $response = $client->messages($request); - self::assertTrue($response->isSuccessful() == true); + print_r($response); } /** @@ -109,7 +109,7 @@ class ClientListTest extends TestCase $response = $client->commands($request); - self::assertTrue($response->isSuccessful() == true); + print_r($response); } /** @@ -126,7 +126,7 @@ class ClientListTest extends TestCase $data = $client->bots($request); - self::assertTrue($data instanceof \RetailCrm\Mg\Bot\Model\Response\GenericListResponse); + print_r($data); } /** @@ -143,7 +143,7 @@ class ClientListTest extends TestCase $response = $client->users($request); - self::assertTrue($response->isSuccessful() == true); + print_r($response); } /** @@ -159,8 +159,6 @@ class ClientListTest extends TestCase $request->setAssign(1); $response = $client->dialogs($request); - - self::assertTrue($response->isSuccessful() == true); } /** @@ -175,6 +173,6 @@ class ClientListTest extends TestCase $response = $client->customers($request); - self::assertTrue($response->isSuccessful() == true); + print_r($response); } } From 4f76afe9c97eadbcd3c08790f504352d663c76f1 Mon Sep 17 00:00:00 2001 From: Pavel Date: Mon, 17 Jun 2019 12:43:54 +0300 Subject: [PATCH 03/37] Docs generation --- .gitignore | 6 + Makefile | 9 + apigen.neon | 32 -- composer.json | 5 +- composer.lock | 440 ++++-------------- phpdoc.dist.xml | 20 + src/Bot/Client.php | 92 ++-- src/Bot/HttpClient.php | 40 +- src/Bot/Model/Entity/Bot.php | 84 ++++ src/Bot/Model/Entity/Bot/Bot.php | 60 --- src/Bot/Model/Entity/Channel/Channel.php | 49 +- .../Model/Entity/Channel/ChannelSettings.php | 49 +- .../Entity/Channel/ChannelSettingsItem.php | 53 ++- src/Bot/Model/Entity/Chat/Chat.php | 43 +- src/Bot/Model/Entity/Chat/ChatLastMessage.php | 34 +- src/Bot/Model/Entity/Chat/ChatMember.php | 39 +- src/Bot/Model/Entity/Command.php | 29 +- src/Bot/Model/Entity/CommonFields.php | 32 +- src/Bot/Model/Entity/Customer.php | 79 +++- src/Bot/Model/Entity/Dialog.php | 59 ++- src/Bot/Model/Entity/FileMeta.php | 26 +- src/Bot/Model/Entity/Message/Item.php | 34 +- src/Bot/Model/Entity/Message/Message.php | 96 ++-- src/Bot/Model/Entity/Message/MessageCost.php | 29 +- .../Model/Entity/Message/MessageDelivery.php | 39 +- src/Bot/Model/Entity/Message/MessageOrder.php | 50 +- .../Model/Entity/Message/MessageOrderItem.php | 44 +- .../Message/MessageOrderPaymentStatus.php | 29 +- .../Model/Entity/Message/MessagePayment.php | 34 +- .../Model/Entity/Message/MessageProduct.php | 54 ++- .../Model/Entity/Message/MessageQuantity.php | 29 +- .../Model/Entity/Message/MessageStatus.php | 29 +- src/Bot/Model/Entity/Responsible.php | 31 +- src/Bot/Model/Entity/User.php | 63 ++- src/Bot/Model/Request/BotsRequest.php | 106 ++--- src/Bot/Model/Request/ChannelsRequest.php | 79 ++-- src/Bot/Model/Request/ChatsRequest.php | 79 ++-- src/Bot/Model/Request/CommandEditRequest.php | 113 ++--- src/Bot/Model/Request/CommandsRequest.php | 52 +-- src/Bot/Model/Request/CommonFields.php | 104 ++--- src/Bot/Model/Request/CustomersRequest.php | 52 +-- src/Bot/Model/Request/DialogAssignRequest.php | 110 ++--- src/Bot/Model/Request/DialogsRequest.php | 170 ++----- src/Bot/Model/Request/InfoRequest.php | 110 ++--- src/Bot/Model/Request/MembersRequest.php | 168 ++----- src/Bot/Model/Request/MessageEditRequest.php | 81 ++-- src/Bot/Model/Request/MessageSendRequest.php | 261 +++-------- src/Bot/Model/Request/MessagesRequest.php | 286 +++--------- src/Bot/Model/Request/UsersRequest.php | 106 ++--- src/Bot/Model/Response/AssignResponse.php | 39 +- src/Bot/Model/Response/CommonFields.php | 27 +- src/Bot/Model/Response/FullFileResponse.php | 39 +- src/Bot/Model/Response/ListResponse.php | 87 +++- .../Model/Response/MessageSendResponse.php | 29 +- src/Bot/Model/Response/UploadFileResponse.php | 62 ++- src/Exception/CurlException.php | 30 -- src/Exception/LimitException.php | 2 +- src/Register.php | 371 +++------------ src/Serializer.php | 14 +- src/Url.php | 88 +--- tests/Bot/Test/TestCase.php | 18 +- tests/Bot/Tests/ClientListTest.php | 2 +- tests/Bot/Tests/MessagesTest.php | 5 - 63 files changed, 1939 insertions(+), 2592 deletions(-) delete mode 100644 apigen.neon create mode 100644 phpdoc.dist.xml create mode 100644 src/Bot/Model/Entity/Bot.php delete mode 100644 src/Bot/Model/Entity/Bot/Bot.php delete mode 100644 src/Exception/CurlException.php diff --git a/.gitignore b/.gitignore index dd9286b..8d66bfa 100644 --- a/.gitignore +++ b/.gitignore @@ -185,3 +185,9 @@ $RECYCLE.BIN/ # Windows shortcuts *.lnk /.php_cs.cache + +# phpDocumentor +phpDocumentor.phar +phpDocumentor.phar.pubkey +mg-bot-api-client-php.pages/* +build/* \ No newline at end of file diff --git a/Makefile b/Makefile index 79babc0..2010005 100644 --- a/Makefile +++ b/Makefile @@ -17,3 +17,12 @@ stan: @echo "==> Running analysis" @php $(BIN_DIR)/phpstan analyse -l 4 -c $(ROOT_DIR)/phpstan.neon $(SRC_DIR) @echo "==> Analysis complete" + +docs: + @echo "==> Building docs" +ifeq ($(wildcard *.phar), ) + @wget https://github.com/phpDocumentor/phpDocumentor2/releases/download/v3.0.0-alpha.3/phpDocumentor.phar -O phpDocumentor.phar + @wget https://github.com/phpDocumentor/phpDocumentor2/releases/download/v3.0.0-alpha.3/phpDocumentor.phar.pubkey -O phpDocumentor.phar.pubkey + @chmod +x phpDocumentor.phar + @php phpDocumentor.phar --config $(ROOT_DIR)/phpdoc.dist.xml +endif \ No newline at end of file diff --git a/apigen.neon b/apigen.neon deleted file mode 100644 index 5c74aed..0000000 --- a/apigen.neon +++ /dev/null @@ -1,32 +0,0 @@ -extensions: - - php - -source: - - src - -exclude: - - tests/ - - vendor/ - - bin/ - - docs/ - -charset: - - auto - - UTF-8 - - Windows-1251 - -title: retailCRM PHP MG Bot API client -templateTheme: bootstrap -groups: auto - -accessLevels: - - public - - protected - -internal: true -php: false -tree: true -deprecated: true -todo: true -destination: ../mg-bot-api-client-php.pages/ -download: false diff --git a/composer.json b/composer.json index 38e6582..836779f 100644 --- a/composer.json +++ b/composer.json @@ -15,12 +15,11 @@ "php": ">=7.0", "ext-curl": "*", "ext-json": "*", - "jms/serializer": "1.13.*", - "symfony/validator": "^4.2", "doctrine/annotations": "^1.6", "doctrine/cache": "^1.8", "guzzlehttp/guzzle": "6.0", - "lazyjsonmapper/lazyjsonmapper": "^1.6" + "lazyjsonmapper/lazyjsonmapper": "^1.6", + "symfony/validator": "^4.3" }, "require-dev": { "phpunit/phpunit": "6.5.*", diff --git a/composer.lock b/composer.lock index 8d3ee74..dfa678f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "acac73ae68db3b7df3284c70aa591bbd", + "content-hash": "2d108dc8d869c82038b7dd68b27c44c9", "packages": [ { "name": "corneltek/getoptionkit", @@ -191,62 +191,6 @@ ], "time": "2018-08-21T18:01:43+00:00" }, - { - "name": "doctrine/instantiator", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/doctrine/instantiator.git", - "reference": "a2c590166b2133a4633738648b6b064edae0814a" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/doctrine/instantiator/zipball/a2c590166b2133a4633738648b6b064edae0814a", - "reference": "a2c590166b2133a4633738648b6b064edae0814a", - "shasum": "" - }, - "require": { - "php": "^7.1" - }, - "require-dev": { - "doctrine/coding-standard": "^6.0", - "ext-pdo": "*", - "ext-phar": "*", - "phpbench/phpbench": "^0.13", - "phpstan/phpstan-phpunit": "^0.11", - "phpstan/phpstan-shim": "^0.11", - "phpunit/phpunit": "^7.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, - "autoload": { - "psr-4": { - "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Marco Pivetta", - "email": "ocramius@gmail.com", - "homepage": "http://ocramius.github.com/" - } - ], - "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", - "homepage": "https://www.doctrine-project.org/projects/instantiator.html", - "keywords": [ - "constructor", - "instantiate" - ], - "time": "2019-03-17T17:37:11+00:00" - }, { "name": "doctrine/lexer", "version": "v1.0.1", @@ -481,180 +425,6 @@ ], "time": "2018-12-04T20:46:45+00:00" }, - { - "name": "jms/metadata", - "version": "1.7.0", - "source": { - "type": "git", - "url": "https://github.com/schmittjoh/metadata.git", - "reference": "e5854ab1aa643623dc64adde718a8eec32b957a8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/metadata/zipball/e5854ab1aa643623dc64adde718a8eec32b957a8", - "reference": "e5854ab1aa643623dc64adde718a8eec32b957a8", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "require-dev": { - "doctrine/cache": "~1.0", - "symfony/cache": "~3.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.5.x-dev" - } - }, - "autoload": { - "psr-0": { - "Metadata\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Asmir Mustafic", - "email": "goetas@gmail.com" - }, - { - "name": "Johannes M. Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "Class/method/property metadata management in PHP", - "keywords": [ - "annotations", - "metadata", - "xml", - "yaml" - ], - "time": "2018-10-26T12:40:10+00:00" - }, - { - "name": "jms/parser-lib", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://github.com/schmittjoh/parser-lib.git", - "reference": "c509473bc1b4866415627af0e1c6cc8ac97fa51d" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/parser-lib/zipball/c509473bc1b4866415627af0e1c6cc8ac97fa51d", - "reference": "c509473bc1b4866415627af0e1c6cc8ac97fa51d", - "shasum": "" - }, - "require": { - "phpoption/phpoption": ">=0.9,<2.0-dev" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, - "autoload": { - "psr-0": { - "JMS\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache2" - ], - "description": "A library for easily creating recursive-descent parsers.", - "time": "2012-11-18T18:08:43+00:00" - }, - { - "name": "jms/serializer", - "version": "1.13.0", - "source": { - "type": "git", - "url": "https://github.com/schmittjoh/serializer.git", - "reference": "00863e1d55b411cc33ad3e1de09a4c8d3aae793c" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/serializer/zipball/00863e1d55b411cc33ad3e1de09a4c8d3aae793c", - "reference": "00863e1d55b411cc33ad3e1de09a4c8d3aae793c", - "shasum": "" - }, - "require": { - "doctrine/annotations": "^1.0", - "doctrine/instantiator": "^1.0.3", - "jms/metadata": "^1.3", - "jms/parser-lib": "1.*", - "php": "^5.5|^7.0", - "phpcollection/phpcollection": "~0.1", - "phpoption/phpoption": "^1.1" - }, - "conflict": { - "twig/twig": "<1.12" - }, - "require-dev": { - "doctrine/orm": "~2.1", - "doctrine/phpcr-odm": "^1.3|^2.0", - "ext-pdo_sqlite": "*", - "jackalope/jackalope-doctrine-dbal": "^1.1.5", - "phpunit/phpunit": "^4.8|^5.0", - "propel/propel1": "~1.7", - "psr/container": "^1.0", - "symfony/dependency-injection": "^2.7|^3.3|^4.0", - "symfony/expression-language": "^2.6|^3.0", - "symfony/filesystem": "^2.1", - "symfony/form": "~2.1|^3.0", - "symfony/translation": "^2.1|^3.0", - "symfony/validator": "^2.2|^3.0", - "symfony/yaml": "^2.1|^3.0", - "twig/twig": "~1.12|~2.0" - }, - "suggest": { - "doctrine/cache": "Required if you like to use cache functionality.", - "doctrine/collections": "Required if you like to use doctrine collection types as ArrayCollection.", - "symfony/yaml": "Required if you'd like to serialize data to YAML format." - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-1.x": "1.13-dev" - } - }, - "autoload": { - "psr-0": { - "JMS\\Serializer": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Asmir Mustafic", - "email": "goetas@gmail.com" - }, - { - "name": "Johannes M. Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "Library for (de-)serializing data of any complexity; supports XML, JSON, and YAML.", - "homepage": "http://jmsyst.com/libs/serializer", - "keywords": [ - "deserialization", - "jaxb", - "json", - "serialization", - "xml" - ], - "time": "2018-07-25T13:58:54+00:00" - }, { "name": "lazyjsonmapper/lazyjsonmapper", "version": "v1.6.3", @@ -705,104 +475,6 @@ ], "time": "2018-05-02T16:57:09+00:00" }, - { - "name": "phpcollection/phpcollection", - "version": "0.5.0", - "source": { - "type": "git", - "url": "https://github.com/schmittjoh/php-collection.git", - "reference": "f2bcff45c0da7c27991bbc1f90f47c4b7fb434a6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/php-collection/zipball/f2bcff45c0da7c27991bbc1f90f47c4b7fb434a6", - "reference": "f2bcff45c0da7c27991bbc1f90f47c4b7fb434a6", - "shasum": "" - }, - "require": { - "phpoption/phpoption": "1.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.4-dev" - } - }, - "autoload": { - "psr-0": { - "PhpCollection": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache2" - ], - "authors": [ - { - "name": "Johannes M. Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "General-Purpose Collection Library for PHP", - "keywords": [ - "collection", - "list", - "map", - "sequence", - "set" - ], - "time": "2015-05-17T12:39:23+00:00" - }, - { - "name": "phpoption/phpoption", - "version": "1.5.0", - "source": { - "type": "git", - "url": "https://github.com/schmittjoh/php-option.git", - "reference": "94e644f7d2051a5f0fcf77d81605f152eecff0ed" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/94e644f7d2051a5f0fcf77d81605f152eecff0ed", - "reference": "94e644f7d2051a5f0fcf77d81605f152eecff0ed", - "shasum": "" - }, - "require": { - "php": ">=5.3.0" - }, - "require-dev": { - "phpunit/phpunit": "4.7.*" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.3-dev" - } - }, - "autoload": { - "psr-0": { - "PhpOption\\": "src/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "Apache2" - ], - "authors": [ - { - "name": "Johannes M. Schmitt", - "email": "schmittjoh@gmail.com" - } - ], - "description": "Option Type for PHP", - "keywords": [ - "language", - "option", - "php", - "type" - ], - "time": "2015-07-25T16:39:46+00:00" - }, { "name": "psr/http-message", "version": "1.0.1", @@ -895,36 +567,47 @@ }, { "name": "symfony/contracts", - "version": "v1.0.2", + "version": "v1.1.3", "source": { "type": "git", "url": "https://github.com/symfony/contracts.git", - "reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf" + "reference": "2d19b12caccbd80cf0c85624dc87b7021a0df1d5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/contracts/zipball/1aa7ab2429c3d594dd70689604b5cf7421254cdf", - "reference": "1aa7ab2429c3d594dd70689604b5cf7421254cdf", + "url": "https://api.github.com/repos/symfony/contracts/zipball/2d19b12caccbd80cf0c85624dc87b7021a0df1d5", + "reference": "2d19b12caccbd80cf0c85624dc87b7021a0df1d5", "shasum": "" }, "require": { "php": "^7.1.3" }, + "replace": { + "symfony/cache-contracts": "self.version", + "symfony/event-dispatcher-contracts": "self.version", + "symfony/http-client-contracts": "self.version", + "symfony/service-contracts": "self.version", + "symfony/translation-contracts": "self.version" + }, "require-dev": { "psr/cache": "^1.0", - "psr/container": "^1.0" + "psr/container": "^1.0", + "symfony/polyfill-intl-idn": "^1.10" }, "suggest": { "psr/cache": "When using the Cache contracts", "psr/container": "When using the Service contracts", - "symfony/cache-contracts-implementation": "", - "symfony/service-contracts-implementation": "", - "symfony/translation-contracts-implementation": "" + "psr/event-dispatcher": "When using the EventDispatcher contracts", + "symfony/cache-implementation": "", + "symfony/event-dispatcher-implementation": "", + "symfony/http-client-implementation": "", + "symfony/service-implementation": "", + "symfony/translation-implementation": "" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.0-dev" + "dev-master": "1.1-dev" } }, "autoload": { @@ -959,7 +642,7 @@ "interoperability", "standards" ], - "time": "2018-12-05T08:06:11+00:00" + "time": "2019-06-05T13:28:50+00:00" }, { "name": "symfony/polyfill-ctype", @@ -1080,29 +763,29 @@ }, { "name": "symfony/validator", - "version": "v4.2.5", + "version": "v4.3.1", "source": { "type": "git", "url": "https://github.com/symfony/validator.git", - "reference": "db5457ed88aacc1a040d4961ee52cddad3e5a4aa" + "reference": "ea74d2843fd8a9f2d4800136c985d13da586a405" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/validator/zipball/db5457ed88aacc1a040d4961ee52cddad3e5a4aa", - "reference": "db5457ed88aacc1a040d4961ee52cddad3e5a4aa", + "url": "https://api.github.com/repos/symfony/validator/zipball/ea74d2843fd8a9f2d4800136c985d13da586a405", + "reference": "ea74d2843fd8a9f2d4800136c985d13da586a405", "shasum": "" }, "require": { "php": "^7.1.3", - "symfony/contracts": "^1.0.2", "symfony/polyfill-ctype": "~1.8", - "symfony/polyfill-mbstring": "~1.0" + "symfony/polyfill-mbstring": "~1.0", + "symfony/translation-contracts": "^1.1" }, "conflict": { "phpunit/phpunit": "<4.8.35|<5.4.3,>=5.0", "symfony/dependency-injection": "<3.4", "symfony/http-kernel": "<3.4", - "symfony/intl": "<4.1", + "symfony/intl": "<4.3", "symfony/translation": "<4.2", "symfony/yaml": "<3.4" }, @@ -1114,10 +797,12 @@ "symfony/config": "~3.4|~4.0", "symfony/dependency-injection": "~3.4|~4.0", "symfony/expression-language": "~3.4|~4.0", + "symfony/http-client": "^4.3", "symfony/http-foundation": "~4.1", "symfony/http-kernel": "~3.4|~4.0", - "symfony/intl": "~4.1", + "symfony/intl": "^4.3", "symfony/property-access": "~3.4|~4.0", + "symfony/property-info": "~3.4|~4.0", "symfony/translation": "~4.2", "symfony/var-dumper": "~3.4|~4.0", "symfony/yaml": "~3.4|~4.0" @@ -1132,13 +817,14 @@ "symfony/http-foundation": "", "symfony/intl": "", "symfony/property-access": "For accessing properties within comparison constraints", + "symfony/property-info": "To automatically add NotNull and Type constraints", "symfony/translation": "For translating validation errors.", "symfony/yaml": "" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "4.2-dev" + "dev-master": "4.3-dev" } }, "autoload": { @@ -1165,7 +851,7 @@ ], "description": "Symfony Validator Component", "homepage": "https://symfony.com", - "time": "2019-03-30T15:58:42+00:00" + "time": "2019-06-03T20:27:40+00:00" } ], "packages-dev": [ @@ -1275,6 +961,62 @@ ], "time": "2019-01-28T20:25:53+00:00" }, + { + "name": "doctrine/instantiator", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/instantiator.git", + "reference": "a2c590166b2133a4633738648b6b064edae0814a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/instantiator/zipball/a2c590166b2133a4633738648b6b064edae0814a", + "reference": "a2c590166b2133a4633738648b6b064edae0814a", + "shasum": "" + }, + "require": { + "php": "^7.1" + }, + "require-dev": { + "doctrine/coding-standard": "^6.0", + "ext-pdo": "*", + "ext-phar": "*", + "phpbench/phpbench": "^0.13", + "phpstan/phpstan-phpunit": "^0.11", + "phpstan/phpstan-shim": "^0.11", + "phpunit/phpunit": "^7.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Instantiator\\": "src/Doctrine/Instantiator/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Marco Pivetta", + "email": "ocramius@gmail.com", + "homepage": "http://ocramius.github.com/" + } + ], + "description": "A small, lightweight utility to instantiate objects in PHP without invoking their constructors", + "homepage": "https://www.doctrine-project.org/projects/instantiator.html", + "keywords": [ + "constructor", + "instantiate" + ], + "time": "2019-03-17T17:37:11+00:00" + }, { "name": "friendsofphp/php-cs-fixer", "version": "v2.14.2", diff --git a/phpdoc.dist.xml b/phpdoc.dist.xml new file mode 100644 index 0000000..18287ae --- /dev/null +++ b/phpdoc.dist.xml @@ -0,0 +1,20 @@ + + + retailCRM PHP MG Bot API client + + docs + utf8 + + php + + + + mg-bot-api-client-php.pages + + +