1+ <?php
2+
3+ namespace Codeeshop \DocumentPHP ;
4+
5+ require_once '../../vendor/autoload.php ' ;
6+
7+ include_once '/opt/lampp/htdocs/myshop1/system/engine/controller.php ' ;
8+
9+ error_reporting (E_ALL ^ E_NOTICE ^ E_WARNING );
10+
11+ class FetchFiles {
12+ public $ data = [];
13+ public $ destination_path = '/opt/lampp/htdocs/myshop1/catalog/controller/api/ ' ;
14+
15+ function rrmdir ($ dir ) {
16+ // return;
17+ if (is_dir ($ dir )) {
18+ $ objects = scandir ($ dir );
19+
20+ foreach ($ objects as $ object ) {
21+ if ($ object != '. ' && $ object != '.. ' ) {
22+ if (filetype ($ dir . '/ ' . $ object ) == 'dir ' ) {$ this ->rrmdir ($ dir . '/ ' . $ object );} else {unlink ($ dir . '/ ' . $ object );}
23+ }
24+ }
25+
26+ reset ($ objects );
27+ // rmdir($dir);
28+ }
29+ }
30+
31+ function recursive_copy ($ src , $ dst ) {
32+ if (is_dir ($ src )) {
33+ $ dir = opendir ($ src );
34+
35+ while (($ file = readdir ($ dir ))) {
36+ if ((substr ($ file , -1 ) != '_ ' ) && ($ file != '. ' ) && ($ file != '.. ' )) {
37+ if (is_dir ($ src . '/ ' . $ file )) {
38+ $ this ->recursive_copy ($ src . '/ ' . $ file , $ dst . '/ ' . $ file );
39+ } else {
40+ if (is_file ($ this ->destination_path . $ file )) {
41+ $ this ->start_processing ($ this ->destination_path . $ file );
42+ // print_r($this->destination_path . $file);
43+ }
44+ // die;
45+ // copy($src . '/' . $file, $dst . '/' . $file);
46+ }
47+ }
48+ }
49+ closedir ($ dir );
50+
51+ return ;
52+ } elseif (is_file ($ src )) {
53+ $ dir = substr ($ dst , 0 , strrpos ($ dst , '/ ' ));
54+ // mkdir($dir, 0777, true);
55+
56+ print_r ($ src );die;
57+ // copy($src, $dst);
58+ } else {
59+ die ('<strong>Not found : </strong> ' . $ src );
60+ // print_r($src);die;
61+ }
62+ }
63+
64+ function get_function ($ method , $ class = null ) {
65+
66+ if (!empty ($ class )) {
67+ $ func = new ReflectionMethod ($ class , $ method );
68+ } else {
69+ $ func = new ReflectionFunction ($ method );
70+ }
71+
72+ $ f = $ func ->getFileName ();
73+ $ start_line = $ func ->getStartLine () - 1 ;
74+ $ end_line = $ func ->getEndLine ();
75+ $ length = $ end_line - $ start_line ;
76+
77+ $ source = file ($ f );
78+ $ source = implode ('' , array_slice ($ source , 0 , count ($ source )));
79+ $ source = preg_split ("/ " . PHP_EOL . "/ " , $ source );
80+
81+ $ body = '' ;
82+ for ($ i = $ start_line ; $ i < $ end_line ; $ i ++) {
83+ $ body .= "{$ source [$ i ]}\n" ;
84+ }
85+
86+ return $ body ;
87+ }
88+
89+ function start_processing ($ file ) {
90+ include_once $ file ;
91+
92+ $ start = strpos ($ file , 'controller ' ) + strlen ('controller ' );
93+ $ end = strpos ($ file , '.php ' ) - $ start ;
94+ $ route = substr ($ file , $ start , $ end );
95+ $ class_name = 'Controller ' . preg_replace ('/[^a-zA-Z0-9]/ ' , '' , $ route );
96+ $ myclass = new $ class_name ([]);
97+ $ class_methods = get_class_methods ($ myclass );
98+ $ class_vars = get_class_vars (get_class ($ myclass ));
99+
100+ $ current_data = [];
101+
102+ // echo "<pre>";
103+ foreach ($ class_methods as $ method_name ) {
104+ $ function_string = $ this ->get_function ($ method_name , $ myclass );
105+
106+ if ($ this ->isReturningJSONResponse ($ function_string )) {
107+ $ method_types_vars = $ this ->findMethodTypesVars ($ function_string );
108+ $ current_method_type = empty ($ method_types_vars ['POST ' ]) ? 'GET ' : 'POST ' ;
109+
110+ $ current_data [] = [
111+ 'full_route ' => $ route . ($ method_name == 'index ' ? '' : ('/ ' . $ method_name )),
112+ 'current_method_type ' => $ current_method_type ,
113+ 'route ' => $ route ,
114+ 'method_name ' => $ method_name ,
115+ 'method_types_vars ' => $ method_types_vars ,
116+ 'file ' => $ file ,
117+ ];
118+ }
119+ }
120+
121+ $ this ->data [$ class_name ] = $ current_data ;
122+ // print_r($this->data);
123+ // echo "</pre>";
124+ }
125+
126+ function findMethodTypesVars ($ function_string = '' ) {
127+ $ method_types = [];
128+ $ method_types ['POST ' ] = $ this ->getParams ($ function_string , "/->post\[/i " , ['->post[ ' , '\'' ], '' );
129+ $ method_types ['GET ' ] = $ this ->getParams ($ function_string , "/->get\[/i " , ['->get[ ' , '\'' ], '' );
130+ return $ method_types ;
131+ }
132+
133+ function isReturningJSONResponse ($ function_string = '' ) {
134+ preg_match_all ("/setOutput\(/i " , $ function_string , $ matches );
135+
136+ return !empty ($ matches [0 ]) ? true : false ;
137+ }
138+ function getParams ($ function_string , $ pattern , $ find , $ replace = '' ) {
139+ preg_match_all ($ pattern , $ function_string , $ matches , PREG_OFFSET_CAPTURE );
140+
141+ $ var_names = [];
142+ foreach ($ matches [0 ] as $ key => $ value ) {
143+ $ strpos = strpos (substr ($ function_string , $ value [1 ], strlen ($ function_string )), '] ' );
144+ $ var_name = str_replace ($ find , $ replace , substr ($ function_string , $ value [1 ], $ strpos ));
145+
146+ $ var_names [] = $ var_name ;
147+ }
148+
149+ return array_unique ($ var_names );
150+ }
151+ }
152+
153+ ?>
0 commit comments