forked from opencart/opencart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathocng
executable file
·88 lines (69 loc) · 2.64 KB
/
ocng
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
80
81
82
83
84
85
86
87
#!/usr/bin/env php
<?php
require_once(__DIR__ . '/app/vendor/autoload.php');
class ServeCommand extends Ahc\Cli\Input\Command
{
public function __construct()
{
parent::__construct('serve', 'Start a development web server');
$this
->option('-a --apple', 'The Apple')
->option('-b --ball', 'The ball')
// Usage examples:
->usage(
// append details or explanation of given example with ` ## ` so they will be uniformly aligned when shown
'<bold> init</end> <comment>--apple applet --ball ballon arggg</end> ## details 1<eol/>' .
// $0 will be interpolated to actual command name
'<bold> init</end> <comment>-a applet -b ballon arggg arg2</end> ## details 2<eol/>'
);
}
// This method is auto called before `self::execute()` and receives `Interactor $io` instance
public function interact(Ahc\Cli\IO\Interactor $io)
{
// // Collect missing opts/args
// if (!$this->apple) {
// $this->set('apple', $io->prompt('Enter apple'));
// }
// if (!$this->ball) {
// $this->set('ball', $io->prompt('Enter ball'));
// }
// ...
}
// When app->handle() locates `init` command it automatically calls `execute()`
// with correct $ball and $apple values
public function execute($ball, $apple)
{
// $io = $this->app()->io();
// $io->write('Apple ' . $apple, true);
// $io->write('Ball ' . $ball, true);
// $shell = new Ahc\Cli\Helper\Shell($command = 'php -v', $rawInput = null);
// // Waits until proc finishes
// $shell->execute($async = true); // default false
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork');
} else if ($pid) {
// we are the parent
pcntl_wait($status); //Protect against Zombie children
} else {
passthru('sleep 1 && php -c php.ini -S 0.0.0.0:9000 -t app 1>&2');
}
// echo $shell->getOutput(); // PHP version string (often with zend/opcache info)
// more codes ...
// If you return integer from here, that will be taken as exit error code
}
}
class OtherCommand extends Ahc\Cli\Input\Command
{
// ...
}
// Init App with name and version
$app = new Ahc\Cli\Application('OCNG', 'v0.0.1');
// Add commands with optional aliases`
$app->add(new ServeCommand, 's');
// $app->add(new OtherCommand, 'o');
// Set logo
$app->logo('╔═╗╔═╗ ╔╗╔╔═╗
║ ║║ ║║║║ ╦
╚═╝╚═╝ ╝╚╝╚═╝');
$app->handle($_SERVER['argv']); // if argv[1] is `i` or `init` it executes InitCommand