| @@ -76,7 +76,7 @@ | ||
| 76 | 76 | 'action' => 'create_order' | 
| 77 | 77 | ]; | 
| 78 | 78 |  		foreach (($config instanceof \carono\turbotext\ConfigAbstract ? $config->toArray() : $config) as $key => $value) { | 
| 79 | - $params[$key] = $value; | |
| 79 | + $params[$key] = $value; | |
| 80 | 80 | } | 
| 81 | 81 |  		return $this->getClient()->getContent('api', $params, 'carono\turbotext\response\OrderResponse'); | 
| 82 | 82 | } | 
| @@ -63,7 +63,7 @@ | ||
| 63 | 63 | 'action' => 'create_microtask' | 
| 64 | 64 | ]; | 
| 65 | 65 |  		foreach (($config instanceof \carono\turbotext\ConfigAbstract ? $config->toArray() : $config) as $key => $value) { | 
| 66 | - $params[$key] = $value; | |
| 66 | + $params[$key] = $value; | |
| 67 | 67 | } | 
| 68 | 68 |  		return $this->getClient()->getContent('api', $params, 'carono\turbotext\response\MicrotaskResponse'); | 
| 69 | 69 | } | 
| @@ -6,63 +6,63 @@ | ||
| 6 | 6 | |
| 7 | 7 | class Client extends ClientAbstract | 
| 8 | 8 |  { | 
| 9 | - public $apiKey; | |
| 10 | - public $url = 'www.turbotext.ru'; | |
| 11 | - public $protocol = 'http'; | |
| 12 | - public $method = 'POST'; | |
| 13 | - public $type = self::TYPE_FORM; | |
| 14 | - public $output_type = self::TYPE_JSON; | |
| 9 | + public $apiKey; | |
| 10 | + public $url = 'www.turbotext.ru'; | |
| 11 | + public $protocol = 'http'; | |
| 12 | + public $method = 'POST'; | |
| 13 | + public $type = self::TYPE_FORM; | |
| 14 | + public $output_type = self::TYPE_JSON; | |
| 15 | 15 | |
| 16 | - /** | |
| 17 | - * @param array $data | |
| 18 | - * @return array|string | |
| 19 | - */ | |
| 20 | - public function prepareData(array $data) | |
| 21 | -    { | |
| 22 | - $data = parent::prepareData($data); | |
| 23 | - $data['api_key'] = $this->apiKey; | |
| 24 | - return $data; | |
| 25 | - } | |
| 16 | + /** | |
| 17 | + * @param array $data | |
| 18 | + * @return array|string | |
| 19 | + */ | |
| 20 | + public function prepareData(array $data) | |
| 21 | +	{ | |
| 22 | + $data = parent::prepareData($data); | |
| 23 | + $data['api_key'] = $this->apiKey; | |
| 24 | + return $data; | |
| 25 | + } | |
| 26 | 26 | |
| 27 | - /** | |
| 28 | - * @param $urlRequest | |
| 29 | - * @param array $data | |
| 30 | - * @param string $responseClass | |
| 31 | - * @return mixed | |
| 32 | - */ | |
| 33 | - public function getContent($urlRequest, $data = [], $responseClass = '\carono\turbotext\Response') | |
| 34 | -    { | |
| 35 | -        try { | |
| 36 | - $content = parent::getContent($urlRequest, $data); | |
| 37 | - return self::stdClassToResponse($content, $responseClass); | |
| 38 | -        } catch (\Exception $e) { | |
| 39 | - $response = new Response(); | |
| 40 | - $response->success = false; | |
| 41 | - $response->errors = $e->getMessage(); | |
| 42 | - return $response; | |
| 43 | - } | |
| 44 | - } | |
| 27 | + /** | |
| 28 | + * @param $urlRequest | |
| 29 | + * @param array $data | |
| 30 | + * @param string $responseClass | |
| 31 | + * @return mixed | |
| 32 | + */ | |
| 33 | + public function getContent($urlRequest, $data = [], $responseClass = '\carono\turbotext\Response') | |
| 34 | +	{ | |
| 35 | +		try { | |
| 36 | + $content = parent::getContent($urlRequest, $data); | |
| 37 | + return self::stdClassToResponse($content, $responseClass); | |
| 38 | +		} catch (\Exception $e) { | |
| 39 | + $response = new Response(); | |
| 40 | + $response->success = false; | |
| 41 | + $response->errors = $e->getMessage(); | |
| 42 | + return $response; | |
| 43 | + } | |
| 44 | + } | |
| 45 | 45 | |
| 46 | - /** | |
| 47 | - * @param $stdClass | |
| 48 | - * @param $responseClass | |
| 49 | - * @return ResponseAbstract | |
| 50 | - */ | |
| 51 | - protected static function stdClassToResponse($stdClass, $responseClass) | |
| 52 | -    { | |
| 53 | - /** | |
| 54 | - * @var ResponseAbstract $response | |
| 55 | - */ | |
| 56 | - $response = new $responseClass(); | |
| 57 | -        foreach ($stdClass as $key => $value) { | |
| 58 | -            if (method_exists($response, 'getResponseClass') && ($class = $response->getResponseClass($key)) && is_array($value)) { | |
| 59 | -                foreach ($value as $item) { | |
| 60 | -                    $response->{$key}[] = self::stdClassToResponse($item, $class); | |
| 61 | - } | |
| 62 | -            } else { | |
| 63 | - $response->$key = $value; | |
| 64 | - } | |
| 65 | - } | |
| 66 | - return $response; | |
| 67 | - } | |
| 46 | + /** | |
| 47 | + * @param $stdClass | |
| 48 | + * @param $responseClass | |
| 49 | + * @return ResponseAbstract | |
| 50 | + */ | |
| 51 | + protected static function stdClassToResponse($stdClass, $responseClass) | |
| 52 | +	{ | |
| 53 | + /** | |
| 54 | + * @var ResponseAbstract $response | |
| 55 | + */ | |
| 56 | + $response = new $responseClass(); | |
| 57 | +		foreach ($stdClass as $key => $value) { | |
| 58 | +			if (method_exists($response, 'getResponseClass') && ($class = $response->getResponseClass($key)) && is_array($value)) { | |
| 59 | +				foreach ($value as $item) { | |
| 60 | +					$response->{$key}[] = self::stdClassToResponse($item, $class); | |
| 61 | + } | |
| 62 | +			} else { | |
| 63 | + $response->$key = $value; | |
| 64 | + } | |
| 65 | + } | |
| 66 | + return $response; | |
| 67 | + } | |
| 68 | 68 | } | 
| 69 | 69 | \ No newline at end of file | 
| @@ -6,22 +6,22 @@ | ||
| 6 | 6 | |
| 7 | 7 | abstract class ResponseAbstract extends ArrayObject | 
| 8 | 8 |  { | 
| 9 | - /** | |
| 10 | - * @var boolean | |
| 11 | - */ | |
| 12 | - public $success; | |
| 13 | - /** | |
| 14 | - * @var string | |
| 15 | - */ | |
| 16 | - public $errors; | |
| 9 | + /** | |
| 10 | + * @var boolean | |
| 11 | + */ | |
| 12 | + public $success; | |
| 13 | + /** | |
| 14 | + * @var string | |
| 15 | + */ | |
| 16 | + public $errors; | |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** | |
| 20 | - * @param $property | |
| 21 | - * @return mixed|null | |
| 22 | - */ | |
| 23 | - public function getResponseClass($property) | |
| 24 | -    { | |
| 25 | - return isset($this->_responseClasses[$property]) ? $this->_responseClasses[$property] : null; | |
| 26 | - } | |
| 19 | + /** | |
| 20 | + * @param $property | |
| 21 | + * @return mixed|null | |
| 22 | + */ | |
| 23 | + public function getResponseClass($property) | |
| 24 | +	{ | |
| 25 | + return isset($this->_responseClasses[$property]) ? $this->_responseClasses[$property] : null; | |
| 26 | + } | |
| 27 | 27 | } | 
| 28 | 28 | \ No newline at end of file | 
| @@ -6,23 +6,23 @@ | ||
| 6 | 6 | |
| 7 | 7 | abstract class RequestAbstract | 
| 8 | 8 |  { | 
| 9 | - protected $_client; | |
| 9 | + protected $_client; | |
| 10 | 10 | |
| 11 | - /** | |
| 12 | - * RequestAbstract constructor. | |
| 13 | - * | |
| 14 | - * @param Client|ClientAbstract $client | |
| 15 | - */ | |
| 16 | - public function __construct($client) | |
| 17 | -    { | |
| 18 | - $this->_client = $client; | |
| 19 | - } | |
| 11 | + /** | |
| 12 | + * RequestAbstract constructor. | |
| 13 | + * | |
| 14 | + * @param Client|ClientAbstract $client | |
| 15 | + */ | |
| 16 | + public function __construct($client) | |
| 17 | +	{ | |
| 18 | + $this->_client = $client; | |
| 19 | + } | |
| 20 | 20 | |
| 21 | - /** | |
| 22 | - * @return Client | |
| 23 | - */ | |
| 24 | - public function getClient() | |
| 25 | -    { | |
| 26 | - return $this->_client; | |
| 27 | - } | |
| 21 | + /** | |
| 22 | + * @return Client | |
| 23 | + */ | |
| 24 | + public function getClient() | |
| 25 | +	{ | |
| 26 | + return $this->_client; | |
| 27 | + } | |
| 28 | 28 | } | 
| 29 | 29 | \ No newline at end of file | 
| @@ -6,25 +6,25 @@ | ||
| 6 | 6 | |
| 7 | 7 | class ArrayObject extends \ArrayObject | 
| 8 | 8 |  { | 
| 9 | - /** | |
| 10 | - * ResponseAbstract constructor. | |
| 11 | - * | |
| 12 | - * @param array $input | |
| 13 | - */ | |
| 14 | - public function __construct($input = []) | |
| 15 | -    { | |
| 16 | - parent::__construct($input, self::ARRAY_AS_PROPS, "ArrayIterator"); | |
| 17 | - } | |
| 9 | + /** | |
| 10 | + * ResponseAbstract constructor. | |
| 11 | + * | |
| 12 | + * @param array $input | |
| 13 | + */ | |
| 14 | + public function __construct($input = []) | |
| 15 | +	{ | |
| 16 | + parent::__construct($input, self::ARRAY_AS_PROPS, "ArrayIterator"); | |
| 17 | + } | |
| 18 | 18 | |
| 19 | - public function toArray() | |
| 20 | -    { | |
| 21 | - $result = []; | |
| 22 | -        foreach ($this as $key => $value) { | |
| 23 | - $result[$key] = $value; | |
| 24 | - } | |
| 25 | -        foreach ((new \ReflectionClass($this))->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) { | |
| 26 | -            $result[$property->name] = $this->{$property->name}; | |
| 27 | - } | |
| 28 | - return $result; | |
| 29 | - } | |
| 19 | + public function toArray() | |
| 20 | +	{ | |
| 21 | + $result = []; | |
| 22 | +		foreach ($this as $key => $value) { | |
| 23 | + $result[$key] = $value; | |
| 24 | + } | |
| 25 | +		foreach ((new \ReflectionClass($this))->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) { | |
| 26 | +			$result[$property->name] = $this->{$property->name}; | |
| 27 | + } | |
| 28 | + return $result; | |
| 29 | + } | |
| 30 | 30 | } | 
| 31 | 31 | \ No newline at end of file | 
| @@ -7,40 +7,40 @@ | ||
| 7 | 7 | |
| 8 | 8 | class ConfigAbstract extends ClassGenerator | 
| 9 | 9 |  { | 
| 10 | - protected function formExtends() | |
| 11 | -    { | |
| 12 | - return 'carono\turbotext\ConfigAbstract'; | |
| 13 | - } | |
| 14 | - | |
| 15 | - protected function formClassName() | |
| 16 | -    { | |
| 17 | - return formClassName($this->params['name']) . 'Config'; | |
| 18 | - } | |
| 19 | - | |
| 20 | - protected function formClassNamespace() | |
| 21 | -    { | |
| 22 | - return 'carono\turbotext\config'; | |
| 23 | - } | |
| 24 | - | |
| 25 | - protected function formOutputPath() | |
| 26 | -    { | |
| 27 | - return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php'; | |
| 28 | - } | |
| 29 | - | |
| 30 | - protected function classProperties() | |
| 31 | -    { | |
| 32 | - $properties = []; | |
| 33 | -        foreach ($this->params['params'] as $param) { | |
| 34 | -            if (is_string($param)) { | |
| 35 | - continue; | |
| 36 | - } | |
| 37 | - $properties[$param['name']] = [ | |
| 38 | - 'comment' => [ | |
| 39 | - $param['description'], | |
| 40 | - '@var ' . formParamType($param['type']) | |
| 41 | - ] | |
| 42 | - ]; | |
| 43 | - } | |
| 44 | - return $properties; | |
| 45 | - } | |
| 10 | + protected function formExtends() | |
| 11 | +	{ | |
| 12 | + return 'carono\turbotext\ConfigAbstract'; | |
| 13 | + } | |
| 14 | + | |
| 15 | + protected function formClassName() | |
| 16 | +	{ | |
| 17 | + return formClassName($this->params['name']) . 'Config'; | |
| 18 | + } | |
| 19 | + | |
| 20 | + protected function formClassNamespace() | |
| 21 | +	{ | |
| 22 | + return 'carono\turbotext\config'; | |
| 23 | + } | |
| 24 | + | |
| 25 | + protected function formOutputPath() | |
| 26 | +	{ | |
| 27 | + return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php'; | |
| 28 | + } | |
| 29 | + | |
| 30 | + protected function classProperties() | |
| 31 | +	{ | |
| 32 | + $properties = []; | |
| 33 | +		foreach ($this->params['params'] as $param) { | |
| 34 | +			if (is_string($param)) { | |
| 35 | + continue; | |
| 36 | + } | |
| 37 | + $properties[$param['name']] = [ | |
| 38 | + 'comment' => [ | |
| 39 | + $param['description'], | |
| 40 | + '@var ' . formParamType($param['type']) | |
| 41 | + ] | |
| 42 | + ]; | |
| 43 | + } | |
| 44 | + return $properties; | |
| 45 | + } | |
| 46 | 46 | } | 
| 47 | 47 | \ No newline at end of file | 
| @@ -6,74 +6,74 @@ | ||
| 6 | 6 | |
| 7 | 7 | class ResponseAbstract extends ClassGenerator | 
| 8 | 8 |  { | 
| 9 | - public $properties = []; | |
| 9 | + public $properties = []; | |
| 10 | 10 | |
| 11 | - protected function formExtends() | |
| 12 | -    { | |
| 13 | -        if (strpos($this->formClassName(), 'ElementResponse')) { | |
| 14 | - return 'carono\turbotext\ArrayObject'; | |
| 15 | -        } else { | |
| 16 | - return 'carono\turbotext\ResponseAbstract'; | |
| 17 | - } | |
| 18 | - } | |
| 11 | + protected function formExtends() | |
| 12 | +	{ | |
| 13 | +		if (strpos($this->formClassName(), 'ElementResponse')) { | |
| 14 | + return 'carono\turbotext\ArrayObject'; | |
| 15 | +		} else { | |
| 16 | + return 'carono\turbotext\ResponseAbstract'; | |
| 17 | + } | |
| 18 | + } | |
| 19 | 19 | |
| 20 | - protected function formClassName() | |
| 21 | -    { | |
| 22 | - $name = $this->params['name']; | |
| 23 | - $name = formClassName($name); | |
| 24 | -        if (!isset($this->params['result']) && substr($name, -1, 1) == 's') { | |
| 25 | - $name = substr($name, 0, -1) . 'Element'; | |
| 26 | - } | |
| 27 | - return $name . 'Response'; | |
| 28 | - } | |
| 20 | + protected function formClassName() | |
| 21 | +	{ | |
| 22 | + $name = $this->params['name']; | |
| 23 | + $name = formClassName($name); | |
| 24 | +		if (!isset($this->params['result']) && substr($name, -1, 1) == 's') { | |
| 25 | + $name = substr($name, 0, -1) . 'Element'; | |
| 26 | + } | |
| 27 | + return $name . 'Response'; | |
| 28 | + } | |
| 29 | 29 | |
| 30 | - protected function formClassNamespace() | |
| 31 | -    { | |
| 32 | - return 'carono\turbotext\response'; | |
| 33 | - } | |
| 30 | + protected function formClassNamespace() | |
| 31 | +	{ | |
| 32 | + return 'carono\turbotext\response'; | |
| 33 | + } | |
| 34 | 34 | |
| 35 | - protected function formOutputPath() | |
| 36 | -    { | |
| 37 | - return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'response' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php'; | |
| 38 | - } | |
| 35 | + protected function formOutputPath() | |
| 36 | +	{ | |
| 37 | + return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'response' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php'; | |
| 38 | + } | |
| 39 | 39 | |
| 40 | - protected function classProperties() | |
| 41 | -    { | |
| 42 | - $properties = []; | |
| 43 | -        if (isset($this->params['result'])) { | |
| 44 | - $properties = [ | |
| 45 | - '_responseClasses' => [ | |
| 46 | - 'value' => [], | |
| 47 | - 'visibility' => 'protected' | |
| 48 | - ] | |
| 49 | - ]; | |
| 50 | - $element = new self(); | |
| 51 | - $params = $this->params['result']; | |
| 52 | - $params['name'] = $this->params['name']; | |
| 53 | - $element->renderToFile($params); | |
| 54 | - $varClass = $element->formClassName(); | |
| 55 | - $properties['_responseClasses']['value'][$this->params['name']] = 'carono\turbotext\response\\' . $varClass; | |
| 56 | - $properties[$this->params['name']] = [ | |
| 57 | - 'value' => [], | |
| 58 | - 'comment' => [ | |
| 59 | - $this->params['description'], | |
| 60 | -                    "@var {$varClass}[]" | |
| 61 | - ] | |
| 62 | - ]; | |
| 63 | -        } else { | |
| 64 | -            foreach ($this->params as $param) { | |
| 65 | -                if (is_string($param)) { | |
| 66 | - continue; | |
| 67 | - } | |
| 68 | - $properties[$param['name']] = [ | |
| 69 | - 'comment' => [ | |
| 70 | - $param['description'], | |
| 71 | - '@var ' . formParamType($param['type']) | |
| 72 | - ] | |
| 73 | - ]; | |
| 74 | - } | |
| 75 | - } | |
| 76 | - return $properties; | |
| 77 | - } | |
| 40 | + protected function classProperties() | |
| 41 | +	{ | |
| 42 | + $properties = []; | |
| 43 | +		if (isset($this->params['result'])) { | |
| 44 | + $properties = [ | |
| 45 | + '_responseClasses' => [ | |
| 46 | + 'value' => [], | |
| 47 | + 'visibility' => 'protected' | |
| 48 | + ] | |
| 49 | + ]; | |
| 50 | + $element = new self(); | |
| 51 | + $params = $this->params['result']; | |
| 52 | + $params['name'] = $this->params['name']; | |
| 53 | + $element->renderToFile($params); | |
| 54 | + $varClass = $element->formClassName(); | |
| 55 | + $properties['_responseClasses']['value'][$this->params['name']] = 'carono\turbotext\response\\' . $varClass; | |
| 56 | + $properties[$this->params['name']] = [ | |
| 57 | + 'value' => [], | |
| 58 | + 'comment' => [ | |
| 59 | + $this->params['description'], | |
| 60 | +					"@var {$varClass}[]" | |
| 61 | + ] | |
| 62 | + ]; | |
| 63 | +		} else { | |
| 64 | +			foreach ($this->params as $param) { | |
| 65 | +				if (is_string($param)) { | |
| 66 | + continue; | |
| 67 | + } | |
| 68 | + $properties[$param['name']] = [ | |
| 69 | + 'comment' => [ | |
| 70 | + $param['description'], | |
| 71 | + '@var ' . formParamType($param['type']) | |
| 72 | + ] | |
| 73 | + ]; | |
| 74 | + } | |
| 75 | + } | |
| 76 | + return $properties; | |
| 77 | + } | |
| 78 | 78 | |
| 79 | 79 | } | 
| 80 | 80 | \ No newline at end of file | 
| @@ -6,42 +6,42 @@ | ||
| 6 | 6 | |
| 7 | 7 | class ClientAbstract extends ClassGenerator | 
| 8 | 8 |  { | 
| 9 | - protected function formExtends() | |
| 10 | -    { | |
| 11 | - return 'carono\rest\Client'; | |
| 12 | - } | |
| 9 | + protected function formExtends() | |
| 10 | +	{ | |
| 11 | + return 'carono\rest\Client'; | |
| 12 | + } | |
| 13 | 13 | |
| 14 | - protected function formClassName() | |
| 15 | -    { | |
| 16 | - return 'ClientAbstract'; | |
| 17 | - } | |
| 14 | + protected function formClassName() | |
| 15 | +	{ | |
| 16 | + return 'ClientAbstract'; | |
| 17 | + } | |
| 18 | 18 | |
| 19 | - protected function formClassNamespace() | |
| 20 | -    { | |
| 21 | - return 'carono\turbotext'; | |
| 22 | - } | |
| 19 | + protected function formClassNamespace() | |
| 20 | +	{ | |
| 21 | + return 'carono\turbotext'; | |
| 22 | + } | |
| 23 | 23 | |
| 24 | - protected function formOutputPath() | |
| 25 | -    { | |
| 26 | - return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php'; | |
| 27 | - } | |
| 24 | + protected function formOutputPath() | |
| 25 | +	{ | |
| 26 | + return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php'; | |
| 27 | + } | |
| 28 | 28 | |
| 29 | - public function methods() | |
| 30 | -    { | |
| 31 | - $this->phpClass->setAbstract(true); | |
| 32 | -        foreach ($this->params as $section) { | |
| 33 | - $sectionRequest = new RequestAbstract(); | |
| 34 | - $sectionRequest->renderToFile($section); | |
| 35 | - $className = "\\" . $sectionRequest->formClassNamespace() . "\\" . $sectionRequest->formClassName(); | |
| 36 | - $method = $this->phpClass->addMethod($section['name']); | |
| 37 | - $body = <<<PHP | |
| 29 | + public function methods() | |
| 30 | +	{ | |
| 31 | + $this->phpClass->setAbstract(true); | |
| 32 | +		foreach ($this->params as $section) { | |
| 33 | + $sectionRequest = new RequestAbstract(); | |
| 34 | + $sectionRequest->renderToFile($section); | |
| 35 | + $className = "\\" . $sectionRequest->formClassNamespace() . "\\" . $sectionRequest->formClassName(); | |
| 36 | + $method = $this->phpClass->addMethod($section['name']); | |
| 37 | + $body = <<<PHP | |
| 38 | 38 | return (new $className(\$this)); | 
| 39 | 39 | PHP; | 
| 40 | - $method->addBody($body); | |
| 41 | - $method->addComment($section['description']); | |
| 42 | -            $method->addComment(""); | |
| 43 | -            $method->addComment("@return $className"); | |
| 44 | - } | |
| 45 | - return false; | |
| 46 | - } | |
| 40 | + $method->addBody($body); | |
| 41 | + $method->addComment($section['description']); | |
| 42 | +			$method->addComment(""); | |
| 43 | +			$method->addComment("@return $className"); | |
| 44 | + } | |
| 45 | + return false; | |
| 46 | + } | |
| 47 | 47 | } | 
| 48 | 48 | \ No newline at end of file |