@@ -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 |
@@ -1,127 +1,127 @@ |
||
1 | 1 | <?php |
2 | 2 | function clearFolder($folder) |
3 | 3 | { |
4 | - $files = glob(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . '*'); |
|
5 | - foreach ($files as $file) { |
|
6 | - if (is_file($file)) { |
|
7 | - @unlink($file); |
|
8 | - } |
|
9 | - } |
|
4 | + $files = glob(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . '*'); |
|
5 | + foreach ($files as $file) { |
|
6 | + if (is_file($file)) { |
|
7 | + @unlink($file); |
|
8 | + } |
|
9 | + } |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | function stripAndWordWrap($str) |
13 | 13 | { |
14 | - return wordwrap(stripSpaces($str), 180) . "\n"; |
|
14 | + return wordwrap(stripSpaces($str), 180) . "\n"; |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | function formParamLine($param) |
18 | 18 | { |
19 | - return '**' . $param['name'] . "** ({$param['type']}) - " . stripLines($param['description']); |
|
19 | + return '**' . $param['name'] . "** ({$param['type']}) - " . stripLines($param['description']); |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | function stripSpaces($str) |
23 | 23 | { |
24 | - $str = preg_replace('/[\s]{2,}/', " ", $str); |
|
25 | - return $str; |
|
24 | + $str = preg_replace('/[\s]{2,}/', " ", $str); |
|
25 | + return $str; |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | function stripLines($str) |
29 | 29 | { |
30 | - $str = str_replace("\n", " ", $str); |
|
31 | - $str = stripSpaces($str); |
|
32 | - return $str; |
|
30 | + $str = str_replace("\n", " ", $str); |
|
31 | + $str = stripSpaces($str); |
|
32 | + return $str; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | function formMethodName($str) |
36 | 36 | { |
37 | - $arr = array_filter(explode('_', $str)); |
|
38 | - $arr = array_map('ucfirst', $arr); |
|
39 | - $arr[0] = lcfirst($arr[0]); |
|
40 | - return join('', $arr); |
|
37 | + $arr = array_filter(explode('_', $str)); |
|
38 | + $arr = array_map('ucfirst', $arr); |
|
39 | + $arr[0] = lcfirst($arr[0]); |
|
40 | + return join('', $arr); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | function formClassName($str, $clear = ['get_', '_array']) |
44 | 44 | { |
45 | - foreach ($clear as $item) { |
|
46 | - $str = str_ireplace($item, '', $str); |
|
47 | - } |
|
48 | - $arr = array_filter(explode('_', $str)); |
|
49 | - $arr = array_map('ucfirst', $arr); |
|
50 | - return join('', $arr); |
|
45 | + foreach ($clear as $item) { |
|
46 | + $str = str_ireplace($item, '', $str); |
|
47 | + } |
|
48 | + $arr = array_filter(explode('_', $str)); |
|
49 | + $arr = array_map('ucfirst', $arr); |
|
50 | + return join('', $arr); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | function formParamType($str) |
54 | 54 | { |
55 | - switch ($str) { |
|
56 | - case 'text': |
|
57 | - return 'string'; |
|
58 | - break; |
|
59 | - case 'date': |
|
60 | - return 'string Y-m-d'; |
|
61 | - break; |
|
62 | - case 'datetime': |
|
63 | - return 'string Y-m-d H:i:s'; |
|
64 | - break; |
|
65 | - } |
|
66 | - return $str; |
|
55 | + switch ($str) { |
|
56 | + case 'text': |
|
57 | + return 'string'; |
|
58 | + break; |
|
59 | + case 'date': |
|
60 | + return 'string Y-m-d'; |
|
61 | + break; |
|
62 | + case 'datetime': |
|
63 | + return 'string Y-m-d H:i:s'; |
|
64 | + break; |
|
65 | + } |
|
66 | + return $str; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | function parseParams($str) |
70 | 70 | { |
71 | - if (preg_match('/^(\w+)\s+\((\w+)\)\s+-\s+(.+)/uis', $str, $m)) { |
|
72 | - return [ |
|
73 | - 'name' => $m[1], |
|
74 | - 'type' => $m[2], |
|
75 | - 'description' => $m[3], |
|
76 | - 'required' => mb_strpos($m[3], 'Необязательный', 0, 'utf-8') === false |
|
77 | - ]; |
|
78 | - } else { |
|
79 | - return []; |
|
80 | - } |
|
71 | + if (preg_match('/^(\w+)\s+\((\w+)\)\s+-\s+(.+)/uis', $str, $m)) { |
|
72 | + return [ |
|
73 | + 'name' => $m[1], |
|
74 | + 'type' => $m[2], |
|
75 | + 'description' => $m[3], |
|
76 | + 'required' => mb_strpos($m[3], 'Необязательный', 0, 'utf-8') === false |
|
77 | + ]; |
|
78 | + } else { |
|
79 | + return []; |
|
80 | + } |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | function parseReturns($tdHtml) |
84 | 84 | { |
85 | - $uls = pq($tdHtml)->find('ul'); |
|
86 | - if ($uls->count() == 1 && strpos($tdHtml, 'Каждый элемент') !== false) { |
|
87 | - if (preg_match('/<td>(.)+<ul>/s', $tdHtml, $m)) { |
|
88 | - $ul = "<ul><li>" . trim(strip_tags($m[0])) . "</li></ul>"; |
|
89 | - $uls = pq("<td>$ul{$uls->eq(0)->htmlOuter()}</td>")->find('ul'); |
|
90 | - } |
|
91 | - } |
|
92 | - $count = $uls->count(); |
|
93 | - $parsing = []; |
|
94 | - foreach ($uls->eq($count == 2 ? 1 : 0)->find('li') as $param) { |
|
95 | - if ($parsedParam = parseParams(pq($param)->text())) { |
|
96 | - $parsing[] = $parsedParam; |
|
97 | - } |
|
98 | - } |
|
99 | - if ($count == 2) { |
|
100 | - $returnParam = parseParams($uls->eq(0)->text()); |
|
101 | - $returnParam['result'] = $parsing; |
|
102 | - return [$returnParam]; |
|
103 | - } else { |
|
104 | - return $parsing; |
|
105 | - } |
|
85 | + $uls = pq($tdHtml)->find('ul'); |
|
86 | + if ($uls->count() == 1 && strpos($tdHtml, 'Каждый элемент') !== false) { |
|
87 | + if (preg_match('/<td>(.)+<ul>/s', $tdHtml, $m)) { |
|
88 | + $ul = "<ul><li>" . trim(strip_tags($m[0])) . "</li></ul>"; |
|
89 | + $uls = pq("<td>$ul{$uls->eq(0)->htmlOuter()}</td>")->find('ul'); |
|
90 | + } |
|
91 | + } |
|
92 | + $count = $uls->count(); |
|
93 | + $parsing = []; |
|
94 | + foreach ($uls->eq($count == 2 ? 1 : 0)->find('li') as $param) { |
|
95 | + if ($parsedParam = parseParams(pq($param)->text())) { |
|
96 | + $parsing[] = $parsedParam; |
|
97 | + } |
|
98 | + } |
|
99 | + if ($count == 2) { |
|
100 | + $returnParam = parseParams($uls->eq(0)->text()); |
|
101 | + $returnParam['result'] = $parsing; |
|
102 | + return [$returnParam]; |
|
103 | + } else { |
|
104 | + return $parsing; |
|
105 | + } |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | function asTable($array) |
109 | 109 | { |
110 | - $header = array_shift($array); |
|
111 | - $content = "\n\n|" . join("|", $header) . "\n"; |
|
112 | - $content .= preg_replace('/[^\|]/iu', '-', trim($content)) . "\n"; |
|
113 | - foreach ($array as $key => $columns) { |
|
114 | - $content .= "|" . join("|", $columns) . "\n"; |
|
115 | - } |
|
116 | - return $content; |
|
110 | + $header = array_shift($array); |
|
111 | + $content = "\n\n|" . join("|", $header) . "\n"; |
|
112 | + $content .= preg_replace('/[^\|]/iu', '-', trim($content)) . "\n"; |
|
113 | + foreach ($array as $key => $columns) { |
|
114 | + $content .= "|" . join("|", $columns) . "\n"; |
|
115 | + } |
|
116 | + return $content; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | function asHeader($string) |
120 | 120 | { |
121 | - return "\n\n" . $string . "\n" . str_repeat('=', mb_strlen($string, 'utf-8')) . "\n"; |
|
121 | + return "\n\n" . $string . "\n" . str_repeat('=', mb_strlen($string, 'utf-8')) . "\n"; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | function asCode($code) |
125 | 125 | { |
126 | - return "`$code`"; |
|
126 | + return "`$code`"; |
|
127 | 127 | } |
128 | 128 | \ 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 |