| @@ -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 | 
| @@ -46,55 +46,55 @@ | ||
| 46 | 46 | HTML; | 
| 47 | 47 | |
| 48 | 48 | $description = [ | 
| 49 | - ['Метод', 'Описание'] | |
| 49 | + ['Метод', 'Описание'] | |
| 50 | 50 | ]; | 
| 51 | 51 | $sectionData = []; | 
| 52 | 52 |  foreach ($data as $section) { | 
| 53 | - $description[] = [ | |
| 54 | - '$client->' . $section['name'] . '()', | |
| 55 | - $section['description'] | |
| 56 | - ]; | |
| 57 | - $sectionData[] = asHeader($section['description']); | |
| 58 | - $sectionData[] = <<<HTML | |
| 53 | + $description[] = [ | |
| 54 | + '$client->' . $section['name'] . '()', | |
| 55 | + $section['description'] | |
| 56 | + ]; | |
| 57 | + $sectionData[] = asHeader($section['description']); | |
| 58 | + $sectionData[] = <<<HTML | |
| 59 | 59 | ```php | 
| 60 | 60 |  \$client->{$section['name']}(); | 
| 61 | 61 | ``` | 
| 62 | 62 | HTML; | 
| 63 | 63 | |
| 64 | - $methods = [ | |
| 65 | - ['Метод', 'Описание', 'Входные данные', 'Выходные данные'] | |
| 66 | - ]; | |
| 64 | + $methods = [ | |
| 65 | + ['Метод', 'Описание', 'Входные данные', 'Выходные данные'] | |
| 66 | + ]; | |
| 67 | 67 | |
| 68 | -    foreach ($section['methods'] as $method) { | |
| 69 | - $results = []; | |
| 70 | - $params = []; | |
| 71 | -        foreach ($method['returns'] as $result) { | |
| 72 | - $results[] = formParamLine($result); | |
| 73 | -            if (isset($result['result'])) { | |
| 74 | -                foreach ($result['result'] as $res) { | |
| 75 | - $results[] = formParamLine($res); | |
| 76 | - } | |
| 77 | - } | |
| 78 | - } | |
| 79 | -        if (isset($method['params'])) { | |
| 80 | -            foreach ($method['params'] as $param) { | |
| 81 | -                $params[] = '**' . $param['name'] . "** ({$param['type']}) - " . stripLines($param['description']); | |
| 82 | - } | |
| 83 | - } | |
| 68 | +	foreach ($section['methods'] as $method) { | |
| 69 | + $results = []; | |
| 70 | + $params = []; | |
| 71 | +		foreach ($method['returns'] as $result) { | |
| 72 | + $results[] = formParamLine($result); | |
| 73 | +			if (isset($result['result'])) { | |
| 74 | +				foreach ($result['result'] as $res) { | |
| 75 | + $results[] = formParamLine($res); | |
| 76 | + } | |
| 77 | + } | |
| 78 | + } | |
| 79 | +		if (isset($method['params'])) { | |
| 80 | +			foreach ($method['params'] as $param) { | |
| 81 | +				$params[] = '**' . $param['name'] . "** ({$param['type']}) - " . stripLines($param['description']); | |
| 82 | + } | |
| 83 | + } | |
| 84 | 84 | |
| 85 | - $methods[] = [ | |
| 86 | - formMethodName($method['name']), | |
| 87 | - stripLines($method['description']), | |
| 88 | -            join('<br /><br />', $params), | |
| 89 | -            join('<br /><br />', $results), | |
| 90 | - ]; | |
| 91 | - } | |
| 92 | - $sectionData[] = asTable($methods); | |
| 85 | + $methods[] = [ | |
| 86 | + formMethodName($method['name']), | |
| 87 | + stripLines($method['description']), | |
| 88 | +			join('<br /><br />', $params), | |
| 89 | +			join('<br /><br />', $results), | |
| 90 | + ]; | |
| 91 | + } | |
| 92 | + $sectionData[] = asTable($methods); | |
| 93 | 93 | } | 
| 94 | 94 | $content .= asTable($description); | 
| 95 | 95 | |
| 96 | 96 |  foreach ($sectionData as $sectionDatum) { | 
| 97 | - $content .= $sectionDatum; | |
| 97 | + $content .= $sectionDatum; | |
| 98 | 98 | } | 
| 99 | 99 | |
| 100 | 100 |  $content .= asHeader('Внимание'); | 
| @@ -66,7 +66,7 @@ | ||
| 66 | 66 | 'action' => 'create_microtask' | 
| 67 | 67 | ]; | 
| 68 | 68 |  		foreach (($config instanceof \carono\turbotext\ConfigAbstract ? $config->toArray() : $config) as $key => $value) { | 
| 69 | - $params[$key] = $value; | |
| 69 | + $params[$key] = $value; | |
| 70 | 70 | } | 
| 71 | 71 |  		return $this->getClient()->getContent('api', $params, 'carono\turbotext\response\CreateMicrotaskResponse'); | 
| 72 | 72 | } | 
| @@ -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'], ['get_', '_array', 'create_']) . '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 | - stripAndWordWrap(stripSpaces($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'], ['get_', '_array', 'create_']) . '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 | + stripAndWordWrap(stripSpaces($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,66 +6,66 @@ | ||
| 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 | -        if (isset($response->success)) { | |
| 67 | - $response->success = filter_var($response->success, FILTER_VALIDATE_BOOLEAN); | |
| 68 | - } | |
| 69 | - return $response; | |
| 70 | - } | |
| 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 | +		if (isset($response->success)) { | |
| 67 | + $response->success = filter_var($response->success, FILTER_VALIDATE_BOOLEAN); | |
| 68 | + } | |
| 69 | + return $response; | |
| 70 | + } | |
| 71 | 71 | } | 
| 72 | 72 | \ No newline at end of file | 
| @@ -80,7 +80,7 @@ discard block | ||
| 80 | 80 | 'action' => 'create_order' | 
| 81 | 81 | ]; | 
| 82 | 82 |  		foreach (($config instanceof \carono\turbotext\ConfigAbstract ? $config->toArray() : $config) as $key => $value) { | 
| 83 | - $params[$key] = $value; | |
| 83 | + $params[$key] = $value; | |
| 84 | 84 | } | 
| 85 | 85 |  		return $this->getClient()->getContent('api', $params, 'carono\turbotext\response\CreateOrderResponse'); | 
| 86 | 86 | } | 
| @@ -98,7 +98,7 @@ discard block | ||
| 98 | 98 | 'action' => 'create_translate_order' | 
| 99 | 99 | ]; | 
| 100 | 100 |  		foreach (($config instanceof \carono\turbotext\ConfigAbstract ? $config->toArray() : $config) as $key => $value) { | 
| 101 | - $params[$key] = $value; | |
| 101 | + $params[$key] = $value; | |
| 102 | 102 | } | 
| 103 | 103 |  		return $this->getClient()->getContent('api', $params, 'carono\turbotext\response\CreateTranslateOrderResponse'); | 
| 104 | 104 | } | 
| @@ -273,7 +273,7 @@ discard block | ||
| 273 | 273 | 'action' => 'edit_order' | 
| 274 | 274 | ]; | 
| 275 | 275 |  		foreach (($config instanceof \carono\turbotext\ConfigAbstract ? $config->toArray() : $config) as $key => $value) { | 
| 276 | - $params[$key] = $value; | |
| 276 | + $params[$key] = $value; | |
| 277 | 277 | } | 
| 278 | 278 |  		return $this->getClient()->getContent('api', $params, 'carono\turbotext\Response'); | 
| 279 | 279 | } | 
| @@ -6,110 +6,110 @@ | ||
| 6 | 6 | |
| 7 | 7 | class RequestAbstract extends ClassGenerator | 
| 8 | 8 |  { | 
| 9 | - /** | |
| 10 | - * @return string | |
| 11 | - */ | |
| 12 | - protected function formExtends() | |
| 13 | -    { | |
| 14 | - return 'carono\turbotext\RequestAbstract'; | |
| 15 | - } | |
| 9 | + /** | |
| 10 | + * @return string | |
| 11 | + */ | |
| 12 | + protected function formExtends() | |
| 13 | +	{ | |
| 14 | + return 'carono\turbotext\RequestAbstract'; | |
| 15 | + } | |
| 16 | 16 | |
| 17 | - /** | |
| 18 | - * @return string | |
| 19 | - */ | |
| 20 | - protected function formClassName() | |
| 21 | -    { | |
| 22 | - return ucfirst($this->params['name']) . 'Request'; | |
| 23 | - } | |
| 17 | + /** | |
| 18 | + * @return string | |
| 19 | + */ | |
| 20 | + protected function formClassName() | |
| 21 | +	{ | |
| 22 | + return ucfirst($this->params['name']) . 'Request'; | |
| 23 | + } | |
| 24 | 24 | |
| 25 | - /** | |
| 26 | - * @return string | |
| 27 | - */ | |
| 28 | - protected function formClassNamespace() | |
| 29 | -    { | |
| 30 | - return 'carono\turbotext\request'; | |
| 31 | - } | |
| 25 | + /** | |
| 26 | + * @return string | |
| 27 | + */ | |
| 28 | + protected function formClassNamespace() | |
| 29 | +	{ | |
| 30 | + return 'carono\turbotext\request'; | |
| 31 | + } | |
| 32 | 32 | |
| 33 | - /** | |
| 34 | - * @return string | |
| 35 | - */ | |
| 36 | - protected function formOutputPath() | |
| 37 | -    { | |
| 38 | - return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'request' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php'; | |
| 39 | - } | |
| 33 | + /** | |
| 34 | + * @return string | |
| 35 | + */ | |
| 36 | + protected function formOutputPath() | |
| 37 | +	{ | |
| 38 | + return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'request' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php'; | |
| 39 | + } | |
| 40 | 40 | |
| 41 | - /** | |
| 42 | - * @return bool | |
| 43 | - */ | |
| 44 | - public function methods() | |
| 45 | -    { | |
| 46 | -        foreach ($this->params['methods'] as $methodData) { | |
| 47 | - $methodName = formMethodName($methodData['name']); | |
| 48 | - $method = $this->phpClass->addMethod($methodName); | |
| 49 | - $method->addComment(stripAndWordWrap($methodData['description'])); | |
| 50 | - $params = []; | |
| 51 | - $params['action'] = $methodData['name']; | |
| 52 | -            if (count($methodData['params']) > 4) { | |
| 53 | - $config = new ConfigAbstract(); | |
| 54 | - $config->renderToFile($methodData); | |
| 55 | - $className = '\\' . $config->formClassNamespace() . '\\' . $config->formClassName(); | |
| 56 | -                $method->addParameter('config'); | |
| 57 | -                $method->addComment("@param $className|array \$config"); | |
| 41 | + /** | |
| 42 | + * @return bool | |
| 43 | + */ | |
| 44 | + public function methods() | |
| 45 | +	{ | |
| 46 | +		foreach ($this->params['methods'] as $methodData) { | |
| 47 | + $methodName = formMethodName($methodData['name']); | |
| 48 | + $method = $this->phpClass->addMethod($methodName); | |
| 49 | + $method->addComment(stripAndWordWrap($methodData['description'])); | |
| 50 | + $params = []; | |
| 51 | + $params['action'] = $methodData['name']; | |
| 52 | +			if (count($methodData['params']) > 4) { | |
| 53 | + $config = new ConfigAbstract(); | |
| 54 | + $config->renderToFile($methodData); | |
| 55 | + $className = '\\' . $config->formClassNamespace() . '\\' . $config->formClassName(); | |
| 56 | +				$method->addParameter('config'); | |
| 57 | +				$method->addComment("@param $className|array \$config"); | |
| 58 | 58 | |
| 59 | - $body = <<<PHP | |
| 59 | + $body = <<<PHP | |
| 60 | 60 |  foreach ((\$config instanceof \carono\\turbotext\ConfigAbstract ? \$config->toArray() : \$config) as \$key => \$value) { | 
| 61 | 61 | \$params[\$key] = \$value; | 
| 62 | 62 | } | 
| 63 | 63 | PHP; | 
| 64 | - $paramsStr = self::arrayAsPhpVar($params); | |
| 65 | -                $method->addBody("\$params = $paramsStr;"); | |
| 66 | - $method->addBody($body); | |
| 67 | -            } else { | |
| 68 | -                foreach ($methodData['params'] as $param) { | |
| 69 | - $type = formParamType($param['type']); | |
| 70 | - $description = trim(stripAndWordWrap($param['description'])); | |
| 71 | -                    $method->addComment("@param {$type} \${$param['name']} {$description}"); | |
| 72 | - $params[$param['name']] = '$' . $param['name']; | |
| 73 | -                    if ($param['required']) { | |
| 74 | - $method->addParameter($param['name']); | |
| 75 | -                    } else { | |
| 76 | - $method->addParameter($param['name'], null); | |
| 77 | - } | |
| 78 | - } | |
| 79 | - $paramsStr = self::arrayAsPhpVar($params); | |
| 80 | -                $method->addBody("\$params = $paramsStr;"); | |
| 81 | - } | |
| 82 | - $response = new ResponseAbstract(); | |
| 83 | -            if (isset($methodData['returns'][0]['result'])) { | |
| 84 | - $returns = $methodData['returns'][0]; | |
| 85 | - $response->renderToFile($returns); | |
| 86 | - $className = $response->formClassNamespace() . '\\' . $response->formClassName(); | |
| 87 | -            } elseif ($methodData['returns']) { | |
| 88 | - $methodData['returns']['name'] = $methodData['name']; | |
| 89 | - $response->properties['asd'] = 213; | |
| 90 | - $response->renderToFile($methodData['returns']); | |
| 91 | - $className = $response->formClassNamespace() . '\\' . $response->formClassName(); | |
| 92 | -            } else { | |
| 93 | - $className = 'carono\turbotext\Response'; | |
| 94 | - } | |
| 95 | -            $method->addComment("@return \\$className|string|\stdClass|\SimpleXMLElement"); | |
| 96 | -            $method->addBody("return \$this->getClient()->getContent('api', \$params, '$className');"); | |
| 97 | - } | |
| 98 | - return false; | |
| 99 | - } | |
| 64 | + $paramsStr = self::arrayAsPhpVar($params); | |
| 65 | +				$method->addBody("\$params = $paramsStr;"); | |
| 66 | + $method->addBody($body); | |
| 67 | +			} else { | |
| 68 | +				foreach ($methodData['params'] as $param) { | |
| 69 | + $type = formParamType($param['type']); | |
| 70 | + $description = trim(stripAndWordWrap($param['description'])); | |
| 71 | +					$method->addComment("@param {$type} \${$param['name']} {$description}"); | |
| 72 | + $params[$param['name']] = '$' . $param['name']; | |
| 73 | +					if ($param['required']) { | |
| 74 | + $method->addParameter($param['name']); | |
| 75 | +					} else { | |
| 76 | + $method->addParameter($param['name'], null); | |
| 77 | + } | |
| 78 | + } | |
| 79 | + $paramsStr = self::arrayAsPhpVar($params); | |
| 80 | +				$method->addBody("\$params = $paramsStr;"); | |
| 81 | + } | |
| 82 | + $response = new ResponseAbstract(); | |
| 83 | +			if (isset($methodData['returns'][0]['result'])) { | |
| 84 | + $returns = $methodData['returns'][0]; | |
| 85 | + $response->renderToFile($returns); | |
| 86 | + $className = $response->formClassNamespace() . '\\' . $response->formClassName(); | |
| 87 | +			} elseif ($methodData['returns']) { | |
| 88 | + $methodData['returns']['name'] = $methodData['name']; | |
| 89 | + $response->properties['asd'] = 213; | |
| 90 | + $response->renderToFile($methodData['returns']); | |
| 91 | + $className = $response->formClassNamespace() . '\\' . $response->formClassName(); | |
| 92 | +			} else { | |
| 93 | + $className = 'carono\turbotext\Response'; | |
| 94 | + } | |
| 95 | +			$method->addComment("@return \\$className|string|\stdClass|\SimpleXMLElement"); | |
| 96 | +			$method->addBody("return \$this->getClient()->getContent('api', \$params, '$className');"); | |
| 97 | + } | |
| 98 | + return false; | |
| 99 | + } | |
| 100 | 100 | |
| 101 | - protected static function arrayAsPhpVar($array) | |
| 102 | -    { | |
| 103 | - $export = []; | |
| 104 | -        foreach ($array as $key => $value) { | |
| 105 | - $export[] = "'$key' => " . (strpos($value, '$') === false ? "'$value'" : $value); | |
| 106 | - } | |
| 107 | -        $export = join(",\n\t", $export); | |
| 108 | -        if ($array) { | |
| 109 | - $result = "[\n\t$export\n]"; | |
| 110 | -        } else { | |
| 111 | - $result = "[]"; | |
| 112 | - } | |
| 113 | - return $result; | |
| 114 | - } | |
| 101 | + protected static function arrayAsPhpVar($array) | |
| 102 | +	{ | |
| 103 | + $export = []; | |
| 104 | +		foreach ($array as $key => $value) { | |
| 105 | + $export[] = "'$key' => " . (strpos($value, '$') === false ? "'$value'" : $value); | |
| 106 | + } | |
| 107 | +		$export = join(",\n\t", $export); | |
| 108 | +		if ($array) { | |
| 109 | + $result = "[\n\t$export\n]"; | |
| 110 | +		} else { | |
| 111 | + $result = "[]"; | |
| 112 | + } | |
| 113 | + return $result; | |
| 114 | + } | |
| 115 | 115 | } | 
| 116 | 116 | \ No newline at end of file |