Browse Source

Use namespaces in build

Maurits van der Schee 5 years ago
parent
commit
de5e1f8ef3
3 changed files with 8380 additions and 6313 deletions
  1. 8367
    6292
      api.php
  2. 11
    21
      build.php
  3. 2
    0
      src/index.php

+ 8367
- 6292
api.php
File diff suppressed because it is too large
View File


+ 11
- 21
build.php View File

9
     }
9
     }
10
 }
10
 }
11
 
11
 
12
-function prioritySort(string $dir, array &$entries)
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): 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);
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;
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 = trim(preg_replace('/\s*<\?php\s+/s', '', $data, 1));
50
             array_push($lines, "// file: $dir/$entry");
35
             array_push($lines, "// file: $dir/$entry");
51
             foreach (explode("\n", $data) as $line) {
36
             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
+                if (preg_match('/vendor\/autoload|declare\s*\(\s*strict_types\s*=\s*1/', $line)) {
38
+                    continue;
39
+                }
40
+                if ($line) {
41
+                    $line = '    ' . $line;
54
                 }
42
                 }
43
+                $line = preg_replace('/^\s*(namespace[^;]+);/', '\1 {', $line);
44
+                array_push($lines, $line);
55
             }
45
             }
46
+            array_push($lines, '}');
47
+            array_push($lines, '');
56
             $count++;
48
             $count++;
57
         }
49
         }
58
     }
50
     }
75
  *   https://github.com/Nyholm
67
  *   https://github.com/Nyholm
76
  **/
68
  **/
77
 
69
 
78
-namespace Tqdev\PhpCrudApi;
79
-
80
 EOF;
70
 EOF;
81
     foreach (explode("\n", $head) as $line) {
71
     foreach (explode("\n", $head) as $line) {
82
         array_push($lines, $line);
72
         array_push($lines, $line);

+ 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