-
Notifications
You must be signed in to change notification settings - Fork 1
/
php-showcase
79 lines (70 loc) · 2.64 KB
/
php-showcase
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/php
<?php
const NIX = DIRECTORY_SEPARATOR === '/';
$PHPBIN = NIX ? 'php' : '%TEMP%\..\PHP74\php';
const BACKGROUND_PROCESS = [
'3' => 'MockServer.php'
];
const ARCHIVES = [
'1' => ['/../content/bubble.c' => '/../content/sample.tar.gz']
];
function out($txt) {
echo NIX ? $txt : preg_replace('/\e[[][A-Za-z0-9];?[0-9]*m?/', '', $txt);
}
out("*** \033[46mhttps://github.com/goobemaster/php-showcase\033[0m ***\n\n");
out("Please choose a solution:\n");
out(" \033[1;33m1)\033[0m Code Show Off\n");
out(" \033[1;33m2)\033[0m Search The News\n");
out(" \033[1;33m3)\033[0m Restless Parrot\n");
out(" \033[1;33m4)\033[0m Wine Setup 3.1\n");
$stdin = fopen('php://stdin', 'r');
out("\nYour \033[1;33mchoice\033[0m (or 'q' to exit): ");
$index = trim(fgets($stdin));
if ($index === 'q') exit(0);
$folder = glob($index . '-*', GLOB_ONLYDIR)[0] . '/docroot';
if (!is_dir($folder)) {
out("\n\033[0;31mCannot find solution with such index, or directory missing.\033[0m");
exit(1);
}
if (array_key_exists($index, ARCHIVES)) {
if (!NIX && $index == '1') {
out("\nPlease, copy your favourite source files to 1-code-show-off/content/\n");
out("or untar the archive in that folder manually.\n");
}
if (NIX) {
foreach (ARCHIVES[$index] as $check => $archive) {
if (!is_file($folder . $check)) {
$archiveFile = $folder . $archive;
$archivePath = dirname($archiveFile);
exec("tar -xvzf {$archiveFile} -C {$archivePath}");
}
}
}
}
if (array_key_exists($index, BACKGROUND_PROCESS)) {
if (!NIX) {
out("Sorry, this one cannot be run on Windows automatically yet.");
exit(1);
}
$procFile = BACKGROUND_PROCESS[$index];
exec(sprintf('php %s/../%s > /dev/null &', $folder, $procFile));
out("\n\033[0;36m{$procFile}\033[0m is running as a background process...\n");
}
if ($index == '5') {
out("Sorry, this one is not even done yet. ;)");
exit(1);
chdir($folder);
system('./build.sh');
foreach (['auth' => '9010', 'connection' => '9020', 'content' => '9030'] as $service => $port) {
exec(sprintf("cd _out/{$service}; php -S localhost:{$port}"));
out("\n\033[0;36m{$service} service\033[0m is running as a background process...\n");
}
chdir("{$folder}/_out/webui");
out("\nOpen \033[0;36mhttp://localhost:8000/\033[0m in a browser. Press \033[0;31mCtrl+C\033[0m to stop the server.\n");
out("\nBackground services must be stopped manually (e.g. 'killall php')");
$server = `php -S localhost:8000`;
exit(0);
}
chdir($folder);
out("\nOpen \033[0;36mhttp://localhost:8000/\033[0m in a browser. Press \033[0;31mCtrl+C\033[0m to stop the server.\n");
$server = shell_exec("{$PHPBIN} -S localhost:8000");