-
Notifications
You must be signed in to change notification settings - Fork 5
/
cli
executable file
·120 lines (101 loc) · 2.46 KB
/
cli
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env php
<?php
/*
*---------------------------------------------------------------
* PHPUnit runner
*---------------------------------------------------------------
*
* This file just loads CCF and all needed resources to run the
* php unit tests. PHPUnit is a really elegant way to make sure
* that everything works how it should.
*
*
* force the environment to phpunit
*
* By default the the environment detector defines the current
* environment. But you can force another one using the this var.
*/
$environment = 'cli';
/*
*---------------------------------------------------------------
* Require CCF
*---------------------------------------------------------------
*
* load the framework file wich wil initialize CCF.
*/
require_once __DIR__."/framework.php";
// get passed arguments
if ( isset( $argv ) )
{
array_shift( $argv );
$argv = implode( ' ', $argv );
}
// direct mode or read loop?
if ( !empty( $argv ) ) {
CCConsoleController::parse( $argv ); die;
}
// clear the screen
CCCli::clear();
/*
* show logo
*/
CCCli::write("==============================
_____ _____ ______
/ ____/ ____| ____|
| | | | | |__
| | | | | __|
| |___| |____| |
\_____\_____|_| Framework
==============================
\n", 'cyan');
/*
* start a manual read loop because we need the gloab scope
*/
while ( 1 ) {
// get input
$_reply = CCCli::read( '> ' );
// continue if no command given
if ( empty( $_reply ) ) {
continue;
}
// check for exit command
if ( $_reply == 'bye' ) {
die;
}
// last char
$last_char = substr( $_reply, -1 );
// get first cmd
$first_cmd = array_shift( array_values( explode( ' ', $_reply ) ) );
// check if we should execute an console controller
if ( $first_cmd == 'run' ) {
CCConsoleController::parse( substr( $_reply, 4 ) ); continue;
}
// add semicolon if missing
if ( $last_char != ";" && $last_char != "}" ) {
$_reply .= ";";
}
/*
* these commands cannot be used with a var assignment
*/
$no_return_cmds = array(
'throw',
'echo',
);
// catch the return
if ( !in_array( $first_cmd, $no_return_cmds ) ) {
$_reply = '$_return_data = '.$_reply;
}
// output buffer
ob_start();
// run the command
$return = eval( $_reply );
echo $out = ob_get_clean();
// add break if something where outputet
if ( strlen( $out ) > 0 ) {
echo "\n";
}
// dump the return
if ( !in_array( $first_cmd, $no_return_cmds ) ) {
var_dump( $_return_data );
}
}