comparison vendor/pear/console_commandline/docs/examples/ex4.php @ 0:1e000243b222

vanilla 1.3.3 distro, I hope
author Charlie Root
date Thu, 04 Jan 2018 15:50:29 -0500
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:1e000243b222
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * This file is part of the PEAR Console_CommandLine package.
7 *
8 * A simple example demonstrating the use of subcommands.
9 * (Same as ex3.php but using an xml file).
10 *
11 * PHP version 5
12 *
13 * LICENSE: This source file is subject to the MIT license that is available
14 * through the world-wide-web at the following URI:
15 * http://opensource.org/licenses/mit-license.php
16 *
17 * @category Console
18 * @package Console_CommandLine
19 * @author David JEAN LOUIS <izimobil@gmail.com>
20 * @copyright 2007 David JEAN LOUIS
21 * @license http://opensource.org/licenses/mit-license.php MIT License
22 * @version CVS: $Id$
23 * @link http://pear.php.net/package/Console_CommandLine
24 * @since File available since release 0.1.0
25 */
26
27 // Include the Console_CommandLine package.
28 require_once 'Console/CommandLine.php';
29
30 // create the parser
31 $xmlfile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'ex4.xml';
32 $parser = Console_CommandLine::fromXmlFile($xmlfile);
33
34 // run the parser
35 try {
36 $result = $parser->parse();
37 if ($result->command_name) {
38 $st = $result->command->options['reverse']
39 ? strrev($result->command->args['text'])
40 : $result->command->args['text'];
41 if ($result->command_name == 'foo') {
42 echo "Foo says: $st\n";
43 } else if ($result->command_name == 'bar') {
44 echo "Bar says: $st\n";
45 }
46 }
47 } catch (Exception $exc) {
48 $parser->displayError($exc->getMessage());
49 }
50
51 ?>