@@ -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 |
@@ -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 |
@@ -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 |