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,34 +9,19 @@ function removeIgnored(string $dir, array &$entries, array $ignore)
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 14
     $count = 0;
30 15
     $entries = scandir($dir);
31 16
     removeIgnored($dir, $entries, $ignore);
32
-    prioritySort($dir, $entries, $priority);
17
+    sort($entries);
33 18
     foreach ($entries as $entry) {
34 19
         if ($entry === '.' || $entry === '..') {
35 20
             continue;
36 21
         }
37 22
         $filename = "$base/$dir/$entry";
38 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 27
     foreach ($entries as $entry) {
@@ -46,13 +31,18 @@ function runDir(string $base, string $dir, array &$lines, array $ignore, array $
46 31
                 continue;
47 32
             }
48 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 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 46
             $count++;
57 47
         }
58 48
     }
@@ -75,24 +65,21 @@ function addHeader(array &$lines)
75 65
  *   https://github.com/Nyholm
76 66
  **/
77 67
 
78
-namespace Tqdev\PhpCrudApi;
79
-
80 68
 EOF;
81 69
     foreach (explode("\n", $head) as $line) {
82 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 76
     $lines = [];
89 77
     $start = microtime(true);
90 78
     addHeader($lines);
91 79
     $ignore = array_flip($ignore);
92
-    $priority = array_flip($priority);
93 80
     $count = 0;
94 81
     foreach ($dirs as $dir) {
95
-        $count += runDir($base, $dir, $lines, $ignore, $priority);
82
+        $count += runDir($base, $dir, $lines, $ignore);
96 83
     }
97 84
     $data = implode("\n", $lines);
98 85
     $data = preg_replace('/\n({)?\s*\n\s*\n/', "\n$1\n", $data);
@@ -107,14 +94,7 @@ function run(string $base, array $dirs, string $filename, array $ignore, array $
107 94
 }
108 95
 
109 96
 $ignore = [
110
-    'vendor/autoload.php',
111
-    'vendor/composer',
112
-    'vendor/php-http',
113 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,4 +1,6 @@
1 1
 <?php
2
+namespace Tqdev\PhpCrudApi;
3
+
2 4
 use Tqdev\PhpCrudApi\Api;
3 5
 use Tqdev\PhpCrudApi\Config;
4 6
 use Tqdev\PhpCrudApi\RequestFactory;

Loading…
Cancel
Save