11.3. Code and Code Explanation
It's time to discuss the actual code for the project. First, I will cover creating a reusable CommandLine class to assist in obtaining user input. Then I will cover the startproject script, which uses it.
11.3.1. The CommandLine Class
The CommandLine class will contain static methods to ease getting outside information. This can be either in the form of command-line arguments or values provided in a configuration file. It will also help reading information in from the user interactively with a prompt. Table 11-1 shows the methods and properties CommandLine will expose.
Property | Description |
---|---|
CONFIG_TYPE_PLAIN | Represents a basic configuration file format |
CONFIG_TYPE_INI | Represents a ini-style configuration file format |
Method | |
parseOptions(args[, allowed]) | Parses command-line arguments and returns them as an array |
parseConfigFile(file[, type]) | Parses a configuration file and returns the options as an array |
prompt(label[, length[, callback]]) | Displays a prompt and reads keyboard input |
promtDefault(label[, default[, length[, callback]]]) | Displays a prompt with suggested response and reads keyboard input |
11.3.1.1. Command-Line Arguments
When the PHP script is run from the command line, the $_SERVER['argc'] and $_SERVER['argv'] variables are populated with the number of arguments passed, and the arguments themselves respectively to the script an array of the arguments. Simple scripts may interpret these values directly, ...
Get PHP and MySQL®: Create-Modify-Reuse now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.