Browse Source

Add install step for dependencies

Maurits van der Schee 5 years ago
parent
commit
52ea4aa8dd
5 changed files with 70 additions and 50 deletions
  1. 4
    0
      README.md
  2. 4
    2
      build.php
  3. 11
    0
      install.php
  4. 50
    0
      patch.php
  5. 1
    48
      update.php

+ 4
- 0
README.md View File

@@ -119,6 +119,10 @@ The following features are supported:
119 119
 
120 120
 ## Compilation
121 121
 
122
+You can install all dependencies of this project using the following command:
123
+
124
+    php install.php
125
+
122 126
 You can compile all files into a single "`api.php`" file using:
123 127
 
124 128
     php build.php

+ 4
- 2
build.php View File

@@ -1,5 +1,7 @@
1 1
 <?php
2 2
 
3
+// combine src and vendor directories into a single file
4
+
3 5
 function removeIgnored(string $dir, array &$entries, array $ignore)
4 6
 {
5 7
     foreach ($entries as $i => $entry) {
@@ -34,8 +36,8 @@ function runDir(string $base, string $dir, array &$lines, array $ignore): int
34 36
             $data = preg_replace('/\s*<\?php\s+/s', '', $data, 1);
35 37
             $data = preg_replace('/^.*?(vendor\/autoload|declare\s*\(\s*strict_types\s*=\s*1).*?$/m', '', $data);
36 38
             array_push($lines, "// file: $dir/$entry");
37
-            if (!preg_match('/^\s*(namespace[^;]*);/', $data)){
38
-                $data = "namespace;\n".$data;
39
+            if (!preg_match('/^\s*(namespace[^;]*);/', $data)) {
40
+                $data = "namespace;\n" . $data;
39 41
             }
40 42
             foreach (explode("\n", trim($data)) as $line) {
41 43
                 if ($line) {

+ 11
- 0
install.php View File

@@ -0,0 +1,11 @@
1
+<?php
2
+
3
+// download composer and install dependencies
4
+
5
+if (!file_exists('composer.phar')) {
6
+    $composer = file_get_contents('https://getcomposer.org/composer.phar');
7
+    file_put_contents('composer.phar', $composer);
8
+}
9
+exec('php composer.phar install');
10
+
11
+include 'patch.php';

+ 50
- 0
patch.php View File

@@ -0,0 +1,50 @@
1
+<?php
2
+
3
+// patch files for PHP 7.0 compatibility
4
+
5
+function patchDir(string $base, string $dir): int
6
+{
7
+    $count = 0;
8
+    $entries = scandir($dir);
9
+    foreach ($entries as $entry) {
10
+        if ($entry === '.' || $entry === '..') {
11
+            continue;
12
+        }
13
+        $filename = "$base/$dir/$entry";
14
+        if (is_dir($filename)) {
15
+            $count += patchDir($base, "$dir/$entry");
16
+        }
17
+    }
18
+    foreach ($entries as $entry) {
19
+        $filename = "$base/$dir/$entry";
20
+        if (is_file($filename)) {
21
+            if (substr($entry, -4) != '.php') {
22
+                continue;
23
+            }
24
+            $patched = $original = file_get_contents($filename);
25
+            $patched = preg_replace('/\):\s*(\?[a-zA-Z]+|void)\s*\n/', ") /*:$1*/\n", $patched);
26
+            $patched = preg_replace('/(private|public|protected) const/', "/*$1*/ const", $patched);
27
+            if ($patched && $patched != $original) {
28
+                file_put_contents($filename, $patched);
29
+                $count++;
30
+            }
31
+        }
32
+    }
33
+    return $count;
34
+}
35
+
36
+function patch(string $base, array $dirs)
37
+{
38
+    $start = microtime(true);
39
+    $count = 0;
40
+    foreach ($dirs as $dir) {
41
+        $count += patchDir($base, $dir);
42
+    }
43
+    $end = microtime(true);
44
+    $time = ($end - $start) * 1000;
45
+    if ($count) {
46
+        fwrite(STDERR, sprintf("%d files patched in %d ms\n", $count, $time));
47
+    }
48
+}
49
+
50
+patch(__DIR__, ['vendor']);

+ 1
- 48
update.php View File

@@ -8,51 +8,4 @@ if (!file_exists('composer.phar')) {
8 8
 }
9 9
 exec('php composer.phar update');
10 10
 
11
-// patch files for PHP 7.0 compatibility
12
-
13
-function patchDir(string $base, string $dir): int
14
-{
15
-    $count = 0;
16
-    $entries = scandir($dir);
17
-    foreach ($entries as $entry) {
18
-        if ($entry === '.' || $entry === '..') {
19
-            continue;
20
-        }
21
-        $filename = "$base/$dir/$entry";
22
-        if (is_dir($filename)) {
23
-            $count += patchDir($base, "$dir/$entry");
24
-        }
25
-    }
26
-    foreach ($entries as $entry) {
27
-        $filename = "$base/$dir/$entry";
28
-        if (is_file($filename)) {
29
-            if (substr($entry, -4) != '.php') {
30
-                continue;
31
-            }
32
-            $patched = $original = file_get_contents($filename);
33
-            $patched = preg_replace('/\):\s*(\?[a-zA-Z]+|void)\s*\n/', ") /*:$1*/\n", $patched);
34
-            $patched = preg_replace('/(private|public|protected) const/', "/*$1*/ const", $patched);
35
-            if ($patched && $patched != $original) {
36
-                file_put_contents($filename, $patched);
37
-                $count++;
38
-            }
39
-        }
40
-    }
41
-    return $count;
42
-}
43
-
44
-function patch(string $base, array $dirs)
45
-{
46
-    $start = microtime(true);
47
-    $count = 0;
48
-    foreach ($dirs as $dir) {
49
-        $count += patchDir($base, $dir);
50
-    }
51
-    $end = microtime(true);
52
-    $time = ($end - $start) * 1000;
53
-    if ($count) {
54
-        fwrite(STDERR, sprintf("%d files patched in %d ms\n", $count, $time));
55
-    }
56
-}
57
-
58
-patch(__DIR__, ['vendor']);
11
+include 'patch.php';

Loading…
Cancel
Save