| 1 |  |  | <?php | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 3 |  |  | function parseParamsFromQuery($query) | 
            
                                                                        
                            
            
                                    
            
            
                | 4 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 5 |  |  |     $params = []; | 
            
                                                                        
                            
            
                                    
            
            
                | 6 |  |  |     foreach ($query as $param) { | 
            
                                                                        
                            
            
                                    
            
            
                | 7 |  |  |         if ($parsedParam = parseParams(pq($param)->text())) { | 
            
                                                                        
                            
            
                                    
            
            
                | 8 |  |  |             $params[] = $parsedParam; | 
            
                                                                        
                            
            
                                    
            
            
                | 9 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 10 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 11 |  |  |     return $params; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | function clearFolder($folder) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | function stripAndWordWrap($str) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     return wordwrap(stripSpaces($str), 180) . "\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | function formParamLine($param) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     return '**' . $param['name'] . "** ({$param['type']}) - " . stripLines($param['description']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | function stripSpaces($str) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     $str = preg_replace('/[\s]{2,}/', " ", $str); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     return $str; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | function stripLines($str) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     $str = str_replace("\n", " ", $str); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     $str = stripSpaces($str); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     return $str; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | function formMethodName($str) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     $arr = array_filter(explode('_', $str)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     $arr = array_map('ucfirst', $arr); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     $arr[0] = lcfirst($arr[0]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     return join('', $arr); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  | function formClassName($str, $clear = ['get_', '_array']) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 join('', $arr); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | function formParamType($str) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 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 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |     return $str; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | function parseParams($str) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     if (preg_match('/^(\w+)\s+\((\w+)\)\s+-\s+(.+)/uis', $str, $m)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |             'name' => $m[1], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |             'type' => $m[2], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |             'description' => $m[3], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |             'required' => mb_strpos($m[3], 'Необязательный', 0, 'utf-8') === false | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         return []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | function parseReturns($tdHtml) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     $uls = pq($tdHtml)->find('ul'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     if ($uls->count() == 1 && strpos($tdHtml, 'Каждый элемент') !== false) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         if (preg_match('/<td>(.)+<ul>/s', $tdHtml, $m)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |             $ul = "<ul><li>" . trim(strip_tags($m[0])) . "</li></ul>"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |             $uls = pq("<td>$ul{$uls->eq(0)->htmlOuter()}</td>")->find('ul'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |     $count = $uls->count(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     $parsing = parseParamsFromQuery($uls->eq($count == 2 ? 1 : 0)->find('li')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     if ($count == 2) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         $returnParam = parseParams($uls->eq(0)->text()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |         $returnParam['result'] = $parsing; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         return [$returnParam]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     } else { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         return $parsing; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  | function asTable($array) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |     $header = array_shift($array); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     $content = "\n\n|" . join("|", $header) . "\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     $content .= preg_replace('/[^\|]/iu', '-', trim($content)) . "\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     foreach ($array as $key => $columns) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |         $content .= "|" . join("|", $columns) . "\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     return $content; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  | function asHeader($string) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |     return "\n\n" . $string . "\n" . str_repeat('=', mb_strlen($string, 'utf-8')) . "\n"; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  | } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  | function asCode($code) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  | { | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 133 |  |  |     return "`$code`"; | 
            
                                                        
            
                                    
            
            
                | 134 |  |  | } | 
            
                        
If you suppress an error, we recommend checking for the error condition explicitly: