-
Notifications
You must be signed in to change notification settings - Fork 2
/
README.txt
81 lines (54 loc) · 2.25 KB
/
README.txt
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
This is a simple to use Command Line Interface ( CLI ) PHP class that allows for user input.
This script can take parameters to your script in 3 different ways...
1.) User Input
- With this method, you can allow your script to ask the user for the parameters for your script.
<?php
require_once('cli.php');
// Create a new CLI object.
$cli = new CLIPHP();
// Ask the user for their first name.
$cli->get('first', "What is your first name?");
// Ask the user for their last name.
$cli->get('last', "What is your last name?");
// Now print the results.
print $cli->args['first'];
print $cli->args['last'];
?>
2.) Cached User Input
- With this method, you can cache the user results inside of a "config" file on the root path of where this script is ran.
- Using this method, they will be asked for the parameters only once, and then every other time the script is ran, the
cached results will populate the parameters. Like so...
<?php
require_once('cli.php');
// Create a new CLI object.
$cli = new CLIPHP();
// Ask the user for their first name. PASS TRUE TO CACHE THE RESULT!!!
$cli->get('first', "What is your first name?", TRUE);
// Ask the user for their last name. PASS TRUE TO CACHE THE RESULT!!!!
$cli->get('last', "What is your last name?", TRUE);
// Now print the results.
print $cli->args['first'];
print $cli->args['last'];
// Now create a separate CLI object.
$cli2 = new CLIPHP();
// Print's the cached results from the first object.
print $cli2->args['first'];
print $cli2->args['last'];
?>
3.) Direct arguments...
- With this, you can just pass the arguments directly using the "-param value" method.
php mycli.php -name "Travis" -last "Tidwell"
- Then inside of your script, you just need to provide the following..
- It will first check to see if values have been passed as arguments, and then if so, it will use those instead.
<?php
require_once('cli.php');
// Create a new CLI object.
$cli = new CLIPHP();
// Ask the user for their first name.
$cli->get('first', "What is your first name?");
// Ask the user for their last name.
$cli->get('last', "What is your last name?");
// Now print the results.
print $cli->args['first'];
print $cli->args['last'];
?>