-
Notifications
You must be signed in to change notification settings - Fork 0
/
axon
executable file
·73 lines (50 loc) · 2.26 KB
/
axon
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
#!/usr/bin/env php
<?php
require_once 'vendor/autoload.php';
global $argv;
$def = new Symfony\Component\Console\Input\InputDefinition();
$def->addArgument(new Symfony\Component\Console\Input\InputArgument('file', null, 'PHP File to execute'));
$def->addOption(new Symfony\Component\Console\Input\InputOption('help', 'h', Symfony\Component\Console\Input\InputOption::VALUE_NONE));
// $def->addOption(new InputOption('detach', 'd', InputOption::VALUE_NONE)); //todo pcntl extension ?
$input = new Symfony\Component\Console\Input\ArgvInput($argv, $def);
$output = new Symfony\Component\Console\Output\ConsoleOutput();
if($input->getOption('help')){
$output->writeln($def->getSynopsis());
} elseif($file = $input->getArgument('file')) {
if (!preg_match('/^\\' . DIRECTORY_SEPARATOR . '/', $file)) {
if (preg_match('/^\.\\' . DIRECTORY_SEPARATOR . '/', $file)) {
$file = preg_replace('/^\.\\' . DIRECTORY_SEPARATOR . '/', __DIR__ . '/', $file);
} else {
$file = __DIR__ . DIRECTORY_SEPARATOR . $file;
}
}
$axon = new Ephrin\Axon();
function setTimeout(callable $fn, $delay){
global $axon;
$args = func_get_args();
$fn = array_shift($args);
$delay = array_shift($args);
$timeoutObject = new \Ephrin\TimeoutObject($fn, $delay, $args);
$axon->timeout($timeoutObject);
return $timeoutObject;
}
function clearTimeout(\Ephrin\TimeoutObject $object){
global $axon;
$axon->timeoutClear($object);
}
function setInterval(callable $fn, $delay){
global $axon;
$args = func_get_args();
$fn = array_shift($args);
$delay = array_shift($args);
$intervalObject = new \Ephrin\IntervalObject($fn, $delay, $args);
$axon->interval($intervalObject);
return $intervalObject;
}
function clearInterval(\Ephrin\IntervalObject $object){
global $axon;
$axon->intervalClear($object);
}
} else {
throw new \RuntimeException('shell is not supported. please provide a valid php file name');
}