move validator call to Request
This commit is contained in:
parent
c5a92a0853
commit
c43b5cf194
5 changed files with 41 additions and 56 deletions
|
@ -1,3 +1,7 @@
|
|||
<<<<<<< HEAD
|
||||
MG_BOT_URL="https://mg-test.retailcrm.pro/"
|
||||
=======
|
||||
MG_BOT_URL=""
|
||||
>>>>>>> b8db7fa... move validator call to Request
|
||||
MG_BOT_KEY=""
|
||||
MG_BOT_DBG=""
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.0
|
||||
*
|
||||
* Validator
|
||||
*
|
||||
* @package RetailCrm\Mg\Bot\Component
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://help.retailcrm.pro/docs/Developers
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Mg\Bot\Component;
|
||||
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* PHP version 7.0
|
||||
*
|
||||
* Validator class
|
||||
*
|
||||
* @package RetailCrm\Mg\Bot\Component
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://help.retailcrm.pro/docs/Developers
|
||||
*/
|
||||
class Validator
|
||||
{
|
||||
/**
|
||||
* Validate given class
|
||||
*
|
||||
* @param $class
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function validate($class)
|
||||
{
|
||||
$errorsString = '';
|
||||
|
||||
$validator = Validation::createValidatorBuilder()
|
||||
->addMethodMapping('loadValidatorMetadata')
|
||||
->getValidator();
|
||||
|
||||
$errors = $validator->validate($class);
|
||||
|
||||
if (count($errors) > 0) {
|
||||
$errorsString = (string) $errors;
|
||||
}
|
||||
|
||||
return $errorsString;
|
||||
}
|
||||
}
|
|
@ -33,7 +33,7 @@ class IntegrationHelper
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public static function moduleRequest(array $config, string $clientId): array
|
||||
public static function moduleRequest(array $config, string $clientId)
|
||||
{
|
||||
$config['host'] = str_replace("https://", '', $config['host']);
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ use RetailCrm\Common\Exception\CurlException;
|
|||
use RetailCrm\Common\Exception\LimitException;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* PHP version 7.0
|
||||
|
@ -77,10 +78,13 @@ class Request
|
|||
public function makeRequest($path, $method, $request = null, $serializeTo = self::S_JSON)
|
||||
{
|
||||
$this->validateMethod($method);
|
||||
$this->validateRequest($request);
|
||||
|
||||
$parameters = $this->serialize($request, $serializeTo);
|
||||
$url = $this->buildUrl($path, $method, $parameters);
|
||||
|
||||
var_dump($url);
|
||||
|
||||
$curlHandler = curl_init();
|
||||
curl_setopt($curlHandler, CURLOPT_URL, $url);
|
||||
curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1);
|
||||
|
@ -167,6 +171,27 @@ class Request
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate given class
|
||||
*
|
||||
* @param string $class
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function validateRequest($class)
|
||||
{
|
||||
$validator = Validation::createValidatorBuilder()
|
||||
->addMethodMapping('loadValidatorMetadata')
|
||||
->getValidator();
|
||||
|
||||
$errors = $validator->validate($class);
|
||||
|
||||
if ($errors->count() > 0) {
|
||||
$message = (string) $errors;
|
||||
throw new InvalidArgumentException($message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize given object to JSON or Array
|
||||
*
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
namespace RetailCrm\Mg\Bot\Tests;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use RetailCrm\Mg\Bot\Client;
|
||||
use RetailCrm\Mg\Bot\Model\Request\ChannelsRequest;
|
||||
use RetailCrm\Mg\Bot\Model\Request\CommandEditRequest;
|
||||
use RetailCrm\Mg\Bot\Test\TestCase;
|
||||
|
||||
|
@ -33,10 +33,19 @@ class ClientTest extends TestCase
|
|||
|
||||
/**
|
||||
* @group("list")
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testChannels()
|
||||
{
|
||||
self::assertTrue(1 == 1);
|
||||
$client = self::getApiClient();
|
||||
$request = new ChannelsRequest();
|
||||
$request->setActive(true);
|
||||
$request->setTypes(['viber']);
|
||||
$channels = $client->channels($request);
|
||||
|
||||
var_dump($channels->getResponse());
|
||||
|
||||
self::assertTrue($channels->isSuccessful() == true);
|
||||
}
|
||||
|
||||
public function testChats()
|
||||
|
|
Loading…
Add table
Reference in a new issue