Browse Source

Merge branch 'master' of github.com:mevdschee/php-crud-api

Maurits van der Schee 5 years ago
parent
commit
305e9a181f
3 changed files with 8369 additions and 6319 deletions
  1. 8352
    6284
      api.php
  2. 15
    35
      build.php
  3. 2
    0
      src/index.php

+ 8352
- 6284
api.php
File diff suppressed because it is too large
View File


+ 15
- 35
build.php View File

9
     }
9
     }
10
 }
10
 }
11
 
11
 
12
-function prioritySort(string $dir, array &$entries, array $priority)
13
-{
14
-    $first = array();
15
-    foreach ($entries as $i => $entry) {
16
-        if (isset($priority[$dir . '/' . $entry])) {
17
-            array_push($first, $entry);
18
-            unset($entries[$i]);
19
-        }
20
-    }
21
-    sort($entries);
22
-    foreach ($first as $entry) {
23
-        array_unshift($entries, $entry);
24
-    }
25
-}
26
-
27
-function runDir(string $base, string $dir, array &$lines, array $ignore, array $priority): int
12
+function runDir(string $base, string $dir, array &$lines, array $ignore): int
28
 {
13
 {
29
     $count = 0;
14
     $count = 0;
30
     $entries = scandir($dir);
15
     $entries = scandir($dir);
31
     removeIgnored($dir, $entries, $ignore);
16
     removeIgnored($dir, $entries, $ignore);
32
-    prioritySort($dir, $entries, $priority);
17
+    sort($entries);
33
     foreach ($entries as $entry) {
18
     foreach ($entries as $entry) {
34
         if ($entry === '.' || $entry === '..') {
19
         if ($entry === '.' || $entry === '..') {
35
             continue;
20
             continue;
36
         }
21
         }
37
         $filename = "$base/$dir/$entry";
22
         $filename = "$base/$dir/$entry";
38
         if (is_dir($filename)) {
23
         if (is_dir($filename)) {
39
-            $count += runDir($base, "$dir/$entry", $lines, $ignore, $priority);
24
+            $count += runDir($base, "$dir/$entry", $lines, $ignore);
40
         }
25
         }
41
     }
26
     }
42
     foreach ($entries as $entry) {
27
     foreach ($entries as $entry) {
46
                 continue;
31
                 continue;
47
             }
32
             }
48
             $data = file_get_contents($filename);
33
             $data = file_get_contents($filename);
49
-            $data = preg_replace('|/\*\*.*?\*/|s', '', $data);
34
+            $data = preg_replace('/\s*<\?php\s+/s', '', $data, 1);
35
+            $data = preg_replace('/^.*?(vendor\/autoload|declare\s*\(\s*strict_types\s*=\s*1).*?$/m', '', $data);
50
             array_push($lines, "// file: $dir/$entry");
36
             array_push($lines, "// file: $dir/$entry");
51
-            foreach (explode("\n", $data) as $line) {
52
-                if (!preg_match('/^<\?php|^namespace |^use |vendor\/autoload|declare\s*\(\s*strict_types\s*=\s*1|^\s*\/\//', $line)) {
53
-                    array_push($lines, $line);
37
+            foreach (explode("\n", trim($data)) as $line) {
38
+                if ($line) {
39
+                    $line = '    ' . $line;
54
                 }
40
                 }
41
+                $line = preg_replace('/^\s*(namespace[^;]+);/', '\1 {', $line);
42
+                array_push($lines, $line);
55
             }
43
             }
44
+            array_push($lines, '}');
45
+            array_push($lines, '');
56
             $count++;
46
             $count++;
57
         }
47
         }
58
     }
48
     }
75
  *   https://github.com/Nyholm
65
  *   https://github.com/Nyholm
76
  **/
66
  **/
77
 
67
 
78
-namespace Tqdev\PhpCrudApi;
79
-
80
 EOF;
68
 EOF;
81
     foreach (explode("\n", $head) as $line) {
69
     foreach (explode("\n", $head) as $line) {
82
         array_push($lines, $line);
70
         array_push($lines, $line);
83
     }
71
     }
84
 }
72
 }
85
 
73
 
86
-function run(string $base, array $dirs, string $filename, array $ignore, array $priority)
74
+function run(string $base, array $dirs, string $filename, array $ignore)
87
 {
75
 {
88
     $lines = [];
76
     $lines = [];
89
     $start = microtime(true);
77
     $start = microtime(true);
90
     addHeader($lines);
78
     addHeader($lines);
91
     $ignore = array_flip($ignore);
79
     $ignore = array_flip($ignore);
92
-    $priority = array_flip($priority);
93
     $count = 0;
80
     $count = 0;
94
     foreach ($dirs as $dir) {
81
     foreach ($dirs as $dir) {
95
-        $count += runDir($base, $dir, $lines, $ignore, $priority);
82
+        $count += runDir($base, $dir, $lines, $ignore);
96
     }
83
     }
97
     $data = implode("\n", $lines);
84
     $data = implode("\n", $lines);
98
     $data = preg_replace('/\n({)?\s*\n\s*\n/', "\n$1\n", $data);
85
     $data = preg_replace('/\n({)?\s*\n\s*\n/', "\n$1\n", $data);
107
 }
94
 }
108
 
95
 
109
 $ignore = [
96
 $ignore = [
110
-    'vendor/autoload.php',
111
-    'vendor/composer',
112
-    'vendor/php-http',
113
     'vendor/nyholm/psr7/src/Factory/HttplugFactory.php',
97
     'vendor/nyholm/psr7/src/Factory/HttplugFactory.php',
114
 ];
98
 ];
115
 
99
 
116
-$priority = [
117
-    'vendor/psr',
118
-];
119
-
120
-run(__DIR__, ['vendor', 'src'], 'api.php', $ignore, $priority);
100
+run(__DIR__, ['vendor/psr', 'vendor/nyholm', 'src'], 'api.php', $ignore);

+ 2
- 0
src/index.php View File

1
 <?php
1
 <?php
2
+namespace Tqdev\PhpCrudApi;
3
+
2
 use Tqdev\PhpCrudApi\Api;
4
 use Tqdev\PhpCrudApi\Api;
3
 use Tqdev\PhpCrudApi\Config;
5
 use Tqdev\PhpCrudApi\Config;
4
 use Tqdev\PhpCrudApi\RequestFactory;
6
 use Tqdev\PhpCrudApi\RequestFactory;

Loading…
Cancel
Save