@@ -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 | - 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']) . '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 |
@@ -2,119 +2,119 @@ |
||
| 2 | 2 | |
| 3 | 3 | function stripAndWordWrap($str) |
| 4 | 4 | { |
| 5 | - return wordwrap(stripSpaces($str), 180) . "\n"; |
|
| 5 | + return wordwrap(stripSpaces($str), 180) . "\n"; |
|
| 6 | 6 | } |
| 7 | 7 | |
| 8 | 8 | function formParamLine($param) |
| 9 | 9 | { |
| 10 | - return '**' . $param['name'] . "** ({$param['type']}) - " . stripLines($param['description']); |
|
| 10 | + return '**' . $param['name'] . "** ({$param['type']}) - " . stripLines($param['description']); |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | function stripSpaces($str) |
| 14 | 14 | { |
| 15 | - $str = preg_replace('/[\s]{2,}/', " ", $str); |
|
| 16 | - return $str; |
|
| 15 | + $str = preg_replace('/[\s]{2,}/', " ", $str); |
|
| 16 | + return $str; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | function stripLines($str) |
| 20 | 20 | { |
| 21 | - $str = str_replace("\n", " ", $str); |
|
| 22 | - $str = stripSpaces($str); |
|
| 23 | - return $str; |
|
| 21 | + $str = str_replace("\n", " ", $str); |
|
| 22 | + $str = stripSpaces($str); |
|
| 23 | + return $str; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | function formMethodName($str) |
| 27 | 27 | { |
| 28 | - $arr = array_filter(explode('_', $str)); |
|
| 29 | - $arr = array_map('ucfirst', $arr); |
|
| 30 | - $arr[0] = lcfirst($arr[0]); |
|
| 31 | - return join('', $arr); |
|
| 28 | + $arr = array_filter(explode('_', $str)); |
|
| 29 | + $arr = array_map('ucfirst', $arr); |
|
| 30 | + $arr[0] = lcfirst($arr[0]); |
|
| 31 | + return join('', $arr); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | function formClassName($str) |
| 35 | 35 | { |
| 36 | - $clear = [ |
|
| 37 | - 'get_', |
|
| 38 | - 'create_', |
|
| 39 | - '_array' |
|
| 40 | - ]; |
|
| 41 | - foreach ($clear as $item) { |
|
| 42 | - $str = str_ireplace($item, '', $str); |
|
| 43 | - } |
|
| 44 | - $arr = array_filter(explode('_', $str)); |
|
| 45 | - $arr = array_map('ucfirst', $arr); |
|
| 46 | - return join('', $arr); |
|
| 36 | + $clear = [ |
|
| 37 | + 'get_', |
|
| 38 | + 'create_', |
|
| 39 | + '_array' |
|
| 40 | + ]; |
|
| 41 | + foreach ($clear as $item) { |
|
| 42 | + $str = str_ireplace($item, '', $str); |
|
| 43 | + } |
|
| 44 | + $arr = array_filter(explode('_', $str)); |
|
| 45 | + $arr = array_map('ucfirst', $arr); |
|
| 46 | + return join('', $arr); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | function formParamType($str) |
| 50 | 50 | { |
| 51 | - if ($str == 'text') { |
|
| 52 | - return 'string'; |
|
| 53 | - } |
|
| 54 | - return $str; |
|
| 51 | + if ($str == 'text') { |
|
| 52 | + return 'string'; |
|
| 53 | + } |
|
| 54 | + return $str; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | function parseParams($str) |
| 58 | 58 | { |
| 59 | - if (preg_match('/^(\w+)\s+\((\w+)\)\s+-\s+(.+)/uis', $str, $m)) { |
|
| 60 | - return [ |
|
| 61 | - 'name' => $m[1], |
|
| 62 | - 'type' => $m[2], |
|
| 63 | - 'description' => $m[3], |
|
| 64 | - 'required' => mb_strpos($m[3], 'Необязательный', 0, 'utf-8') === false |
|
| 65 | - ]; |
|
| 66 | - } else { |
|
| 67 | - return []; |
|
| 68 | - } |
|
| 59 | + if (preg_match('/^(\w+)\s+\((\w+)\)\s+-\s+(.+)/uis', $str, $m)) { |
|
| 60 | + return [ |
|
| 61 | + 'name' => $m[1], |
|
| 62 | + 'type' => $m[2], |
|
| 63 | + 'description' => $m[3], |
|
| 64 | + 'required' => mb_strpos($m[3], 'Необязательный', 0, 'utf-8') === false |
|
| 65 | + ]; |
|
| 66 | + } else { |
|
| 67 | + return []; |
|
| 68 | + } |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | function parseReturns($tdHtml) |
| 72 | 72 | { |
| 73 | - $uls = pq($tdHtml)->find('ul'); |
|
| 74 | - $returns = []; |
|
| 75 | - if ($uls->count() == 1 && strpos($tdHtml, 'Каждый элемент') !== false) { |
|
| 76 | - if (preg_match('/<td>(.)+<ul>/s', $tdHtml, $m)) { |
|
| 77 | - $ul = "<ul><li>" . trim(strip_tags($m[0])) . "</li></ul>"; |
|
| 78 | - $uls = pq("<td>$ul{$uls->eq(0)->htmlOuter()}</td>")->find('ul'); |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - if ($uls->count() == 2) { |
|
| 82 | - $returnParam = parseParams($uls->eq(0)->text()); |
|
| 83 | - $result = []; |
|
| 84 | - foreach ($uls->eq(1)->find('li') as $param) { |
|
| 85 | - if ($parsedParam = parseParams(pq($param)->text())) { |
|
| 86 | - $result[] = $parsedParam; |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - $returnParam['result'] = $result; |
|
| 90 | - $returns[] = $returnParam; |
|
| 91 | - } else { |
|
| 92 | - foreach ($uls->eq(0)->find('li') as $param) { |
|
| 93 | - if ($parsedParam = parseParams(pq($param)->text())) { |
|
| 94 | - $returns[] = $parsedParam; |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - return $returns; |
|
| 73 | + $uls = pq($tdHtml)->find('ul'); |
|
| 74 | + $returns = []; |
|
| 75 | + if ($uls->count() == 1 && strpos($tdHtml, 'Каждый элемент') !== false) { |
|
| 76 | + if (preg_match('/<td>(.)+<ul>/s', $tdHtml, $m)) { |
|
| 77 | + $ul = "<ul><li>" . trim(strip_tags($m[0])) . "</li></ul>"; |
|
| 78 | + $uls = pq("<td>$ul{$uls->eq(0)->htmlOuter()}</td>")->find('ul'); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + if ($uls->count() == 2) { |
|
| 82 | + $returnParam = parseParams($uls->eq(0)->text()); |
|
| 83 | + $result = []; |
|
| 84 | + foreach ($uls->eq(1)->find('li') as $param) { |
|
| 85 | + if ($parsedParam = parseParams(pq($param)->text())) { |
|
| 86 | + $result[] = $parsedParam; |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + $returnParam['result'] = $result; |
|
| 90 | + $returns[] = $returnParam; |
|
| 91 | + } else { |
|
| 92 | + foreach ($uls->eq(0)->find('li') as $param) { |
|
| 93 | + if ($parsedParam = parseParams(pq($param)->text())) { |
|
| 94 | + $returns[] = $parsedParam; |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + return $returns; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | function asTable($array) |
| 102 | 102 | { |
| 103 | - $header = array_shift($array); |
|
| 104 | - $content = "\n\n|" . join("|", $header) . "\n"; |
|
| 105 | - $content .= preg_replace('/[^\|]/iu', '-', trim($content)) . "\n"; |
|
| 106 | - foreach ($array as $key => $columns) { |
|
| 107 | - $content .= "|" . join("|", $columns) . "\n"; |
|
| 108 | - } |
|
| 109 | - return $content; |
|
| 103 | + $header = array_shift($array); |
|
| 104 | + $content = "\n\n|" . join("|", $header) . "\n"; |
|
| 105 | + $content .= preg_replace('/[^\|]/iu', '-', trim($content)) . "\n"; |
|
| 106 | + foreach ($array as $key => $columns) { |
|
| 107 | + $content .= "|" . join("|", $columns) . "\n"; |
|
| 108 | + } |
|
| 109 | + return $content; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | function asHeader($string) |
| 113 | 113 | { |
| 114 | - return "\n\n" . $string . "\n" . str_repeat('=', mb_strlen($string, 'utf-8')) . "\n"; |
|
| 114 | + return "\n\n" . $string . "\n" . str_repeat('=', mb_strlen($string, 'utf-8')) . "\n"; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | function asCode($code) |
| 118 | 118 | { |
| 119 | - return "`$code`"; |
|
| 119 | + return "`$code`"; |
|
| 120 | 120 | } |
| 121 | 121 | \ 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 | - stripAndWordWrap($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 | - stripAndWordWrap($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 | + stripAndWordWrap($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 | + stripAndWordWrap($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,109 +6,109 @@ |
||
| 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 | - $response->renderToFile($methodData['returns'][0]); |
|
| 85 | - $className = $response->formClassNamespace() . '\\' . $response->formClassName(); |
|
| 86 | - } elseif ($methodData['returns']) { |
|
| 87 | - $methodData['returns']['name'] = $methodData['name']; |
|
| 88 | - $response->properties['asd'] = 213; |
|
| 89 | - $response->renderToFile($methodData['returns']); |
|
| 90 | - $className = $response->formClassNamespace() . '\\' . $response->formClassName(); |
|
| 91 | - } else { |
|
| 92 | - $className = 'carono\turbotext\Response'; |
|
| 93 | - } |
|
| 94 | - $method->addComment("@return \\$className|string|\stdClass|\SimpleXMLElement"); |
|
| 95 | - $method->addBody("return \$this->getClient()->getContent('api', \$params, '$className');"); |
|
| 96 | - } |
|
| 97 | - return false; |
|
| 98 | - } |
|
| 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 | + $response->renderToFile($methodData['returns'][0]); |
|
| 85 | + $className = $response->formClassNamespace() . '\\' . $response->formClassName(); |
|
| 86 | + } elseif ($methodData['returns']) { |
|
| 87 | + $methodData['returns']['name'] = $methodData['name']; |
|
| 88 | + $response->properties['asd'] = 213; |
|
| 89 | + $response->renderToFile($methodData['returns']); |
|
| 90 | + $className = $response->formClassNamespace() . '\\' . $response->formClassName(); |
|
| 91 | + } else { |
|
| 92 | + $className = 'carono\turbotext\Response'; |
|
| 93 | + } |
|
| 94 | + $method->addComment("@return \\$className|string|\stdClass|\SimpleXMLElement"); |
|
| 95 | + $method->addBody("return \$this->getClient()->getContent('api', \$params, '$className');"); |
|
| 96 | + } |
|
| 97 | + return false; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - protected static function arrayAsPhpVar($array) |
|
| 101 | - { |
|
| 102 | - $export = []; |
|
| 103 | - foreach ($array as $key => $value) { |
|
| 104 | - $export[] = "'$key' => " . (strpos($value, '$') === false ? "'$value'" : $value); |
|
| 105 | - } |
|
| 106 | - $export = join(",\n\t", $export); |
|
| 107 | - if ($array) { |
|
| 108 | - $result = "[\n\t$export\n]"; |
|
| 109 | - } else { |
|
| 110 | - $result = "[]"; |
|
| 111 | - } |
|
| 112 | - return $result; |
|
| 113 | - } |
|
| 100 | + protected static function arrayAsPhpVar($array) |
|
| 101 | + { |
|
| 102 | + $export = []; |
|
| 103 | + foreach ($array as $key => $value) { |
|
| 104 | + $export[] = "'$key' => " . (strpos($value, '$') === false ? "'$value'" : $value); |
|
| 105 | + } |
|
| 106 | + $export = join(",\n\t", $export); |
|
| 107 | + if ($array) { |
|
| 108 | + $result = "[\n\t$export\n]"; |
|
| 109 | + } else { |
|
| 110 | + $result = "[]"; |
|
| 111 | + } |
|
| 112 | + return $result; |
|
| 113 | + } |
|
| 114 | 114 | } |
| 115 | 115 | \ No newline at end of file |