1
0
mirror of synced 2024-11-27 05:46:02 +03:00

Update models & serialization (#3)

This commit is contained in:
Alex Lushpai 2019-07-16 15:04:54 +03:00 committed by GitHub
parent 8001ab64e2
commit 318b2e74cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
86 changed files with 2634 additions and 1943 deletions

View File

@ -1,3 +1,3 @@
MG_BOT_URL="https://mg-test.retailcrm.pro/"
MG_BOT_URL="https://mg-s1.retailcrm.pro/"
MG_BOT_KEY=""
MG_BOT_DBG=""

View File

@ -5,7 +5,6 @@ cache:
- $HOME/.composer/cache
php:
- '7.0'
- '7.1'
- '7.2'
- '7.3'
@ -15,3 +14,6 @@ before_script:
- composer install $flags
script: make travis
after_success:
- bash <(curl -s https://codecov.io/bash)

View File

@ -1,6 +1,6 @@
ROOT_DIR=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
SRC_DIR=$(ROOT_DIR)/src
BIN_DIR=$(ROOT_DIR)/bin
BIN_DIR=$(ROOT_DIR)/vendor/bin
test:
@echo "==> Running tests"
@ -11,7 +11,7 @@ test:
stan:
@echo "==> Running analysis"
@php $(BIN_DIR)/phpstan analyse -a $(ROOT_DIR)/extra/autoloader.php -l 4 src
@php $(BIN_DIR)/phpstan analyse
@echo "==> Analysis complete"
travis: test stan

View File

@ -1,6 +1,7 @@
[![Build Status](https://img.shields.io/travis/retailcrm/mg-bot-api-client-php/master.svg?style=flat-square)](https://travis-ci.org/retailcrm/mg-bot-api-client-php)
[![Covarage](https://img.shields.io/codecov/c/gh/retailcrm/mg-bot-api-client-php/master.svg?style=flat-square)](https://codecov.io/gh/retailcrm/mg-bot-api-client-php)
[![Latest stable](https://img.shields.io/packagist/v/retailcrm/mg-bot-api-client-php.svg?style=flat-square)](https://packagist.org/packages/retailcrm/mg-bot-api-client-php)
[![PHP from Packagist](https://img.shields.io/packagist/php-v/mg-bot-retailcrm/api-client-php.svg?style=flat-square)](https://packagist.org/packages/retailcrm/mg-bot-api-client-php)
[![PHP from Packagist](https://img.shields.io/packagist/php-v/retailcrm/mg-bot-api-client-php.svg?style=flat-square)](https://packagist.org/packages/retailcrm/mg-bot-api-client-php)
# retailCRM API PHP client
@ -9,7 +10,7 @@ This is php retailCRM MG Bot API client.
## Requirements
* PHP 7.0 and above
* PHP 7.1 and above
* PHP's cURL support
* PHP's JSON support

View File

@ -12,40 +12,21 @@
}
],
"require": {
"php": ">=7.0",
"php": ">=7.1",
"ext-curl": "*",
"ext-json": "*",
"jms/serializer": "1.14.*",
"symfony/validator": "3.*",
"doctrine/annotations": "1.4.*",
"symfony/validator": "4.3.*",
"doctrine/annotations": "1.6.*",
"doctrine/cache": "1.6.*",
"guzzlehttp/guzzle": "6.*",
"doctrine/instantiator": "1.0.*",
"symfony/translation": "3.*",
"symfony/dependency-injection": "3.*",
"symfony/config": "3.*",
"symfony/finder": "3.4.*",
"symfony/filesystem": "3.*"
"guzzlehttp/guzzle": "6.*"
},
"require-dev": {
"phpmd/phpmd": "2.*",
"squizlabs/php_codesniffer": "3.4.*",
"symfony/dotenv": "3.*",
"friendsofphp/php-cs-fixer": "2.*",
"phpunit/phpunit": "6.*",
"nette/bootstrap": "2.*",
"nette/neon": "2.*",
"nette/php-generator": "3.0.*",
"phpstan/phpstan": "0.9.*",
"ocramius/package-versions": "1.2.*",
"nette/finder": "2.4.*",
"symfony/console": "3.*",
"symfony/debug": "3.*",
"symfony/event-dispatcher": "3.*",
"symfony/options-resolver": "3.4.*",
"symfony/process": "3.4.*",
"symfony/stopwatch": "3.4.*",
"myclabs/deep-copy": "1.6.*"
"symfony/dotenv": "4.3.*",
"phpunit/phpunit": "7.*",
"phpstan/phpstan": "0.11.*"
},
"support": {
"email": "support@retailcrm.ru"
@ -63,7 +44,7 @@
}
},
"config": {
"bin-dir": "bin",
"bin-dir": "vendor/bin",
"process-timeout": 600
}
}

1758
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
parameters:
autoload_files:
- %currentWorkingDirectory%/vendor/autoload.php
level: 4
level: 7
paths:
- %currentWorkingDirectory%/src

View File

@ -1,22 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="phpunit.xsd"
bootstrap="./tests/bootstrap.php"
colors="true"
verbose="true"
processIsolation="false"
stopOnFailure="false">
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
backupGlobals="false"
colors="false"
bootstrap="tests/bootstrap.php"
backupStaticAttributes="false"
convertErrorsToExceptions="false"
convertNoticesToExceptions="false"
convertWarningsToExceptions="false"
processIsolation="true"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
>
<testsuites>
<testsuite name="RetailCrm">
<directory>tests/Bot/Tests</directory>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/Bot</directory>
<directory>src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="clover.xml"/>
<log type="junit" target="/tmp/logfile.xml"/>
</logging>
</phpunit>

View File

@ -0,0 +1,87 @@
<?php
/**
* PHP version 7.1
*
* ModelAdapter
*
* @package RetailCrm\Mg\Bot\Adapter
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Adapter;
use RetailCrm\Common\Exception\InvalidJsonException;
use RetailCrm\Common\Serializer;
use RetailCrm\Mg\Bot\Model\Response;
/**
* Class ModelAdapter
*
* @package RetailCrm\Mg\Bot\Adapter
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ModelAdapter
{
/**
* @var mixed $model
*/
private $model;
/**
* @var string $classname
*/
private $classname;
/**
* ModelAdapter constructor.
*
* @param string $classname
*
*/
public function __construct(string $classname)
{
$this->model = new $classname;
$this->classname = $classname;
}
/**
* Get Response Model
*
* @param \RetailCrm\Mg\Bot\Model\Response $response
*
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
*/
public function getResponseModel(Response $response)
{
return Serializer::deserialize($response->getBody(), $this->model);
}
/**
* Get Response List
*
* @param \RetailCrm\Mg\Bot\Model\Response $response
*
* @return array
*/
public function getResponseList(Response $response)
{
$array = json_decode($response->getBody(), true);
if (json_last_error() != JSON_ERROR_NONE) {
throw new InvalidJsonException('Received invalid JSON', 1);
}
$result = [];
foreach ($array as $item) {
$result[] = Serializer::deserialize($item, $this->classname, Serializer::S_ARRAY);
}
return $result;
}
}

View File

@ -0,0 +1,61 @@
<?php
/**
* PHP version 7.1
*
* Response adapter
*
* @package RetailCrm\Mg\Bot\Adapter
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Adapter;
use Psr\Http\Message\ResponseInterface;
use RetailCrm\Mg\Bot\Model\Response;
/**
* Class ResponseAdapter
*
* @package RetailCrm\Mg\Bot
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ResponseAdapter
{
/**
* @var \RetailCrm\Mg\Bot\Model\Response $model
*/
private $model;
/**
* @var \Psr\Http\Message\ResponseInterface $interface
*/
private $interface;
/**
* ResponseAdapter constructor.
*
* @param \Psr\Http\Message\ResponseInterface $interface
*/
public function __construct(ResponseInterface $interface)
{
$this->interface = $interface;
$this->model = new Response();
}
/**
* Build response
*
* @return \RetailCrm\Mg\Bot\Model\Response
*/
public function build(): Response
{
$this->model->setStatus($this->interface->getStatusCode());
$this->model->setBody((string) $this->interface->getBody());
return $this->model;
}
}

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Client
*
@ -14,18 +14,26 @@
namespace RetailCrm\Mg\Bot;
use Psr\Http\Message\ResponseInterface;
use RetailCrm\Common\Exception\InvalidJsonException;
use RetailCrm\Common\Url;
use RetailCrm\Common\Serializer;
use RetailCrm\Mg\Bot\Adapter\ModelAdapter;
use RetailCrm\Mg\Bot\Model\Entity\Bot;
use RetailCrm\Mg\Bot\Model\Entity\Channel\Channel;
use RetailCrm\Mg\Bot\Model\Entity\Chat\Chat;
use RetailCrm\Mg\Bot\Model\Entity\Chat\ChatMember;
use RetailCrm\Mg\Bot\Model\Entity\Command;
use RetailCrm\Mg\Bot\Model\Entity\Customer;
use RetailCrm\Mg\Bot\Model\Entity\Dialog;
use RetailCrm\Mg\Bot\Model\Entity\Message\Message;
use RetailCrm\Mg\Bot\Model\Entity\User;
use RetailCrm\Mg\Bot\Model\Request\UploadFileByUrlRequest;
use RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse;
use RetailCrm\Mg\Bot\Model\Response\FullFileResponse;
use RetailCrm\Mg\Bot\Model\Response\ListResponse;
use RetailCrm\Mg\Bot\Model\Response\MessageSendResponse;
use RetailCrm\Mg\Bot\Model\Response\UploadFileResponse;
/**
* PHP version 7.0
*
* Client class
* Class Client
*
* @package RetailCrm\Mg\Bot
* @author retailCRM <integration@retailcrm.ru>
@ -39,11 +47,6 @@ class Client
*/
const VERSION = 'v1';
/**
* @internal
*/
const ERROR_ONLY_RESPONSE = 'ErrorOnlyResponse';
/**
* @var HttpClient
*/
@ -63,115 +66,25 @@ class Client
$this->client = new HttpClient($url, $token, $debug ? STDOUT : null, $handler);
}
/**
* @param string $path
* @param string $method
* @param object|null $request Request parameters
* @param string $responseType
* @param bool $arrayOfObjects
*
* @return object|null
* @throws \Exception
*/
private function submitRequest(
$path,
$method,
$request,
$responseType,
$arrayOfObjects = false
) {
$response = $this->client->makeRequest(
$path,
$method,
$request
);
$statusCode = $response->getStatusCode();
$data = json_decode((string) $response->getBody(), true);
if (json_last_error() == JSON_ERROR_NONE) {
if ($arrayOfObjects) {
return new ListResponse($responseType, $data, $statusCode);
} else {
$obj = Serializer::deserialize($data, $responseType, Serializer::S_ARRAY);
if ($statusCode >= 400
&& method_exists($obj, 'setErrors')
&& method_exists($obj, 'getErrors')
&& count(call_user_func([$obj, 'getErrors'])) == 0
) {
call_user_func_array([$obj, 'setErrors'], [['Status Code ' . $response->getStatusCode()]]);
}
if (method_exists($obj, 'setStatusCode')) {
call_user_func_array([$obj, 'setStatusCode'], [$statusCode]);
}
return $obj;
}
} else {
throw new InvalidJsonException('Received invalid JSON', 1);
}
}
/**
* @param bool $fromRoot
* @param string ...$classes
*
* @return string
*/
private static function concatClasspath($fromRoot, ...$classes)
{
$path = '';
foreach ($classes as $class) {
if (empty($path) && !$fromRoot) {
$path .= $class;
} else {
$path .= '\\' . $class;
}
}
return $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);
}
/**
* Returns filtered bots list
*
* @param Model\Request\BotsRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @return array
* @throws \Exception
*/
public function bots(Model\Request\BotsRequest $request)
public function bots(Model\Request\BotsRequest $request): array
{
return $this->submitRequest(
$response = $this->client->makeRequest(
'/bots',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Bot'),
true
$request
);
$adapter = new ModelAdapter(Bot::class);
return $adapter->getResponseList($response);
}
/**
@ -179,17 +92,20 @@ class Client
*
* @param Model\Request\InfoRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse|object
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
* @throws \Exception
*/
public function info(Model\Request\InfoRequest $request)
{
return $this->submitRequest(
$response = $this->client->makeRequest(
'/my/info',
HttpClient::METHOD_PATCH,
$request,
static::getResponseClass(self::ERROR_ONLY_RESPONSE)
$request
);
$adapter = new ModelAdapter(ErrorOnlyResponse::class);
return $adapter->getResponseModel($response);
}
/**
@ -197,18 +113,20 @@ class Client
*
* @param Model\Request\ChannelsRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @return array
* @throws \Exception
*/
public function channels(Model\Request\ChannelsRequest $request)
public function channels(Model\Request\ChannelsRequest $request): array
{
return $this->submitRequest(
$response = $this->client->makeRequest(
'/channels',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Channel', 'Channel'),
true
$request
);
$adapter = new ModelAdapter(Channel::class);
return $adapter->getResponseList($response);
}
/**
@ -216,18 +134,20 @@ class Client
*
* @param Model\Request\ChatsRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @return array
* @throws \Exception
*/
public function chats(Model\Request\ChatsRequest $request)
public function chats(Model\Request\ChatsRequest $request): array
{
return $this->submitRequest(
$response = $this->client->makeRequest(
'/chats',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Chat', 'Chat'),
true
$request
);
$adapter = new ModelAdapter(Chat::class);
return $adapter->getResponseList($response);
}
/**
@ -235,18 +155,20 @@ class Client
*
* @param Model\Request\CommandsRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @return array
* @throws \Exception
*/
public function commands(Model\Request\CommandsRequest $request)
public function commands(Model\Request\CommandsRequest $request): array
{
return $this->submitRequest(
$response = $this->client->makeRequest(
'/my/commands',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Command'),
true
$request
);
$adapter = new ModelAdapter(Command::class);
return $adapter->getResponseList($response);
}
/**
@ -254,17 +176,20 @@ class Client
*
* @param Model\Request\CommandEditRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse|object
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
* @throws \Exception
*/
public function commandEdit(Model\Request\CommandEditRequest $request)
{
return $this->submitRequest(
$response = $this->client->makeRequest(
sprintf("/my/commands/%s", $request->getName()),
HttpClient::METHOD_PUT,
$request,
static::getResponseClass(self::ERROR_ONLY_RESPONSE)
$request
);
$adapter = new ModelAdapter(ErrorOnlyResponse::class);
return $adapter->getResponseModel($response);
}
/**
@ -272,17 +197,19 @@ class Client
*
* @param string $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse|object
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
* @throws \Exception
*/
public function commandDelete(string $request)
{
return $this->submitRequest(
$response = $this->client->makeRequest(
sprintf("/my/commands/%s", $request),
HttpClient::METHOD_DELETE,
null,
static::getResponseClass(self::ERROR_ONLY_RESPONSE)
HttpClient::METHOD_DELETE
);
$adapter = new ModelAdapter(ErrorOnlyResponse::class);
return $adapter->getResponseModel($response);
}
/**
@ -290,18 +217,20 @@ class Client
*
* @param Model\Request\CustomersRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @return array
* @throws \Exception
*/
public function customers(Model\Request\CustomersRequest $request)
public function customers(Model\Request\CustomersRequest $request): array
{
return $this->submitRequest(
$response = $this->client->makeRequest(
'/customers',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Customer'),
true
$request
);
$adapter = new ModelAdapter(Customer::class);
return $adapter->getResponseList($response);
}
/**
@ -309,18 +238,20 @@ class Client
*
* @param Model\Request\DialogsRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @return array
* @throws \Exception
*/
public function dialogs(Model\Request\DialogsRequest $request)
public function dialogs(Model\Request\DialogsRequest $request): array
{
return $this->submitRequest(
$response = $this->client->makeRequest(
'/dialogs',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Dialog'),
true
$request
);
$adapter = new ModelAdapter(Dialog::class);
return $adapter->getResponseList($response);
}
/**
@ -328,17 +259,20 @@ class Client
*
* @param Model\Request\DialogAssignRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\AssignResponse|object
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
* @throws \Exception
*/
public function dialogAssign(Model\Request\DialogAssignRequest $request)
{
return $this->submitRequest(
$response = $this->client->makeRequest(
sprintf("/dialogs/%d/assign", $request->getDialogId()),
HttpClient::METHOD_PATCH,
$request,
static::getResponseClass('AssignResponse')
$request
);
$adapter = new ModelAdapter(ErrorOnlyResponse::class);
return $adapter->getResponseModel($response);
}
/**
@ -346,17 +280,20 @@ class Client
*
* @param string $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse|object
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
* @throws \Exception
*/
public function dialogClose(string $request)
{
return $this->submitRequest(
$response = $this->client->makeRequest(
sprintf("/dialogs/%d/close", $request),
HttpClient::METHOD_DELETE,
null,
static::getResponseClass(self::ERROR_ONLY_RESPONSE)
null
);
$adapter = new ModelAdapter(ErrorOnlyResponse::class);
return $adapter->getResponseModel($response);
}
/**
@ -364,18 +301,20 @@ class Client
*
* @param Model\Request\MembersRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @return array
* @throws \Exception
*/
public function members(Model\Request\MembersRequest $request)
public function members(Model\Request\MembersRequest $request): array
{
return $this->submitRequest(
$response = $this->client->makeRequest(
'/members',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Chat', 'ChatMember'),
true
$request
);
$adapter = new ModelAdapter(ChatMember::class);
return $adapter->getResponseList($response);
}
/**
@ -383,18 +322,20 @@ class Client
*
* @param Model\Request\MessagesRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @return array
* @throws \Exception
*/
public function messages(Model\Request\MessagesRequest $request)
public function messages(Model\Request\MessagesRequest $request): array
{
return $this->submitRequest(
$response = $this->client->makeRequest(
'/messages',
HttpClient::METHOD_GET,
$request,
self::getEntityClass('Message', 'Message'),
true
$request
);
$adapter = new ModelAdapter(Message::class);
return $adapter->getResponseList($response);
}
/**
@ -402,17 +343,20 @@ class Client
*
* @param Model\Request\MessageSendRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\MessageSendResponse|object
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
* @throws \Exception
*/
public function messageSend(Model\Request\MessageSendRequest $request)
{
return $this->submitRequest(
$response = $this->client->makeRequest(
'/messages',
HttpClient::METHOD_POST,
$request,
static::getResponseClass('MessageSendResponse')
$request
);
$adapter = new ModelAdapter(MessageSendResponse::class);
return $adapter->getResponseModel($response);
}
/**
@ -420,17 +364,20 @@ class Client
*
* @param Model\Request\MessageEditRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\MessageSendResponse|object
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
* @throws \Exception
*/
public function messageEdit(Model\Request\MessageEditRequest $request)
{
return $this->submitRequest(
$response = $this->client->makeRequest(
sprintf("/messages/%d", $request->getId()),
HttpClient::METHOD_PATCH,
$request,
static::getResponseClass('MessageSendResponse')
$request
);
$adapter = new ModelAdapter(MessageSendResponse::class);
return $adapter->getResponseModel($response);
}
/**
@ -438,17 +385,20 @@ class Client
*
* @param string $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse|object
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
* @throws \Exception
*/
public function messageDelete(string $request)
{
return $this->submitRequest(
$response = $this->client->makeRequest(
sprintf("/messages/%d", $request),
HttpClient::METHOD_DELETE,
null,
static::getResponseClass(self::ERROR_ONLY_RESPONSE)
null
);
$adapter = new ModelAdapter(ErrorOnlyResponse::class);
return $adapter->getResponseModel($response);
}
/**
@ -456,18 +406,20 @@ class Client
*
* @param Model\Request\UsersRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @return array
* @throws \Exception
*/
public function users(Model\Request\UsersRequest $request)
public function users(Model\Request\UsersRequest $request): array
{
return $this->submitRequest(
$response = $this->client->makeRequest(
'/users',
HttpClient::METHOD_GET,
$request,
self::getEntityClass('User'),
true
$request
);
$adapter = new ModelAdapter(User::class);
return $adapter->getResponseList($response);
}
/**
@ -475,7 +427,7 @@ class Client
*
* @param string $url File URL
*
* @return \RetailCrm\Mg\Bot\Model\Response\UploadFileResponse|object
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
* @throws \Exception
*/
public function uploadFileByUrl(string $url)
@ -483,51 +435,54 @@ class Client
$request = new UploadFileByUrlRequest();
$request->setUrl($url);
return $this->submitRequest(
$response = $this->client->makeRequest(
'/files/upload_by_url',
HttpClient::METHOD_POST,
$request,
self::getResponseClass('UploadFileResponse')
$request
);
$adapter = new ModelAdapter(UploadFileResponse::class);
return $adapter->getResponseModel($response);
}
/**
* @param string $filename
* @return Model\Response\UploadFileResponse|null
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
*
* @throws \Exception
*/
public function uploadFile(string $filename)
{
$obj = new ErrorOnlyResponse();
$response = $this->client->postFile($filename);
if ($response instanceof ResponseInterface) {
$obj = Serializer::deserialize(
(string) $response->getBody(),
self::getResponseClass('UploadFileResponse')
UploadFileResponse::class
);
return $obj instanceof UploadFileResponse ? $obj : null;
}
return null;
return $obj;
}
/**
* @param string $fileId
* @return Model\Response\FullFileResponse|null
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
*
* @throws \Exception
*/
public function getFileById(string $fileId)
{
$obj = $this->submitRequest(
\sprintf('/files/%s', $fileId),
$response = $this->client->makeRequest(
sprintf('/files/%s', $fileId),
HttpClient::METHOD_GET,
null,
self::getResponseClass('FullFileResponse')
null
);
return ($obj instanceof FullFileResponse) ? $obj : null;
$adapter = new ModelAdapter(FullFileResponse::class);
return $adapter->getResponseModel($response);
}
}

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* HttpClient
*
@ -13,11 +13,18 @@
namespace RetailCrm\Mg\Bot;
use BadMethodCallException;
use ErrorException;
use Exception;
use InvalidArgumentException;
use RetailCrm\Common\Exception\InvalidJsonException;
use RetailCrm\Common\Exception\LimitException;
use InvalidArgumentException;
use RetailCrm\Common\Exception\NotFoundException;
use RetailCrm\Common\Exception\UnauthorizedException;
use RetailCrm\Common\Serializer;
use RetailCrm\Common\Url;
use RetailCrm\Mg\Bot\Adapter\ResponseAdapter;
use RuntimeException;
use Symfony\Component\Validator\Validation;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
@ -26,9 +33,7 @@ use Psr\Http\Message\ResponseInterface;
use function GuzzleHttp\Psr7\stream_for;
/**
* PHP version 7.0
*
* HttpClient class
* Class HttpClient
*
* @package RetailCrm\Mg\Bot
* @author retailCRM <integration@retailcrm.ru>
@ -107,7 +112,7 @@ class HttpClient
* @param string $method Request method (default: 'GET')
* @param mixed $request Request model (default: null)
*
* @return ResponseInterface
* @return \RetailCrm\Mg\Bot\Model\Response
* @throws \Exception
*/
public function makeRequest($path, $method, $request = null)
@ -121,20 +126,20 @@ class HttpClient
}
if ($method == self::METHOD_GET && !is_null($request)) {
$getParameters = Url::buildGetParameters(Serializer::serialize($request, Serializer::S_ARRAY));
$getParameters = Url::buildGetParameters((array)Serializer::serialize($request, Serializer::S_ARRAY));
}
$requestBody = is_null($request) ? null : Serializer::serialize($request, Serializer::S_JSON);
$requestBody = is_null($request) ? '' : Serializer::serialize($request, Serializer::S_JSON);
$request = new Request(
$method,
\sprintf("%s%s%s", $this->basePath, $path, $getParameters),
sprintf("%s%s%s", $this->basePath, $path, $getParameters),
[
'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])) {
if (in_array($method, [self::METHOD_POST, self::METHOD_PUT, self::METHOD_PATCH, self::METHOD_DELETE]) && is_string($requestBody)) {
$request = $request->withBody(stream_for($requestBody));
}
@ -151,27 +156,14 @@ class HttpClient
]
);
} catch (GuzzleException $exception) {
throw new \Exception($exception->getMessage(), $exception->getCode(), $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;
$this->validateResponse($responseObject);
/**
* 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 \InvalidArgumentException($errorMessage);
}
$adapter = new ResponseAdapter($responseObject);
if ($statusCode == 503) {
throw new LimitException($errorMessage);
}
return $responseObject;
return $adapter->build();
}
/**
@ -183,17 +175,17 @@ class HttpClient
public function postFile(string $filename)
{
if (!file_exists($filename)) {
throw new \InvalidArgumentException("File doesn't exist");
throw new InvalidArgumentException("File doesn't exist");
}
if (filesize($filename) == 0) {
throw new \InvalidArgumentException("Empty file provided");
throw new InvalidArgumentException("Empty file provided");
}
try {
$responseData = $this->client->request(
self::METHOD_POST,
\sprintf("%s/files/upload", $this->basePath),
sprintf("%s/files/upload", $this->basePath),
[
'headers' => [
'X-Bot-Token' => $this->token
@ -202,7 +194,7 @@ class HttpClient
]
);
} catch (GuzzleException $exception) {
throw new \Exception($exception->getMessage(), $exception->getCode(), $exception);
throw new Exception($exception->getMessage(), $exception->getCode(), $exception);
}
return isset($responseData) ? $responseData : null;
@ -235,22 +227,65 @@ class HttpClient
*/
private function validateRequest($class)
{
if (!is_string($class) && method_exists($class, 'validate')) {
$errors = $class->validate();
} else {
$validator = Validation::createValidatorBuilder()
->enableAnnotationMapping()
->getValidator();
$errors = $validator->validate($class);
if ($errors->count() > 0) {
$message = '';
foreach ($errors as $error) {
$message .= (string)$error;
}
if ((is_object($errors) && call_user_func([$errors, 'count']) > 0) || is_string($errors)) {
$message = (string) $errors;
throw new InvalidArgumentException($message);
}
}
/**
* @param \Psr\Http\Message\ResponseInterface $responseObject
*
* @throws \ErrorException
*/
private function validateResponse(ResponseInterface $responseObject)
{
$statusCode = $responseObject->getStatusCode();
$response = self::parseJSON((string)$responseObject->getBody());
$errorMessage = !empty($response['errorMsg']) ? $response['errorMsg'] : '';
$errorMessage = !empty($response['errors']) ? $this->getErrors($response['errors']) : $errorMessage;
/**
* responses with 400 & 460 http codes contains extended error data
* therefore they are not handled as exceptions
*/
if ($statusCode == 400) {
throw new RuntimeException($errorMessage);
}
if (in_array($statusCode, [401, 403])) {
throw new UnauthorizedException($errorMessage);
}
if ($statusCode == 404) {
throw new NotFoundException($errorMessage);
}
if (in_array($statusCode, [405, 501])) {
throw new BadMethodCallException($errorMessage);
}
if (in_array($statusCode, [500, 502])) {
throw new ErrorException($errorMessage);
}
if ($statusCode == 503) {
throw new LimitException($errorMessage);
}
}
/**
* @param array $errors
*

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Constants
*
@ -14,8 +14,6 @@
namespace RetailCrm\Mg\Bot\Model;
/**
* PHP version 7.0
*
* Constants class
*
* @package RetailCrm\Mg\Bot\Model

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Bot entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Bot class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Bot
class Bot implements ModelInterface
{
/**
* @var string $id

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Channel entity
*
@ -13,21 +13,20 @@
namespace RetailCrm\Mg\Bot\Model\Entity\Channel;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use DateTime;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Channel class
* Class Channel
*
* @package RetailCrm\Mg\Bot\Model\Entity\Channel
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Channel
class Channel implements ModelInterface
{
/**
* @var string $id
@ -120,7 +119,7 @@ class Channel
/**
* @return \DateTime
*/
public function getCreatedAt(): \DateTime
public function getCreatedAt(): DateTime
{
return $this->createdAt;
}
@ -128,7 +127,7 @@ class Channel
/**
* @param \DateTime $createdAt
*/
public function setCreatedAt(\DateTime $createdAt)
public function setCreatedAt(DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
@ -136,7 +135,7 @@ class Channel
/**
* @return \DateTime
*/
public function getUpdatedAt(): \DateTime
public function getUpdatedAt(): DateTime
{
return $this->updatedAt;
}
@ -144,7 +143,7 @@ class Channel
/**
* @param \DateTime $updatedAt
*/
public function setUpdatedAt(\DateTime $updatedAt)
public function setUpdatedAt(DateTime $updatedAt)
{
$this->updatedAt = $updatedAt;
}
@ -152,7 +151,7 @@ class Channel
/**
* @return \DateTime
*/
public function getActivatedAt(): \DateTime
public function getActivatedAt(): DateTime
{
return $this->activatedAt;
}
@ -160,7 +159,7 @@ class Channel
/**
* @param \DateTime $activatedAt
*/
public function setActivatedAt(\DateTime $activatedAt)
public function setActivatedAt(DateTime $activatedAt)
{
$this->activatedAt = $activatedAt;
}
@ -168,7 +167,7 @@ class Channel
/**
* @return \DateTime
*/
public function getDeactivatedAt(): \DateTime
public function getDeactivatedAt(): DateTime
{
return $this->deactivatedAt;
}
@ -176,7 +175,7 @@ class Channel
/**
* @param \DateTime $deactivatedAt
*/
public function setDeactivatedAt(\DateTime $deactivatedAt)
public function setDeactivatedAt(DateTime $deactivatedAt)
{
$this->deactivatedAt = $deactivatedAt;
}

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* ChannelSettings entity
*
@ -16,18 +16,17 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Channel;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* ChannelSettings class
* Class ChannelSettings
*
* @package RetailCrm\Mg\Bot\Model\Entity\Channel
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ChannelSettings
class ChannelSettings implements ModelInterface
{
/**
* @var ChannelSettingsStatus $status

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* ChannelSettingsItem entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Channel;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* ChannelSettingsItem class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Channel
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ChannelSettingsItem
class ChannelSettingsItem implements ModelInterface
{
/**
* @var string $creating

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* ChannelSettingsStatus entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Channel;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* ChannelSettingsStatus class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Channel
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ChannelSettingsStatus
class ChannelSettingsStatus implements ModelInterface
{
/**
* @var string $delivered

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Chat entity
*
@ -18,10 +18,9 @@ use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\Entity\Customer;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Chat class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Chat
@ -29,7 +28,7 @@ use RetailCrm\Mg\Bot\Model\Entity\Customer;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Chat
class Chat implements ModelInterface
{
/**
* @var string $id

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* ChatLastMessage entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Chat;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* ChatLastMessage class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Chat
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ChatLastMessage
class ChatLastMessage implements ModelInterface
{
/**
* @var int $creating

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* ChatMember entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Chat;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* ChatMember class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Chat
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ChatMember
class ChatMember implements ModelInterface
{
/**
* @var string $id

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Command entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Command class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Command
class Command implements ModelInterface
{
/**
* @var string $id

View File

@ -0,0 +1,81 @@
<?php
/**
* PHP version 7.1
*
* Cost entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @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;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* Cost class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Cost implements ModelInterface
{
/**
* @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;
}
}

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Customer entity
*
@ -13,23 +13,21 @@
namespace RetailCrm\Mg\Bot\Model\Entity;
use RetailCrm\Mg\Bot\Model\ModelInterface;
use Symfony\Component\Validator\Constraints as Assert;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Customer class
* | email | string |
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Customer
class Customer implements ModelInterface
{
/**
* @var string $id

View File

@ -0,0 +1,132 @@
<?php
/**
* PHP version 7.1
*
* Delivery entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @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;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* Delivery class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Delivery implements ModelInterface
{
/**
* @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;
}
}

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Dialog entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Dialog class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Dialog
class Dialog implements ModelInterface
{
/**
* @var string $id

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* FileMeta entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* FileMeta class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class FileMeta
class FileMeta implements ModelInterface
{
/**
* @var int $height

View File

@ -0,0 +1,80 @@
<?php
/**
* PHP version 7.1
*
* Item entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @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;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* Item class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Item implements ModelInterface
{
/**
* @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;
}
}

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Item entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Item class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Item
class Item implements ModelInterface
{
/**
* @var string $id

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Message entity
*
@ -18,10 +18,9 @@ use RetailCrm\Mg\Bot\Model\Entity\User;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Message class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -29,7 +28,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Message
class Message implements ModelInterface
{
/**
* @var string $id

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* MessageCost entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessageCost class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageCost
class MessageCost implements ModelInterface
{
/**
* @var float $value

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* MessageDelivery entity
*
@ -16,11 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\Entity\Message\MessageCost;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessageDelivery class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -28,7 +26,7 @@ use RetailCrm\Mg\Bot\Model\Entity\Message\MessageCost;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageDelivery
class MessageDelivery implements ModelInterface
{
/**
* @var string $name

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* MessageOrder entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessageOrder class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageOrder
class MessageOrder implements ModelInterface
{
/**
* @var string $number

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0.
* PHP version 7.1
*
* MessageOrderItem entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0.
*
* MessageOrderItem class
*
* @author retailCRM <integration@retailcrm.ru>
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
*
* @see http://help.retailcrm.pro/docs/Developers
*/
class MessageOrderItem
class MessageOrderItem implements ModelInterface
{
/**
* @var string

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* MessageOrderPaymentStatus entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessageOrderPaymentStatus class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageOrderPaymentStatus
class MessageOrderPaymentStatus implements ModelInterface
{
/**
* @var string $name

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* MessagePayment entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessagePayment class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessagePayment
class MessagePayment implements ModelInterface
{
/**
* @var string $name

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* MessageProduct entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessageProduct class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageProduct
class MessageProduct implements ModelInterface
{
/**
* @var int $id

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* MessageQuantity entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessageQuantity class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageQuantity
class MessageQuantity implements ModelInterface
{
/**
* @var float $value

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* MessageStatus entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessageStatus class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageStatus
class MessageStatus implements ModelInterface
{
/**
* @var string $code

View File

@ -0,0 +1,230 @@
<?php
/**
* PHP version 7.1
*
* Order entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @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;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* Order class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Order implements ModelInterface
{
/**
* @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;
}
}

View File

@ -0,0 +1,155 @@
<?php
/**
* PHP version 7.1
*
* Order item entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @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;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* OrderItem class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class OrderItem implements ModelInterface
{
/**
* @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;
}
}

View File

@ -0,0 +1,105 @@
<?php
/**
* PHP version 7.1
*
* Payment entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @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;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* Payment class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Payment implements ModelInterface
{
/**
* @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;
}
}

View File

@ -0,0 +1,80 @@
<?php
/**
* PHP version 7.1
*
* Payment status entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @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;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PaymentStatus class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class PaymentStatus implements ModelInterface
{
/**
* @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;
}
}

View File

@ -0,0 +1,205 @@
<?php
/**
* PHP version 7.1
*
* Product entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @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;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* Product class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Product implements ModelInterface
{
/**
* @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;
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
* PHP version 7.1
*
* Quantity entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @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;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* Quantity class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Quantity implements ModelInterface
{
/**
* @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;
}
}

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Responsible entity
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* Responsible class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Responsible
class Responsible implements ModelInterface
{
/**
* @var string $assignedAt

View File

@ -0,0 +1,80 @@
<?php
/**
* PHP version 7.1
*
* Status entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @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;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* Status class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Status implements ModelInterface
{
/**
* @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;
}
}

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* User entity
*
@ -13,14 +13,13 @@
namespace RetailCrm\Mg\Bot\Model\Entity;
use RetailCrm\Mg\Bot\Model\ModelInterface;
use Symfony\Component\Validator\Constraints as Assert;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* User class
*
* @package RetailCrm\Mg\Bot\Model\Entity
@ -28,7 +27,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class User
class User implements ModelInterface
{
/**
* @var string $id

View File

@ -0,0 +1,18 @@
<?php
/**
* PHP version 7.1
*
* ModelInterface
*
* @package RetailCrm\Mg\Bot\Model
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model;
interface ModelInterface
{
}

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Bots Request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* BotsRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class BotsRequest
class BotsRequest implements ModelInterface
{
use CommonFields;

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Channels list request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* ChannelsRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ChannelsRequest
class ChannelsRequest implements ModelInterface
{
use CommonFields;

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Chats list request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* ChatsRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ChatsRequest
class ChatsRequest implements ModelInterface
{
use CommonFields;

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Edit Command Request
*
@ -13,15 +13,12 @@
namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use Symfony\Component\Validator\Constraints as Assert;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* CommandEditRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -29,7 +26,7 @@ use Symfony\Component\Validator\Constraints as Assert;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class CommandEditRequest
class CommandEditRequest implements ModelInterface
{
/**
* @var int $botId

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Commands list request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* CommandsRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class CommandsRequest
class CommandsRequest implements ModelInterface
{
use CommonFields;

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Common fields
*
@ -18,8 +18,6 @@ use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* CommonFields trait
*
* @package RetailCrm\Mg\Bot\Model\Request

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Customers list request
*
@ -16,11 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\Request\CommonFields;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* CustomersRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -28,7 +26,7 @@ use RetailCrm\Mg\Bot\Model\Request\CommonFields;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class CustomersRequest
class CustomersRequest implements ModelInterface
{
use CommonFields;

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Dialog assign request
*
@ -17,10 +17,9 @@ use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* DialogAssignRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -28,7 +27,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class DialogAssignRequest
class DialogAssignRequest implements ModelInterface
{
/**
* @var int $dialogId

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Dialogs list request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* DialogsRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class DialogsRequest
class DialogsRequest implements ModelInterface
{
use CommonFields;

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Bot info request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* InfoRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class InfoRequest
class InfoRequest implements ModelInterface
{
/**
* @var string $name

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Members list request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MembersRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MembersRequest
class MembersRequest implements ModelInterface
{
/**
* @var int $chatId

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Messages edit request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessageEditRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageEditRequest
class MessageEditRequest implements ModelInterface
{
/**
* @var int $id

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Messages send request
*
@ -18,13 +18,10 @@ use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\Entity\Message\MessageOrder;
use RetailCrm\Mg\Bot\Model\Entity\Message\MessageProduct;
use RetailCrm\Mg\Bot\Model\ModelInterface;
use Symfony\Component\Validator\Constraints as Assert;
use RetailCrm\Mg\Bot\Model\Entity\Order;
use RetailCrm\Mg\Bot\Model\Entity\Product;
/**
* PHP version 7.0
*
* MessageSendRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -32,7 +29,7 @@ use RetailCrm\Mg\Bot\Model\Entity\Product;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageSendRequest
class MessageSendRequest implements ModelInterface
{
/**
* @var string $type

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Messages list request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* MessagesRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessagesRequest
class MessagesRequest implements ModelInterface
{
use CommonFields;

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Upload file by url request
*
@ -15,11 +15,10 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
use Symfony\Component\Validator\Constraints as Assert;
/**
* PHP version 7.0
*
* UploadFileByUrlRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use Symfony\Component\Validator\Constraints as Assert;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class UploadFileByUrlRequest
class UploadFileByUrlRequest implements ModelInterface
{
/**
* @var string $url

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Users list request
*
@ -16,10 +16,9 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* UsersRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class UsersRequest
class UsersRequest implements ModelInterface
{
use CommonFields;

View File

@ -0,0 +1,57 @@
<?php
/**
* PHP version 7.1
*
* ModelInterface
*
* @package RetailCrm\Mg\Bot\Model
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model;
/**
* Class Response
*
* @package RetailCrm\Mg\Bot\Model
*/
class Response
{
private $status;
private $body;
/**
* @return mixed
*/
public function getStatus()
{
return $this->status;
}
/**
* @param mixed $status
*/
public function setStatus($status)
{
$this->status = $status;
}
/**
* @return mixed
*/
public function getBody()
{
return $this->body;
}
/**
* @param mixed $body
*/
public function setBody($body)
{
$this->body = $body;
}
}

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* AssignResponse
*
@ -17,10 +17,9 @@ 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\ModelInterface;
/**
* PHP version 7.0
*
* AssignResponse class
*
* @package RetailCrm\Mg\Bot\Model\Response
@ -28,7 +27,7 @@ use RetailCrm\Mg\Bot\Model\Entity\Responsible;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class AssignResponse
class AssignResponse implements ModelInterface
{
use CommonFields;

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* ErrorTrait
*
@ -19,8 +19,6 @@ use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* CommonFields trait
*
* @package RetailCrm\Mg\Bot\Model\Response
@ -50,7 +48,7 @@ trait CommonFields
*/
public function getErrors(): array
{
return is_null($this->errors) ? [] : $this->errors;
return empty($this->errors) ? [] : $this->errors;
}
/**

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* ErrorOnlyResponse
*
@ -13,9 +13,9 @@
namespace RetailCrm\Mg\Bot\Model\Response;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* ErrorOnlyResponse class
*
* @package RetailCrm\Mg\Bot\Model\Response
@ -23,7 +23,7 @@ namespace RetailCrm\Mg\Bot\Model\Response;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ErrorOnlyResponse
class ErrorOnlyResponse implements ModelInterface
{
use CommonFields;
}

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* FullFileResponse
*
@ -16,10 +16,9 @@ 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\ModelInterface;
/**
* PHP version 7.0
*
* FullFileResponse class
*
* @package RetailCrm\Mg\Bot\Model\Response
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class FullFileResponse
class FullFileResponse implements ModelInterface
{
use CommonFields;

View File

@ -1,202 +0,0 @@
<?php
/**
* PHP version 7.0
*
* ListResponse
*
* @package RetailCrm\Mg\Bot\Model\Response
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Response;
use RetailCrm\Common\Serializer;
/**
* PHP version 7.0
*
* ListResponse class. Used to store multiple objects at once.
* Implements `Iterator`, `ArrayAccess` and `Countable`.
*
* @package RetailCrm\Mg\Bot\Model\Response
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ListResponse implements \Iterator, \ArrayAccess, \Countable
{
use CommonFields;
/**
* @var array
*/
private $items = [];
/**
* @var int
*/
private $position = 0;
/**
* ListResponse constructor.
*
* @param string $responseType
* @param array $data
* @param int $statusCode
*/
public function __construct($responseType, $data, $statusCode)
{
$this->setStatusCode($statusCode);
if (isset($data['errors'])) {
$this->setErrors($data['errors']);
} else {
foreach ($data as $item) {
$this->items[] =
Serializer::deserialize($item, $responseType, Serializer::S_ARRAY);
}
}
}
/**
* @return bool
*/
public function isSuccessful()
{
return empty($this->errors);
}
/**
* \Countable implementation
*
* @return int
*/
public function count(): int
{
return count($this->items ?: []);
}
/**
* Set offset
*
* @param mixed $offset offset value
* @param mixed $value value
*
* @return void
* @internal
*/
public function offsetSet($offset, $value)
{
throw new \BadMethodCallException(
"This call not allowed: offsetSet [$offset] [$value]"
);
}
/**
* Unset offset
*
* @param mixed $offset offset value
*
* @return void
* @internal
*/
public function offsetUnset($offset)
{
throw new \BadMethodCallException(
"This call not allowed: offsetSet [$offset]"
);
}
/**
* Check offset
*
* @param mixed $offset offset value
*
* @return bool
* @internal
*/
public function offsetExists($offset)
{
return isset($this->items[$offset]);
}
/**
* Get offset
*
* @param mixed $offset offset value
*
* @return mixed
* @internal
*/
public function offsetGet($offset)
{
if (!isset($this->items[$offset])) {
throw new \InvalidArgumentException("Item \"$offset\" not found");
}
return $this->items[$offset];
}
/**
* @param mixed $name
*
* @return mixed
* @internal
*/
public function __get($name)
{
return $this->items[$name];
}
/**
* Implements rewind() for Iterable
* @internal
*/
public function rewind()
{
$this->position = 0;
}
/**
* Implements current() for Iterable
*
* @internal
* @return mixed
*/
public function current()
{
return $this->items[$this->position];
}
/**
* Implements key() for Iterable
*
* @internal
* @return int|mixed
*/
public function key()
{
return $this->position;
}
/**
* Implements next() for Iterable
* @internal
*/
public function next()
{
++$this->position;
}
/**
* Implements valid() for Iterable
*
* @internal
* @return bool
*/
public function valid()
{
return isset($this->items[$this->position]);
}
}

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* MessageSendResponse
*
@ -16,10 +16,9 @@ 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\ModelInterface;
/**
* PHP version 7.0
*
* MessageSendResponse class
*
* @package RetailCrm\Mg\Bot\Model\Response
@ -27,7 +26,7 @@ use JMS\Serializer\Annotation\Type;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageSendResponse
class MessageSendResponse implements ModelInterface
{
use CommonFields;

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* UploadFileResponse
*
@ -17,10 +17,9 @@ use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\Entity\FileMeta;
use RetailCrm\Mg\Bot\Model\ModelInterface;
/**
* PHP version 7.0
*
* UploadFileResponse class
*
* @package RetailCrm\Mg\Bot\Model\Response
@ -28,7 +27,7 @@ use RetailCrm\Mg\Bot\Model\Entity\FileMeta;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class UploadFileResponse
class UploadFileResponse implements ModelInterface
{
use CommonFields;

View File

@ -0,0 +1,29 @@
<?php
/**
* PHP version 7.1
*
* CurlException
*
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Common\Exception;
use RuntimeException;
use Throwable;
/**
* Class CurlException
*
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class CurlException extends RuntimeException implements Throwable
{
}

View File

@ -1,9 +1,9 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* CurlException
* InvalidJsonException
*
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>
@ -14,10 +14,9 @@
namespace RetailCrm\Common\Exception;
use DomainException;
use Throwable;
/**
* PHP version 7.0
*
* Class InvalidJsonException
*
* @package RetailCrm\Common\Exception
@ -25,6 +24,6 @@ use DomainException;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class InvalidJsonException extends DomainException
class InvalidJsonException extends DomainException implements Throwable
{
}

View File

@ -1,9 +1,9 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* CurlException
* LimitException
*
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>
@ -14,10 +14,9 @@
namespace RetailCrm\Common\Exception;
use DomainException;
use Throwable;
/**
* PHP version 7.0
*
* Class LimitException
*
* @package RetailCrm\Common\Exception
@ -25,6 +24,6 @@ use DomainException;
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class LimitException extends DomainException
class LimitException extends DomainException implements Throwable
{
}

View File

@ -0,0 +1,28 @@
<?php
/**
* PHP version 7.1
*
* NotFoundException
*
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Common\Exception;
use DomainException;
use Throwable;
/**
* Class NotFoundException
*
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class NotFoundException extends DomainException implements Throwable
{
}

View File

@ -0,0 +1,20 @@
<?php
/**
* PHP version 7.1
*
* UnauthorizedException
*
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Common\Exception;
use DomainException;
use Throwable;
class UnauthorizedException extends DomainException implements Throwable
{
}

View File

@ -1,9 +1,9 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Register Helper
* Register
*
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
@ -19,9 +19,7 @@ use JMS\Serializer\Annotation\Type;
use Symfony\Component\Validator\Constraints as Assert;
/**
* PHP version 7.0
*
* RequestHelper class
* Class Register
*
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
@ -328,6 +326,7 @@ class Register
* Get configuration as JSON
*
* @return array|string
* @todo make exact type
*/
public function getJsonConfiguration()
{
@ -338,6 +337,7 @@ class Register
* Get configuration as array
*
* @return array|string
* @todo make exact type
*/
public function getArrayConfiguration()
{

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Serializer
*
@ -16,11 +16,11 @@ namespace RetailCrm\Common;
use JMS\Serializer\DeserializationContext;
use JMS\Serializer\SerializationContext;
use JMS\Serializer\SerializerBuilder;
use RetailCrm\Mg\Bot\Model\ModelInterface;
use RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse;
/**
* PHP version 7.0
*
* Serializer class
* Class Serializer
*
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
@ -66,7 +66,7 @@ class Serializer
* @param string $entityType
* @param string $from
*
* @return object|null
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
*/
public static function deserialize($data, $entityType, $from = self::S_JSON)
{
@ -76,16 +76,16 @@ class Serializer
switch ($from) {
case self::S_ARRAY:
$deserialized =
$serializer->fromArray(array_filter($data), self::normalizeNamespace($entityType), $context);
$deserialized = $serializer
->fromArray(array_filter($data), self::normalizeNamespace($entityType), $context);
break;
case self::S_JSON:
$deserialized =
$serializer->deserialize($data, self::normalizeNamespace($entityType), $from, $context);
$deserialized = $serializer
->deserialize($data, self::normalizeNamespace($entityType), $from, $context);
break;
}
return is_object($deserialized) ? $deserialized : null;
return $deserialized instanceof ModelInterface ? $deserialized : new ErrorOnlyResponse();
}
/**

View File

@ -1,9 +1,9 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Url handler
* Url
*
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
@ -14,9 +14,7 @@
namespace RetailCrm\Common;
/**
* PHP version 7.0
*
* Url class
* Class Url
*
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
@ -25,13 +23,6 @@ namespace RetailCrm\Common;
*/
class Url
{
/**
* This class is used to store normalizeUrl method
* which is used in Client and HttpClient to check
* trailing slash.
*/
private function __construct() {}
/**
* Check trailing slash into url
*

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 5.4
* PHP version 7.1
*
* Test case class
*
@ -22,7 +22,6 @@ use RetailCrm\Mg\Bot\Client;
/**
* Class TestCase
*
* @category RetailCrm
* @package Test
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
@ -36,7 +35,7 @@ class TestCase extends BaseCase
* @param string $url (default: null)
* @param string $key (default: null)
* @param bool $debug (default: false)
* @param array $response (default: null)
* @param array ...$response (default: null)
*
* @return Client
*/
@ -62,8 +61,8 @@ class TestCase extends BaseCase
/**
* Returns mocked GuzzleHttp response
*
* @param string|null $body
* @param int $statusCode
* @param string|null $body HTTP Body
* @param int $statusCode HTTP status code
*
* @return Response
*/
@ -93,8 +92,8 @@ class TestCase extends BaseCase
* Only file name (without extension or any other data) should be provided,
* e.g. `getJsonResponse('bots', 200)`
*
* @param string $jsonFile
* @param int $statusCode
* @param string $jsonFile mocked body
* @param int $statusCode mocked status code
*
* @return Response|null
*/
@ -120,8 +119,8 @@ class TestCase extends BaseCase
}
/**
* @param int $statusCode
* @param array ...$errors
* @param int $statusCode response code
* @param array ...$errors response errors
*
* @return Response
*/
@ -139,7 +138,7 @@ class TestCase extends BaseCase
/**
* Generate and return empty response
*
* @param int $statusCode
* @param int $statusCode HTTP status code
*
* @return Response|null
*/

View File

@ -1,7 +1,7 @@
<?php
/**
* PHP version 7.0
* PHP version 7.1
*
* Client Test
*

View File

@ -6,6 +6,7 @@
* Dialogs Test
*
* @package RetailCrm\Mg\Bot\Tests
* @category Test
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers