custom autoloader for annotations, move constraints to annotations
This commit is contained in:
parent
b8db7faf0d
commit
114e02ab72
7 changed files with 188 additions and 107 deletions
|
@ -34,7 +34,8 @@
|
|||
"psr-4": {
|
||||
"RetailCrm\\Mg\\": ["src/", "tests/"],
|
||||
"RetailCrm\\Common\\": "src/"
|
||||
}
|
||||
},
|
||||
"files": ["extra/autoloader.php"]
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
|
|
211
composer.lock
generated
211
composer.lock
generated
|
@ -908,39 +908,36 @@
|
|||
},
|
||||
{
|
||||
"name": "nette/bootstrap",
|
||||
"version": "v2.4.6",
|
||||
"version": "v3.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nette/bootstrap.git",
|
||||
"reference": "268816e3f1bb7426c3a4ceec2bd38a036b532543"
|
||||
"reference": "e1075af05c211915e03e0c86542f3ba5433df4a3"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/nette/bootstrap/zipball/268816e3f1bb7426c3a4ceec2bd38a036b532543",
|
||||
"reference": "268816e3f1bb7426c3a4ceec2bd38a036b532543",
|
||||
"url": "https://api.github.com/repos/nette/bootstrap/zipball/e1075af05c211915e03e0c86542f3ba5433df4a3",
|
||||
"reference": "e1075af05c211915e03e0c86542f3ba5433df4a3",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"nette/di": "~2.4.7",
|
||||
"nette/utils": "~2.4",
|
||||
"php": ">=5.6.0"
|
||||
},
|
||||
"conflict": {
|
||||
"nette/nette": "<2.2"
|
||||
"nette/di": "^3.0",
|
||||
"nette/utils": "^3.0",
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"latte/latte": "~2.2",
|
||||
"nette/application": "~2.3",
|
||||
"nette/caching": "~2.3",
|
||||
"nette/database": "~2.3",
|
||||
"nette/forms": "~2.3",
|
||||
"nette/http": "~2.4.0",
|
||||
"nette/mail": "~2.3",
|
||||
"nette/robot-loader": "^2.4.2 || ^3.0",
|
||||
"nette/safe-stream": "~2.2",
|
||||
"nette/security": "~2.3",
|
||||
"nette/tester": "~2.0",
|
||||
"tracy/tracy": "^2.4.1"
|
||||
"latte/latte": "^2.2",
|
||||
"nette/application": "^3.0",
|
||||
"nette/caching": "^3.0",
|
||||
"nette/database": "^3.0",
|
||||
"nette/forms": "^3.0",
|
||||
"nette/http": "^3.0",
|
||||
"nette/mail": "^3.0",
|
||||
"nette/robot-loader": "^3.0",
|
||||
"nette/safe-stream": "^2.2",
|
||||
"nette/security": "^3.0",
|
||||
"nette/tester": "^2.0",
|
||||
"tracy/tracy": "^2.6"
|
||||
},
|
||||
"suggest": {
|
||||
"nette/robot-loader": "to use Configurator::createRobotLoader()",
|
||||
|
@ -949,7 +946,7 @@
|
|||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.4-dev"
|
||||
"dev-master": "3.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
|
@ -973,53 +970,57 @@
|
|||
"homepage": "https://nette.org/contributors"
|
||||
}
|
||||
],
|
||||
"description": "? Nette Bootstrap: the simple way to configure and bootstrap your Nette application.",
|
||||
"description": "🅱 Nette Bootstrap: the simple way to configure and bootstrap your Nette application.",
|
||||
"homepage": "https://nette.org",
|
||||
"keywords": [
|
||||
"bootstrapping",
|
||||
"configurator",
|
||||
"nette"
|
||||
],
|
||||
"time": "2018-05-17T12:52:20+00:00"
|
||||
"time": "2019-03-26T12:59:07+00:00"
|
||||
},
|
||||
{
|
||||
"name": "nette/di",
|
||||
"version": "v2.4.15",
|
||||
"version": "v3.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nette/di.git",
|
||||
"reference": "d0561b8f77e8ef2ed6d83328860e16c81a5a8649"
|
||||
"reference": "19d83539245aaacb59470828919182411061841f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/nette/di/zipball/d0561b8f77e8ef2ed6d83328860e16c81a5a8649",
|
||||
"reference": "d0561b8f77e8ef2ed6d83328860e16c81a5a8649",
|
||||
"url": "https://api.github.com/repos/nette/di/zipball/19d83539245aaacb59470828919182411061841f",
|
||||
"reference": "19d83539245aaacb59470828919182411061841f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-tokenizer": "*",
|
||||
"nette/neon": "^2.3.3 || ~3.0.0",
|
||||
"nette/php-generator": "^2.6.1 || ^3.0.0",
|
||||
"nette/utils": "^2.5.0 || ~3.0.0",
|
||||
"php": ">=5.6.0"
|
||||
"nette/neon": "^3.0",
|
||||
"nette/php-generator": "^3.2.2",
|
||||
"nette/robot-loader": "^3.2",
|
||||
"nette/schema": "^1.0",
|
||||
"nette/utils": "^3.0",
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"conflict": {
|
||||
"nette/bootstrap": "<2.4",
|
||||
"nette/nette": "<2.2"
|
||||
"nette/bootstrap": "<3.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"nette/tester": "^2.0",
|
||||
"nette/tester": "^2.2",
|
||||
"tracy/tracy": "^2.3"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.4-dev"
|
||||
"dev-master": "3.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"src/"
|
||||
],
|
||||
"files": [
|
||||
"src/compatibility.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
|
@ -1038,7 +1039,7 @@
|
|||
"homepage": "https://nette.org/contributors"
|
||||
}
|
||||
],
|
||||
"description": "? Nette Dependency Injection Container: Flexible, compiled and full-featured DIC with perfectly usable autowiring and support for all new PHP 7.1 features.",
|
||||
"description": "💎 Nette Dependency Injection Container: Flexible, compiled and full-featured DIC with perfectly usable autowiring and support for all new PHP 7.1 features.",
|
||||
"homepage": "https://nette.org",
|
||||
"keywords": [
|
||||
"compiled",
|
||||
|
@ -1049,7 +1050,7 @@
|
|||
"nette",
|
||||
"static"
|
||||
],
|
||||
"time": "2019-01-30T13:26:05+00:00"
|
||||
"time": "2019-04-03T19:35:46+00:00"
|
||||
},
|
||||
{
|
||||
"name": "nette/finder",
|
||||
|
@ -1235,26 +1236,23 @@
|
|||
},
|
||||
{
|
||||
"name": "nette/robot-loader",
|
||||
"version": "v3.1.1",
|
||||
"version": "v3.2.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nette/robot-loader.git",
|
||||
"reference": "3e8d75d6d976e191bdf46752ca40a286671219d2"
|
||||
"reference": "0712a0e39ae7956d6a94c0ab6ad41aa842544b5c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/nette/robot-loader/zipball/3e8d75d6d976e191bdf46752ca40a286671219d2",
|
||||
"reference": "3e8d75d6d976e191bdf46752ca40a286671219d2",
|
||||
"url": "https://api.github.com/repos/nette/robot-loader/zipball/0712a0e39ae7956d6a94c0ab6ad41aa842544b5c",
|
||||
"reference": "0712a0e39ae7956d6a94c0ab6ad41aa842544b5c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-tokenizer": "*",
|
||||
"nette/finder": "^2.3 || ^3.0",
|
||||
"nette/utils": "^2.4 || ^3.0",
|
||||
"php": ">=5.6.0"
|
||||
},
|
||||
"conflict": {
|
||||
"nette/nette": "<2.2"
|
||||
"nette/finder": "^2.5",
|
||||
"nette/utils": "^3.0",
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"nette/tester": "^2.0",
|
||||
|
@ -1263,7 +1261,7 @@
|
|||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "3.1-dev"
|
||||
"dev-master": "3.2-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
|
@ -1296,52 +1294,39 @@
|
|||
"nette",
|
||||
"trait"
|
||||
],
|
||||
"time": "2019-03-01T20:23:02+00:00"
|
||||
"time": "2019-03-08T21:57:24+00:00"
|
||||
},
|
||||
{
|
||||
"name": "nette/utils",
|
||||
"version": "v2.5.3",
|
||||
"name": "nette/schema",
|
||||
"version": "v1.0.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nette/utils.git",
|
||||
"reference": "17b9f76f2abd0c943adfb556e56f2165460b15ce"
|
||||
"url": "https://github.com/nette/schema.git",
|
||||
"reference": "6241d8d4da39e825dd6cb5bfbe4242912f4d7e4d"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/nette/utils/zipball/17b9f76f2abd0c943adfb556e56f2165460b15ce",
|
||||
"reference": "17b9f76f2abd0c943adfb556e56f2165460b15ce",
|
||||
"url": "https://api.github.com/repos/nette/schema/zipball/6241d8d4da39e825dd6cb5bfbe4242912f4d7e4d",
|
||||
"reference": "6241d8d4da39e825dd6cb5bfbe4242912f4d7e4d",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.6.0"
|
||||
},
|
||||
"conflict": {
|
||||
"nette/nette": "<2.2"
|
||||
"nette/utils": "^3.0.1",
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"nette/tester": "~2.0",
|
||||
"nette/tester": "^2.2",
|
||||
"tracy/tracy": "^2.3"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-gd": "to use Image",
|
||||
"ext-iconv": "to use Strings::webalize() and toAscii()",
|
||||
"ext-intl": "for script transliteration in Strings::webalize() and toAscii()",
|
||||
"ext-json": "to use Nette\\Utils\\Json",
|
||||
"ext-mbstring": "to use Strings::lower() etc...",
|
||||
"ext-xml": "to use Strings::length() etc. when mbstring is not available"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.5-dev"
|
||||
"dev-master": "1.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"src/"
|
||||
],
|
||||
"files": [
|
||||
"src/loader.php"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
|
@ -1360,7 +1345,71 @@
|
|||
"homepage": "https://nette.org/contributors"
|
||||
}
|
||||
],
|
||||
"description": "? Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.",
|
||||
"description": "📐 Nette Schema: validating data structures against a given Schema.",
|
||||
"homepage": "https://nette.org",
|
||||
"keywords": [
|
||||
"config",
|
||||
"nette"
|
||||
],
|
||||
"time": "2019-04-03T15:53:25+00:00"
|
||||
},
|
||||
{
|
||||
"name": "nette/utils",
|
||||
"version": "v3.0.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nette/utils.git",
|
||||
"reference": "bd961f49b211997202bda1d0fbc410905be370d4"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/nette/utils/zipball/bd961f49b211997202bda1d0fbc410905be370d4",
|
||||
"reference": "bd961f49b211997202bda1d0fbc410905be370d4",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"nette/tester": "~2.0",
|
||||
"tracy/tracy": "^2.3"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-gd": "to use Image",
|
||||
"ext-iconv": "to use Strings::webalize() and toAscii()",
|
||||
"ext-intl": "to use Strings::webalize(), toAscii(), normalize() and compare()",
|
||||
"ext-json": "to use Nette\\Utils\\Json",
|
||||
"ext-mbstring": "to use Strings::lower() etc...",
|
||||
"ext-xml": "to use Strings::length() etc. when mbstring is not available"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "3.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"src/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"BSD-3-Clause",
|
||||
"GPL-2.0",
|
||||
"GPL-3.0"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "David Grudl",
|
||||
"homepage": "https://davidgrudl.com"
|
||||
},
|
||||
{
|
||||
"name": "Nette Community",
|
||||
"homepage": "https://nette.org/contributors"
|
||||
}
|
||||
],
|
||||
"description": "🛠 Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.",
|
||||
"homepage": "https://nette.org",
|
||||
"keywords": [
|
||||
"array",
|
||||
|
@ -1378,7 +1427,7 @@
|
|||
"utility",
|
||||
"validation"
|
||||
],
|
||||
"time": "2018-09-18T10:22:16+00:00"
|
||||
"time": "2019-03-22T01:00:30+00:00"
|
||||
},
|
||||
{
|
||||
"name": "nikic/php-parser",
|
||||
|
@ -3430,16 +3479,16 @@
|
|||
},
|
||||
{
|
||||
"name": "theseer/tokenizer",
|
||||
"version": "1.1.0",
|
||||
"version": "1.1.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/theseer/tokenizer.git",
|
||||
"reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b"
|
||||
"reference": "1c42705be2b6c1de5904f8afacef5895cab44bf8"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/theseer/tokenizer/zipball/cb2f008f3f05af2893a87208fe6a6c4985483f8b",
|
||||
"reference": "cb2f008f3f05af2893a87208fe6a6c4985483f8b",
|
||||
"url": "https://api.github.com/repos/theseer/tokenizer/zipball/1c42705be2b6c1de5904f8afacef5895cab44bf8",
|
||||
"reference": "1c42705be2b6c1de5904f8afacef5895cab44bf8",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
|
@ -3466,7 +3515,7 @@
|
|||
}
|
||||
],
|
||||
"description": "A small library for converting tokenized PHP source code into XML and potentially other formats",
|
||||
"time": "2017-04-07T12:08:54+00:00"
|
||||
"time": "2019-04-04T09:56:43+00:00"
|
||||
},
|
||||
{
|
||||
"name": "webmozart/assert",
|
||||
|
|
14
extra/autoloader.php
Normal file
14
extra/autoloader.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
// autoload.php
|
||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||
use Composer\Autoload\ClassLoader;
|
||||
|
||||
/**
|
||||
* @var ClassLoader $loader
|
||||
*/
|
||||
$loader = require __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
AnnotationRegistry::registerLoader('class_exists');
|
||||
|
||||
return $loader;
|
|
@ -46,11 +46,11 @@ class BotsRequest
|
|||
private $self;
|
||||
|
||||
/**
|
||||
* @Type("string")
|
||||
* @Accessor(getter="getRole",setter="setRole")
|
||||
* @Type("array")
|
||||
* @Accessor(getter="getRoles",setter="setRoles")
|
||||
* @SkipWhenEmpty
|
||||
*/
|
||||
private $role;
|
||||
private $roles;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
|
@ -85,18 +85,18 @@ class BotsRequest
|
|||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @return array
|
||||
*/
|
||||
public function getRole()
|
||||
public function getRoles()
|
||||
{
|
||||
return $this->role;
|
||||
return $this->roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $role
|
||||
* @param array $roles
|
||||
*/
|
||||
public function setRole($role)
|
||||
public function setRoles($roles)
|
||||
{
|
||||
$this->role = $role;
|
||||
$this->roles = $roles;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ class CommandEditRequest
|
|||
* @Type("string")
|
||||
* @Accessor(getter="getName",setter="setName")
|
||||
* @SkipWhenEmpty
|
||||
* @Assert\NotBlank
|
||||
*/
|
||||
private $name;
|
||||
|
||||
|
@ -80,12 +81,4 @@ class CommandEditRequest
|
|||
{
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Symfony\Component\Validator\Mapping\ClassMetadata $metadata
|
||||
*/
|
||||
public static function loadValidatorMetadata(ClassMetadata $metadata)
|
||||
{
|
||||
$metadata->addPropertyConstraint('name', new Assert\NotBlank());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,8 +83,6 @@ class 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);
|
||||
|
@ -181,7 +179,7 @@ class Request
|
|||
private function validateRequest($class)
|
||||
{
|
||||
$validator = Validation::createValidatorBuilder()
|
||||
->addMethodMapping('loadValidatorMetadata')
|
||||
->enableAnnotationMapping()
|
||||
->getValidator();
|
||||
|
||||
$errors = $validator->validate($class);
|
||||
|
@ -206,7 +204,8 @@ class Request
|
|||
|
||||
switch ($serialize) {
|
||||
case self::S_ARRAY:
|
||||
$serialized = (array)$request;
|
||||
$serializer = SerializerBuilder::create()->build();
|
||||
$serialized = $serializer->toArray($request);
|
||||
break;
|
||||
case self::S_JSON:
|
||||
$serializer = SerializerBuilder::create()->build();
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
namespace RetailCrm\Mg\Bot\Tests;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use RetailCrm\Mg\Bot\Model\Constants;
|
||||
use RetailCrm\Mg\Bot\Model\Request\BotsRequest;
|
||||
use RetailCrm\Mg\Bot\Model\Request\ChannelsRequest;
|
||||
use RetailCrm\Mg\Bot\Model\Request\CommandEditRequest;
|
||||
use RetailCrm\Mg\Bot\Test\TestCase;
|
||||
|
@ -40,11 +42,9 @@ class ClientTest extends TestCase
|
|||
$client = self::getApiClient();
|
||||
$request = new ChannelsRequest();
|
||||
$request->setActive(true);
|
||||
$request->setTypes(['viber']);
|
||||
$request->setTypes([Constants::CHANNEL_TYPE_FACEBOOK]);
|
||||
$channels = $client->channels($request);
|
||||
|
||||
var_dump($channels->getResponse());
|
||||
|
||||
self::assertTrue($channels->isSuccessful() == true);
|
||||
}
|
||||
|
||||
|
@ -68,6 +68,9 @@ class ClientTest extends TestCase
|
|||
self::assertTrue(1 == 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testCommandEditException()
|
||||
{
|
||||
self::expectException(InvalidArgumentException::class);
|
||||
|
@ -79,9 +82,31 @@ class ClientTest extends TestCase
|
|||
$client->commandEdit($command);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testCommandDeleteException()
|
||||
{
|
||||
self::expectException(\Exception::class);
|
||||
|
||||
$client = self::getApiClient();
|
||||
$command = "qwerty";
|
||||
|
||||
$client->commandDelete($command);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testBots()
|
||||
{
|
||||
self::assertTrue(1 == 1);
|
||||
$client = self::getApiClient();
|
||||
$request = new BotsRequest();
|
||||
$request->setActive(1);
|
||||
$request->setRoles([Constants::BOT_ROLE_RESPONSIBLE]);
|
||||
$bots = $client->bots($request);
|
||||
|
||||
self::assertTrue($bots->isSuccessful() == true);
|
||||
}
|
||||
|
||||
public function testUsers()
|
||||
|
|
Loading…
Add table
Reference in a new issue