@@ -17,10 +17,10 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | $apidoc = 'apidoc.html'; |
| 19 | 19 | if (file_exists($apidoc)) { |
| 20 | - $content = file_get_contents($apidoc); |
|
| 20 | + $content = file_get_contents($apidoc); |
|
| 21 | 21 | } else { |
| 22 | - $content = (new Client())->get('https://www.etxt.ru/api/')->getBody()->getContents(); |
|
| 23 | - file_put_contents($apidoc, $content); |
|
| 22 | + $content = (new Client())->get('https://www.etxt.ru/api/')->getBody()->getContents(); |
|
| 23 | + file_put_contents($apidoc, $content); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | |
@@ -28,54 +28,54 @@ discard block |
||
| 28 | 28 | $data = []; |
| 29 | 29 | |
| 30 | 30 | foreach ($query->find('h4') as $title) { |
| 31 | - $name = pq($title)->text(); |
|
| 32 | - if (strpos($name, '.') === false) { |
|
| 33 | - continue; |
|
| 34 | - } |
|
| 35 | - echo $name . "\n"; |
|
| 36 | - $description = $query->find("td:contains('$name')")->next('td')->text(); |
|
| 37 | - list($api, $method) = explode('.', $name); |
|
| 31 | + $name = pq($title)->text(); |
|
| 32 | + if (strpos($name, '.') === false) { |
|
| 33 | + continue; |
|
| 34 | + } |
|
| 35 | + echo $name . "\n"; |
|
| 36 | + $description = $query->find("td:contains('$name')")->next('td')->text(); |
|
| 37 | + list($api, $method) = explode('.', $name); |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | - $params = []; |
|
| 41 | - if (pq($title)->nextAll('h5')->eq(0)->text() === 'Параметры') { |
|
| 42 | - foreach (pq($title)->nextAll('h5:contains("Параметры")')->eq(0)->next('table')->eq(0)->find('tr')->eq(0)->nextAll() as $tr) { |
|
| 43 | - $td = pq($tr)->find('td'); |
|
| 44 | - foreach (explode(', ', $td->eq(0)->text()) as $name) { |
|
| 45 | - $params[] = [ |
|
| 46 | - 'name' => $name, |
|
| 47 | - 'type' => $td->eq(1)->text(), |
|
| 48 | - 'description' => $td->eq(2)->text(), |
|
| 49 | - 'required' => isRequired($td->eq(2)->text()) |
|
| 50 | - ]; |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - $results = []; |
|
| 55 | - foreach (pq($title)->nextAll('h5:contains("Результат")')->next('table')->eq(0)->find('tr')->eq(0)->nextAll() as $tr) { |
|
| 56 | - $td = pq($tr)->find('td'); |
|
| 57 | - foreach (explode(', ', $td->eq(0)->text()) as $name) { |
|
| 58 | - $results[] = [ |
|
| 59 | - 'name' => $name, |
|
| 60 | - 'description' => $td->eq(1)->text(), |
|
| 61 | - ]; |
|
| 62 | - } |
|
| 63 | - } |
|
| 40 | + $params = []; |
|
| 41 | + if (pq($title)->nextAll('h5')->eq(0)->text() === 'Параметры') { |
|
| 42 | + foreach (pq($title)->nextAll('h5:contains("Параметры")')->eq(0)->next('table')->eq(0)->find('tr')->eq(0)->nextAll() as $tr) { |
|
| 43 | + $td = pq($tr)->find('td'); |
|
| 44 | + foreach (explode(', ', $td->eq(0)->text()) as $name) { |
|
| 45 | + $params[] = [ |
|
| 46 | + 'name' => $name, |
|
| 47 | + 'type' => $td->eq(1)->text(), |
|
| 48 | + 'description' => $td->eq(2)->text(), |
|
| 49 | + 'required' => isRequired($td->eq(2)->text()) |
|
| 50 | + ]; |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + $results = []; |
|
| 55 | + foreach (pq($title)->nextAll('h5:contains("Результат")')->next('table')->eq(0)->find('tr')->eq(0)->nextAll() as $tr) { |
|
| 56 | + $td = pq($tr)->find('td'); |
|
| 57 | + foreach (explode(', ', $td->eq(0)->text()) as $name) { |
|
| 58 | + $results[] = [ |
|
| 59 | + 'name' => $name, |
|
| 60 | + 'description' => $td->eq(1)->text(), |
|
| 61 | + ]; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - if (!isset($data[$api])) { |
|
| 66 | - $data[$api] = [ |
|
| 67 | - 'name' => $api, |
|
| 68 | - 'description' => $description, |
|
| 69 | - 'methods' => [] |
|
| 70 | - ]; |
|
| 71 | - } |
|
| 65 | + if (!isset($data[$api])) { |
|
| 66 | + $data[$api] = [ |
|
| 67 | + 'name' => $api, |
|
| 68 | + 'description' => $description, |
|
| 69 | + 'methods' => [] |
|
| 70 | + ]; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - $data[$api]['methods'][] = [ |
|
| 74 | - 'name' => $method, |
|
| 75 | - 'description' => pq($title)->next('p')->text(), |
|
| 76 | - 'params' => $params, |
|
| 77 | - 'returns' => $results |
|
| 78 | - ]; |
|
| 73 | + $data[$api]['methods'][] = [ |
|
| 74 | + 'name' => $method, |
|
| 75 | + 'description' => pq($title)->next('p')->text(), |
|
| 76 | + 'params' => $params, |
|
| 77 | + 'returns' => $results |
|
| 78 | + ]; |
|
| 79 | 79 | }; |
| 80 | 80 | file_put_contents('data.json', json_encode($data)); |
| 81 | 81 | |
@@ -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 | - } |
|
| 13 | - |
|
| 14 | - protected function formClassName() |
|
| 15 | - { |
|
| 16 | - return 'ClientAbstract'; |
|
| 17 | - } |
|
| 18 | - |
|
| 19 | - protected function formClassNamespace() |
|
| 20 | - { |
|
| 21 | - return 'carono\etxtru'; |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - protected function formOutputPath() |
|
| 25 | - { |
|
| 26 | - return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php'; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - public function methods() |
|
| 30 | - { |
|
| 31 | - $this->phpClass->setAbstract(true); |
|
| 32 | - foreach ($this->params as $request => $data) { |
|
| 33 | - $sectionRequest = new RequestAbstract(); |
|
| 34 | - $sectionRequest->renderToFile($data); |
|
| 35 | - $className = "\\" . $sectionRequest->formClassNamespace() . "\\" . $sectionRequest->formClassName(); |
|
| 36 | - |
|
| 37 | - $method = $this->phpClass->addMethod(formMethodName($request)); |
|
| 38 | - $body = <<<PHP |
|
| 9 | + protected function formExtends() |
|
| 10 | + { |
|
| 11 | + return 'carono\rest\Client'; |
|
| 12 | + } |
|
| 13 | + |
|
| 14 | + protected function formClassName() |
|
| 15 | + { |
|
| 16 | + return 'ClientAbstract'; |
|
| 17 | + } |
|
| 18 | + |
|
| 19 | + protected function formClassNamespace() |
|
| 20 | + { |
|
| 21 | + return 'carono\etxtru'; |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + protected function formOutputPath() |
|
| 25 | + { |
|
| 26 | + return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php'; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + public function methods() |
|
| 30 | + { |
|
| 31 | + $this->phpClass->setAbstract(true); |
|
| 32 | + foreach ($this->params as $request => $data) { |
|
| 33 | + $sectionRequest = new RequestAbstract(); |
|
| 34 | + $sectionRequest->renderToFile($data); |
|
| 35 | + $className = "\\" . $sectionRequest->formClassNamespace() . "\\" . $sectionRequest->formClassName(); |
|
| 36 | + |
|
| 37 | + $method = $this->phpClass->addMethod(formMethodName($request)); |
|
| 38 | + $body = <<<PHP |
|
| 39 | 39 | return (new $className(\$this)); |
| 40 | 40 | PHP; |
| 41 | - $method->addBody($body); |
|
| 42 | - $method->addComment($data['description']); |
|
| 43 | - $method->addComment("@return $className"); |
|
| 44 | - } |
|
| 45 | - return false; |
|
| 46 | - } |
|
| 41 | + $method->addBody($body); |
|
| 42 | + $method->addComment($data['description']); |
|
| 43 | + $method->addComment("@return $className"); |
|
| 44 | + } |
|
| 45 | + return false; |
|
| 46 | + } |
|
| 47 | 47 | } |
| 48 | 48 | \ No newline at end of file |
@@ -6,51 +6,51 @@ |
||
| 6 | 6 | |
| 7 | 7 | class ResponseAbstract extends ClassGenerator |
| 8 | 8 | { |
| 9 | - public $properties = []; |
|
| 10 | - |
|
| 11 | - protected function formExtends() |
|
| 12 | - { |
|
| 13 | - if (strpos($this->formClassName(), 'ElementResponse')) { |
|
| 14 | - return 'carono\etxtru\ArrayObject'; |
|
| 15 | - } |
|
| 16 | - |
|
| 17 | - return 'carono\etxtru\ResponseAbstract'; |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - protected function formClassName() |
|
| 21 | - { |
|
| 22 | - $name = $this->params['name']; |
|
| 23 | - |
|
| 24 | - |
|
| 25 | - $name = formClassName($name); |
|
| 26 | - if (!isset($this->params['returns']) && substr($name, -1, 1) == 's') { |
|
| 27 | - $name = substr($name, 0, -1) . 'Element'; |
|
| 28 | - } |
|
| 29 | - return $name . 'Response'; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - protected function formClassNamespace() |
|
| 33 | - { |
|
| 34 | - return 'carono\etxtru\response'; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - protected function formOutputPath() |
|
| 38 | - { |
|
| 39 | - return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'response' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php'; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - protected function classProperties() |
|
| 43 | - { |
|
| 44 | - $properties = []; |
|
| 45 | - foreach ($this->params['returns'] as $param) { |
|
| 46 | - $properties[$param['name']] = [ |
|
| 47 | - 'comment' => [ |
|
| 48 | - stripAndWordWrap($param['description']) |
|
| 49 | - ], |
|
| 50 | - 'value' => null |
|
| 51 | - ]; |
|
| 52 | - } |
|
| 53 | - return $properties; |
|
| 54 | - } |
|
| 9 | + public $properties = []; |
|
| 10 | + |
|
| 11 | + protected function formExtends() |
|
| 12 | + { |
|
| 13 | + if (strpos($this->formClassName(), 'ElementResponse')) { |
|
| 14 | + return 'carono\etxtru\ArrayObject'; |
|
| 15 | + } |
|
| 16 | + |
|
| 17 | + return 'carono\etxtru\ResponseAbstract'; |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + protected function formClassName() |
|
| 21 | + { |
|
| 22 | + $name = $this->params['name']; |
|
| 23 | + |
|
| 24 | + |
|
| 25 | + $name = formClassName($name); |
|
| 26 | + if (!isset($this->params['returns']) && substr($name, -1, 1) == 's') { |
|
| 27 | + $name = substr($name, 0, -1) . 'Element'; |
|
| 28 | + } |
|
| 29 | + return $name . 'Response'; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + protected function formClassNamespace() |
|
| 33 | + { |
|
| 34 | + return 'carono\etxtru\response'; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + protected function formOutputPath() |
|
| 38 | + { |
|
| 39 | + return dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . 'response' . DIRECTORY_SEPARATOR . $this->formClassName() . '.php'; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + protected function classProperties() |
|
| 43 | + { |
|
| 44 | + $properties = []; |
|
| 45 | + foreach ($this->params['returns'] as $param) { |
|
| 46 | + $properties[$param['name']] = [ |
|
| 47 | + 'comment' => [ |
|
| 48 | + stripAndWordWrap($param['description']) |
|
| 49 | + ], |
|
| 50 | + 'value' => null |
|
| 51 | + ]; |
|
| 52 | + } |
|
| 53 | + return $properties; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | 56 | } |
| 57 | 57 | \ 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\etxtru\ConfigAbstract'; |
|
| 13 | - } |
|
| 14 | - |
|
| 15 | - protected function formClassName() |
|
| 16 | - { |
|
| 17 | - return formClassName($this->params['api'] . '_' . $this->params['name'], []) . 'Config'; |
|
| 18 | - } |
|
| 19 | - |
|
| 20 | - protected function formClassNamespace() |
|
| 21 | - { |
|
| 22 | - return 'carono\etxtru\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\etxtru\ConfigAbstract'; |
|
| 13 | + } |
|
| 14 | + |
|
| 15 | + protected function formClassName() |
|
| 16 | + { |
|
| 17 | + return formClassName($this->params['api'] . '_' . $this->params['name'], []) . 'Config'; |
|
| 18 | + } |
|
| 19 | + |
|
| 20 | + protected function formClassNamespace() |
|
| 21 | + { |
|
| 22 | + return 'carono\etxtru\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,105 +6,105 @@ |
||
| 6 | 6 | |
| 7 | 7 | class RequestAbstract extends ClassGenerator |
| 8 | 8 | { |
| 9 | - /** |
|
| 10 | - * @return string |
|
| 11 | - */ |
|
| 12 | - protected function formExtends() |
|
| 13 | - { |
|
| 14 | - return 'carono\etxtru\RequestAbstract'; |
|
| 15 | - } |
|
| 9 | + /** |
|
| 10 | + * @return string |
|
| 11 | + */ |
|
| 12 | + protected function formExtends() |
|
| 13 | + { |
|
| 14 | + return 'carono\etxtru\RequestAbstract'; |
|
| 15 | + } |
|
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @return string |
|
| 19 | - */ |
|
| 20 | - protected function formClassName() |
|
| 21 | - { |
|
| 22 | - return ucfirst(formClassName($this->params['name'])) . 'Request'; |
|
| 23 | - } |
|
| 17 | + /** |
|
| 18 | + * @return string |
|
| 19 | + */ |
|
| 20 | + protected function formClassName() |
|
| 21 | + { |
|
| 22 | + return ucfirst(formClassName($this->params['name'])) . 'Request'; |
|
| 23 | + } |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * @return string |
|
| 27 | - */ |
|
| 28 | - protected function formClassNamespace() |
|
| 29 | - { |
|
| 30 | - return 'carono\etxtru\request'; |
|
| 31 | - } |
|
| 25 | + /** |
|
| 26 | + * @return string |
|
| 27 | + */ |
|
| 28 | + protected function formClassNamespace() |
|
| 29 | + { |
|
| 30 | + return 'carono\etxtru\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 | - { |
|
| 41 | + /** |
|
| 42 | + * @return bool |
|
| 43 | + */ |
|
| 44 | + public function methods() |
|
| 45 | + { |
|
| 46 | 46 | |
| 47 | - foreach ($this->params['methods'] as $methodData) { |
|
| 47 | + foreach ($this->params['methods'] as $methodData) { |
|
| 48 | 48 | |
| 49 | - $methodName = formMethodName($methodData['name']); |
|
| 50 | - $method = $this->phpClass->addMethod($methodName); |
|
| 51 | - $method->addComment(stripAndWordWrap($methodData['description'])); |
|
| 52 | - $params = []; |
|
| 53 | - if (count($methodData['params']) > 4) { |
|
| 54 | - $config = new ConfigAbstract(); |
|
| 55 | - $config->renderToFile(array_merge(['api' => $this->params['name']], $methodData)); |
|
| 56 | - $className = '\\' . $config->formClassNamespace() . '\\' . $config->formClassName(); |
|
| 57 | - $method->addParameter('config'); |
|
| 58 | - $method->addComment("@param $className|array \$config"); |
|
| 59 | - $body = <<<PHP |
|
| 49 | + $methodName = formMethodName($methodData['name']); |
|
| 50 | + $method = $this->phpClass->addMethod($methodName); |
|
| 51 | + $method->addComment(stripAndWordWrap($methodData['description'])); |
|
| 52 | + $params = []; |
|
| 53 | + if (count($methodData['params']) > 4) { |
|
| 54 | + $config = new ConfigAbstract(); |
|
| 55 | + $config->renderToFile(array_merge(['api' => $this->params['name']], $methodData)); |
|
| 56 | + $className = '\\' . $config->formClassNamespace() . '\\' . $config->formClassName(); |
|
| 57 | + $method->addParameter('config'); |
|
| 58 | + $method->addComment("@param $className|array \$config"); |
|
| 59 | + $body = <<<PHP |
|
| 60 | 60 | foreach (\$config instanceof \carono\\etxtru\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])) { |
|
| 84 | - $response->renderToFile(['name' => $methodName, 'returns' => $methodData['returns']]); |
|
| 85 | - $className = $response->formClassNamespace() . '\\' . $response->formClassName(); |
|
| 86 | - } else { |
|
| 87 | - $className = 'carono\etxtru\Response'; |
|
| 88 | - } |
|
| 89 | - $method->addComment("@return \\$className|\stdClass"); |
|
| 90 | - $api = $this->params['name'] . '.' . $methodData['name']; |
|
| 91 | - $method->addBody("return \$this->getClient()->getContent('$api', \$params, '$className');"); |
|
| 92 | - } |
|
| 93 | - return false; |
|
| 94 | - } |
|
| 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])) { |
|
| 84 | + $response->renderToFile(['name' => $methodName, 'returns' => $methodData['returns']]); |
|
| 85 | + $className = $response->formClassNamespace() . '\\' . $response->formClassName(); |
|
| 86 | + } else { |
|
| 87 | + $className = 'carono\etxtru\Response'; |
|
| 88 | + } |
|
| 89 | + $method->addComment("@return \\$className|\stdClass"); |
|
| 90 | + $api = $this->params['name'] . '.' . $methodData['name']; |
|
| 91 | + $method->addBody("return \$this->getClient()->getContent('$api', \$params, '$className');"); |
|
| 92 | + } |
|
| 93 | + return false; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - protected static function arrayAsPhpVar($array) |
|
| 97 | - { |
|
| 98 | - $export = []; |
|
| 99 | - foreach ($array as $key => $value) { |
|
| 100 | - $export[] = "'$key' => " . (strpos($value, '$') === false ? "'$value'" : $value); |
|
| 101 | - } |
|
| 102 | - $export = implode(",\n\t", $export); |
|
| 103 | - if ($array) { |
|
| 104 | - $result = "[\n\t$export\n]"; |
|
| 105 | - } else { |
|
| 106 | - $result = '[]'; |
|
| 107 | - } |
|
| 108 | - return $result; |
|
| 109 | - } |
|
| 96 | + protected static function arrayAsPhpVar($array) |
|
| 97 | + { |
|
| 98 | + $export = []; |
|
| 99 | + foreach ($array as $key => $value) { |
|
| 100 | + $export[] = "'$key' => " . (strpos($value, '$') === false ? "'$value'" : $value); |
|
| 101 | + } |
|
| 102 | + $export = implode(",\n\t", $export); |
|
| 103 | + if ($array) { |
|
| 104 | + $result = "[\n\t$export\n]"; |
|
| 105 | + } else { |
|
| 106 | + $result = '[]'; |
|
| 107 | + } |
|
| 108 | + return $result; |
|
| 109 | + } |
|
| 110 | 110 | } |
| 111 | 111 | \ No newline at end of file |
@@ -2,144 +2,144 @@ |
||
| 2 | 2 | |
| 3 | 3 | function parseParamsFromQuery($query) |
| 4 | 4 | { |
| 5 | - $params = []; |
|
| 6 | - foreach ($query as $param) { |
|
| 7 | - if ($parsedParam = parseParams(pq($param)->text())) { |
|
| 8 | - $params[] = $parsedParam; |
|
| 9 | - } |
|
| 10 | - } |
|
| 11 | - return $params; |
|
| 5 | + $params = []; |
|
| 6 | + foreach ($query as $param) { |
|
| 7 | + if ($parsedParam = parseParams(pq($param)->text())) { |
|
| 8 | + $params[] = $parsedParam; |
|
| 9 | + } |
|
| 10 | + } |
|
| 11 | + return $params; |
|
| 12 | 12 | } |
| 13 | 13 | |
| 14 | 14 | function clearFolder($folder) |
| 15 | 15 | { |
| 16 | - $files = glob(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . '*'); |
|
| 17 | - foreach ($files as $file) { |
|
| 18 | - if (is_file($file)) { |
|
| 19 | - @unlink($file); |
|
| 20 | - } |
|
| 21 | - } |
|
| 16 | + $files = glob(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'src' . DIRECTORY_SEPARATOR . $folder . DIRECTORY_SEPARATOR . '*'); |
|
| 17 | + foreach ($files as $file) { |
|
| 18 | + if (is_file($file)) { |
|
| 19 | + @unlink($file); |
|
| 20 | + } |
|
| 21 | + } |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | function stripAndWordWrap($str) |
| 25 | 25 | { |
| 26 | - return wordwrap(stripSpaces($str), 180) . "\n"; |
|
| 26 | + return wordwrap(stripSpaces($str), 180) . "\n"; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | function formParamLine($param) |
| 30 | 30 | { |
| 31 | - return '**' . $param['name'] . '** - ' . stripLines($param['description']); |
|
| 31 | + return '**' . $param['name'] . '** - ' . stripLines($param['description']); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | function stripSpaces($str) |
| 35 | 35 | { |
| 36 | - $str = preg_replace('/[\s]{2,}/', ' ', $str); |
|
| 37 | - return $str; |
|
| 36 | + $str = preg_replace('/[\s]{2,}/', ' ', $str); |
|
| 37 | + return $str; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | function stripLines($str) |
| 41 | 41 | { |
| 42 | - $str = str_replace("\n", ' ', $str); |
|
| 43 | - $str = stripSpaces($str); |
|
| 44 | - return $str; |
|
| 42 | + $str = str_replace("\n", ' ', $str); |
|
| 43 | + $str = stripSpaces($str); |
|
| 44 | + return $str; |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | function formMethodName($str) |
| 48 | 48 | { |
| 49 | - $arr = array_filter(explode('_', $str)); |
|
| 50 | - $arr = array_map('ucfirst', $arr); |
|
| 51 | - $arr[0] = lcfirst($arr[0]); |
|
| 52 | - return implode('', $arr); |
|
| 49 | + $arr = array_filter(explode('_', $str)); |
|
| 50 | + $arr = array_map('ucfirst', $arr); |
|
| 51 | + $arr[0] = lcfirst($arr[0]); |
|
| 52 | + return implode('', $arr); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | function formClassName($str, $clear = ['get_', '_array']) |
| 56 | 56 | { |
| 57 | - foreach ($clear as $item) { |
|
| 58 | - $str = str_ireplace($item, '', $str); |
|
| 59 | - } |
|
| 60 | - $arr = array_filter(explode('_', $str)); |
|
| 61 | - $arr = array_map('ucfirst', $arr); |
|
| 62 | - return implode('', $arr); |
|
| 57 | + foreach ($clear as $item) { |
|
| 58 | + $str = str_ireplace($item, '', $str); |
|
| 59 | + } |
|
| 60 | + $arr = array_filter(explode('_', $str)); |
|
| 61 | + $arr = array_map('ucfirst', $arr); |
|
| 62 | + return implode('', $arr); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | function formParamType($str) |
| 66 | 66 | { |
| 67 | - switch ($str) { |
|
| 68 | - case 'text': |
|
| 69 | - return 'string'; |
|
| 70 | - break; |
|
| 71 | - case 'date': |
|
| 72 | - return 'string Y-m-d'; |
|
| 73 | - break; |
|
| 74 | - case 'datetime': |
|
| 75 | - return 'string Y-m-d H:i:s'; |
|
| 76 | - break; |
|
| 77 | - case 'string': |
|
| 78 | - return 'string'; |
|
| 79 | - break; |
|
| 80 | - case 'int': |
|
| 81 | - return 'int'; |
|
| 82 | - break; |
|
| 83 | - } |
|
| 84 | - return $str; |
|
| 67 | + switch ($str) { |
|
| 68 | + case 'text': |
|
| 69 | + return 'string'; |
|
| 70 | + break; |
|
| 71 | + case 'date': |
|
| 72 | + return 'string Y-m-d'; |
|
| 73 | + break; |
|
| 74 | + case 'datetime': |
|
| 75 | + return 'string Y-m-d H:i:s'; |
|
| 76 | + break; |
|
| 77 | + case 'string': |
|
| 78 | + return 'string'; |
|
| 79 | + break; |
|
| 80 | + case 'int': |
|
| 81 | + return 'int'; |
|
| 82 | + break; |
|
| 83 | + } |
|
| 84 | + return $str; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | function isRequired($text) |
| 88 | 88 | { |
| 89 | - return mb_strpos($text, 'Необязательный', 0, 'utf-8') === false; |
|
| 89 | + return mb_strpos($text, 'Необязательный', 0, 'utf-8') === false; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | function parseParams($str) |
| 93 | 93 | { |
| 94 | - if (preg_match('/^(\w+)\s+\((\w+)\)\s+-\s+(.+)/uis', $str, $m)) { |
|
| 95 | - return [ |
|
| 96 | - 'name' => $m[1], |
|
| 97 | - 'type' => $m[2], |
|
| 98 | - 'description' => $m[3], |
|
| 99 | - 'required' => isRequired($m[3]) |
|
| 100 | - ]; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - return []; |
|
| 94 | + if (preg_match('/^(\w+)\s+\((\w+)\)\s+-\s+(.+)/uis', $str, $m)) { |
|
| 95 | + return [ |
|
| 96 | + 'name' => $m[1], |
|
| 97 | + 'type' => $m[2], |
|
| 98 | + 'description' => $m[3], |
|
| 99 | + 'required' => isRequired($m[3]) |
|
| 100 | + ]; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + return []; |
|
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | function parseReturns($tdHtml) |
| 107 | 107 | { |
| 108 | - $uls = pq($tdHtml)->find('ul'); |
|
| 109 | - if ($uls->count() == 1 && strpos($tdHtml, 'Каждый элемент') !== false) { |
|
| 110 | - if (preg_match('/<td>(.)+<ul>/s', $tdHtml, $m)) { |
|
| 111 | - $ul = "<ul><li>" . trim(strip_tags($m[0])) . "</li></ul>"; |
|
| 112 | - $uls = pq("<td>$ul{$uls->eq(0)->htmlOuter()}</td>")->find('ul'); |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - $count = $uls->count(); |
|
| 116 | - $parsing = parseParamsFromQuery($uls->eq($count == 2 ? 1 : 0)->find('li')); |
|
| 117 | - if ($count == 2) { |
|
| 118 | - $returnParam = parseParams($uls->eq(0)->text()); |
|
| 119 | - $returnParam['result'] = $parsing; |
|
| 120 | - return [$returnParam]; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return $parsing; |
|
| 108 | + $uls = pq($tdHtml)->find('ul'); |
|
| 109 | + if ($uls->count() == 1 && strpos($tdHtml, 'Каждый элемент') !== false) { |
|
| 110 | + if (preg_match('/<td>(.)+<ul>/s', $tdHtml, $m)) { |
|
| 111 | + $ul = "<ul><li>" . trim(strip_tags($m[0])) . "</li></ul>"; |
|
| 112 | + $uls = pq("<td>$ul{$uls->eq(0)->htmlOuter()}</td>")->find('ul'); |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + $count = $uls->count(); |
|
| 116 | + $parsing = parseParamsFromQuery($uls->eq($count == 2 ? 1 : 0)->find('li')); |
|
| 117 | + if ($count == 2) { |
|
| 118 | + $returnParam = parseParams($uls->eq(0)->text()); |
|
| 119 | + $returnParam['result'] = $parsing; |
|
| 120 | + return [$returnParam]; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return $parsing; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | function asTable($array) |
| 127 | 127 | { |
| 128 | - $header = array_shift($array); |
|
| 129 | - $content = "\n\n|" . implode('|', $header) . "\n"; |
|
| 130 | - $content .= preg_replace('/[^\|]/iu', '-', trim($content)) . "\n"; |
|
| 131 | - foreach ($array as $key => $columns) { |
|
| 132 | - $content .= '|' . implode('|', $columns) . "\n"; |
|
| 133 | - } |
|
| 134 | - return $content; |
|
| 128 | + $header = array_shift($array); |
|
| 129 | + $content = "\n\n|" . implode('|', $header) . "\n"; |
|
| 130 | + $content .= preg_replace('/[^\|]/iu', '-', trim($content)) . "\n"; |
|
| 131 | + foreach ($array as $key => $columns) { |
|
| 132 | + $content .= '|' . implode('|', $columns) . "\n"; |
|
| 133 | + } |
|
| 134 | + return $content; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | function asHeader($string, $sub = 1) |
| 138 | 138 | { |
| 139 | - return "\n\n" . str_repeat('#', $sub) . ' ' . $string . "\n\n"; |
|
| 139 | + return "\n\n" . str_repeat('#', $sub) . ' ' . $string . "\n\n"; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | function asCode($code) |
| 143 | 143 | { |
| 144 | - return "`$code`"; |
|
| 144 | + return "`$code`"; |
|
| 145 | 145 | } |
| 146 | 146 | \ No newline at end of file |
@@ -52,37 +52,37 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | $data = json_decode(file_get_contents('data.json'), true); |
| 54 | 54 | $description = [ |
| 55 | - ['Метод', 'Описание'] |
|
| 55 | + ['Метод', 'Описание'] |
|
| 56 | 56 | ]; |
| 57 | 57 | |
| 58 | 58 | foreach ($data as $api => $section) { |
| 59 | - $sectionName = formMethodName($section['name']); |
|
| 60 | - $description[] = ['$client->' . $sectionName . '()', $section['description']]; |
|
| 59 | + $sectionName = formMethodName($section['name']); |
|
| 60 | + $description[] = ['$client->' . $sectionName . '()', $section['description']]; |
|
| 61 | 61 | |
| 62 | - $sectionData[] = asHeader($section['description']); |
|
| 63 | - $sectionData[] = <<<HTML |
|
| 62 | + $sectionData[] = asHeader($section['description']); |
|
| 63 | + $sectionData[] = <<<HTML |
|
| 64 | 64 | ```php |
| 65 | 65 | \$client->{$sectionName}(); |
| 66 | 66 | ``` |
| 67 | 67 | |
| 68 | 68 | HTML; |
| 69 | - $sectionData[] = asHeader('Доступные методы', 2); |
|
| 70 | - foreach ($section['methods'] as $method) { |
|
| 71 | - $sectionData[] = '**' . $method['name'] . '** - ' . $method['description']; |
|
| 72 | - |
|
| 73 | - |
|
| 74 | - if (count($method['params']) > 4) { |
|
| 75 | - $params = '$config'; |
|
| 76 | - } else { |
|
| 77 | - $params = []; |
|
| 78 | - foreach ($method['params'] as $param) { |
|
| 79 | - $params[] = '$' . $param['name']; |
|
| 80 | - } |
|
| 81 | - $params = implode(', ', $params); |
|
| 82 | - } |
|
| 83 | - $methodName = formMethodName($method['name']); |
|
| 84 | - |
|
| 85 | - $sectionData[] = <<<HTML |
|
| 69 | + $sectionData[] = asHeader('Доступные методы', 2); |
|
| 70 | + foreach ($section['methods'] as $method) { |
|
| 71 | + $sectionData[] = '**' . $method['name'] . '** - ' . $method['description']; |
|
| 72 | + |
|
| 73 | + |
|
| 74 | + if (count($method['params']) > 4) { |
|
| 75 | + $params = '$config'; |
|
| 76 | + } else { |
|
| 77 | + $params = []; |
|
| 78 | + foreach ($method['params'] as $param) { |
|
| 79 | + $params[] = '$' . $param['name']; |
|
| 80 | + } |
|
| 81 | + $params = implode(', ', $params); |
|
| 82 | + } |
|
| 83 | + $methodName = formMethodName($method['name']); |
|
| 84 | + |
|
| 85 | + $sectionData[] = <<<HTML |
|
| 86 | 86 | |
| 87 | 87 | ```php |
| 88 | 88 | \$client->{$sectionName}()->{$methodName}($params); |
@@ -91,24 +91,24 @@ discard block |
||
| 91 | 91 | HTML; |
| 92 | 92 | |
| 93 | 93 | |
| 94 | - $sectionData[] = ''; |
|
| 95 | - if ($method['params']) { |
|
| 96 | - $sectionData[] = asHeader('Входные параметры', 4); |
|
| 97 | - $params = [['Параметр', 'Тип', 'Описание']]; |
|
| 98 | - foreach ($method['params'] as $param) { |
|
| 99 | - $params[] = [$param['name'], $param['type'], stripLines($param['description'])]; |
|
| 100 | - } |
|
| 101 | - $sectionData[] = asTable($params); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $sectionData[] = asHeader('Результат', 4); |
|
| 105 | - $params = [['Параметр', 'Описание']]; |
|
| 106 | - foreach ($method['returns'] as $param) { |
|
| 107 | - $params[] = [$param['name'], stripLines($param['description'])]; |
|
| 108 | - } |
|
| 109 | - $sectionData[] = asTable($params); |
|
| 110 | - $sectionData[] = "\n\n***\n\n"; |
|
| 111 | - } |
|
| 94 | + $sectionData[] = ''; |
|
| 95 | + if ($method['params']) { |
|
| 96 | + $sectionData[] = asHeader('Входные параметры', 4); |
|
| 97 | + $params = [['Параметр', 'Тип', 'Описание']]; |
|
| 98 | + foreach ($method['params'] as $param) { |
|
| 99 | + $params[] = [$param['name'], $param['type'], stripLines($param['description'])]; |
|
| 100 | + } |
|
| 101 | + $sectionData[] = asTable($params); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $sectionData[] = asHeader('Результат', 4); |
|
| 105 | + $params = [['Параметр', 'Описание']]; |
|
| 106 | + foreach ($method['returns'] as $param) { |
|
| 107 | + $params[] = [$param['name'], stripLines($param['description'])]; |
|
| 108 | + } |
|
| 109 | + $sectionData[] = asTable($params); |
|
| 110 | + $sectionData[] = "\n\n***\n\n"; |
|
| 111 | + } |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | file_put_contents('../README.md', trim(implode('', $sectionData))); |
@@ -8,72 +8,72 @@ |
||
| 8 | 8 | |
| 9 | 9 | class Client extends ClientAbstract |
| 10 | 10 | { |
| 11 | - public $apiKey; |
|
| 12 | - public $url = 'www.etxt.ru/api/json'; |
|
| 13 | - public $method = 'POST'; |
|
| 14 | - public $type = self::TYPE_MULTIPART; |
|
| 15 | - public $output_type = self::TYPE_JSON; |
|
| 11 | + public $apiKey; |
|
| 12 | + public $url = 'www.etxt.ru/api/json'; |
|
| 13 | + public $method = 'POST'; |
|
| 14 | + public $type = self::TYPE_MULTIPART; |
|
| 15 | + public $output_type = self::TYPE_JSON; |
|
| 16 | 16 | |
| 17 | - protected function sign($method) |
|
| 18 | - { |
|
| 19 | - $baseParamsArr = [ |
|
| 20 | - 'token' => $this->apiKey, |
|
| 21 | - 'method' => $method |
|
| 22 | - ]; |
|
| 23 | - ksort($baseParamsArr); |
|
| 24 | - $params = ''; |
|
| 25 | - foreach ($baseParamsArr as $key => $val) { |
|
| 26 | - $params .= ($key . '=' . $val); |
|
| 27 | - } |
|
| 28 | - return md5($params . md5($this->password . 'api-pass')); |
|
| 29 | - } |
|
| 17 | + protected function sign($method) |
|
| 18 | + { |
|
| 19 | + $baseParamsArr = [ |
|
| 20 | + 'token' => $this->apiKey, |
|
| 21 | + 'method' => $method |
|
| 22 | + ]; |
|
| 23 | + ksort($baseParamsArr); |
|
| 24 | + $params = ''; |
|
| 25 | + foreach ($baseParamsArr as $key => $val) { |
|
| 26 | + $params .= ($key . '=' . $val); |
|
| 27 | + } |
|
| 28 | + return md5($params . md5($this->password . 'api-pass')); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @param $urlRequest |
|
| 33 | - * @param array $data |
|
| 34 | - * @param string $responseClass |
|
| 35 | - * @return mixed |
|
| 36 | - */ |
|
| 37 | - public function getContent($urlRequest, $data = [], $responseClass = Response::class) |
|
| 38 | - { |
|
| 39 | - try { |
|
| 40 | - $method = $urlRequest; |
|
| 41 | - $sign = $this->sign($method); |
|
| 42 | - $urlRequest = '?' . build_query(['token' => $this->apiKey, 'method' => $method, 'sign' => $sign]); |
|
| 43 | - $content = parent::getContent($urlRequest, $data); |
|
| 44 | - return self::stdClassToResponse($content, $responseClass); |
|
| 45 | - } catch (\Exception $e) { |
|
| 31 | + /** |
|
| 32 | + * @param $urlRequest |
|
| 33 | + * @param array $data |
|
| 34 | + * @param string $responseClass |
|
| 35 | + * @return mixed |
|
| 36 | + */ |
|
| 37 | + public function getContent($urlRequest, $data = [], $responseClass = Response::class) |
|
| 38 | + { |
|
| 39 | + try { |
|
| 40 | + $method = $urlRequest; |
|
| 41 | + $sign = $this->sign($method); |
|
| 42 | + $urlRequest = '?' . build_query(['token' => $this->apiKey, 'method' => $method, 'sign' => $sign]); |
|
| 43 | + $content = parent::getContent($urlRequest, $data); |
|
| 44 | + return self::stdClassToResponse($content, $responseClass); |
|
| 45 | + } catch (\Exception $e) { |
|
| 46 | 46 | if ($this->request){ |
| 47 | - $this->request->getBody()->rewind(); |
|
| 47 | + $this->request->getBody()->rewind(); |
|
| 48 | 48 | } |
| 49 | - $response = new Response(); |
|
| 50 | - $response->success = false; |
|
| 51 | - $response->error = $this->request ? $this->request->getBody()->getContents() : $e->getMessage(); |
|
| 52 | - return $response; |
|
| 53 | - } |
|
| 54 | - } |
|
| 49 | + $response = new Response(); |
|
| 50 | + $response->success = false; |
|
| 51 | + $response->error = $this->request ? $this->request->getBody()->getContents() : $e->getMessage(); |
|
| 52 | + return $response; |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @param $stdClass |
|
| 58 | - * @param $responseClass |
|
| 59 | - * @return ResponseAbstract |
|
| 60 | - */ |
|
| 61 | - protected static function stdClassToResponse($stdClass, $responseClass) |
|
| 62 | - { |
|
| 63 | - /** |
|
| 64 | - * @var ResponseAbstract $response |
|
| 65 | - */ |
|
| 66 | - $response = new $responseClass(); |
|
| 67 | - foreach ($stdClass as $key => $value) { |
|
| 68 | - if (is_array($value) && method_exists($response, 'getResponseClass') && ($class = $response->getResponseClass($key))) { |
|
| 69 | - foreach ($value as $item) { |
|
| 70 | - $response->{$key}[] = self::stdClassToResponse($item, $class); |
|
| 71 | - } |
|
| 72 | - } else { |
|
| 73 | - $response->$key = $value; |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - $response->success = !(bool)$response->error; |
|
| 77 | - return $response; |
|
| 78 | - } |
|
| 56 | + /** |
|
| 57 | + * @param $stdClass |
|
| 58 | + * @param $responseClass |
|
| 59 | + * @return ResponseAbstract |
|
| 60 | + */ |
|
| 61 | + protected static function stdClassToResponse($stdClass, $responseClass) |
|
| 62 | + { |
|
| 63 | + /** |
|
| 64 | + * @var ResponseAbstract $response |
|
| 65 | + */ |
|
| 66 | + $response = new $responseClass(); |
|
| 67 | + foreach ($stdClass as $key => $value) { |
|
| 68 | + if (is_array($value) && method_exists($response, 'getResponseClass') && ($class = $response->getResponseClass($key))) { |
|
| 69 | + foreach ($value as $item) { |
|
| 70 | + $response->{$key}[] = self::stdClassToResponse($item, $class); |
|
| 71 | + } |
|
| 72 | + } else { |
|
| 73 | + $response->$key = $value; |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + $response->success = !(bool)$response->error; |
|
| 77 | + return $response; |
|
| 78 | + } |
|
| 79 | 79 | } |
| 80 | 80 | \ No newline at end of file |
@@ -43,7 +43,7 @@ |
||
| 43 | 43 | $content = parent::getContent($urlRequest, $data); |
| 44 | 44 | return self::stdClassToResponse($content, $responseClass); |
| 45 | 45 | } catch (\Exception $e) { |
| 46 | - if ($this->request){ |
|
| 46 | + if ($this->request) { |
|
| 47 | 47 | $this->request->getBody()->rewind(); |
| 48 | 48 | } |
| 49 | 49 | $response = new Response(); |