[612] | 1 | #!/usr/bin/env php |
---|
[339] | 2 | <?php |
---|
[362] | 3 | /** |
---|
| 4 | * The Strangecode Codebase - a general application development framework for PHP |
---|
| 5 | * For details visit the project site: <http://trac.strangecode.com/codebase/> |
---|
[396] | 6 | * Copyright 2001-2012 Strangecode, LLC |
---|
[476] | 7 | * |
---|
[362] | 8 | * This file is part of The Strangecode Codebase. |
---|
| 9 | * |
---|
| 10 | * The Strangecode Codebase is free software: you can redistribute it and/or |
---|
| 11 | * modify it under the terms of the GNU General Public License as published by the |
---|
| 12 | * Free Software Foundation, either version 3 of the License, or (at your option) |
---|
| 13 | * any later version. |
---|
[476] | 14 | * |
---|
[362] | 15 | * The Strangecode Codebase is distributed in the hope that it will be useful, but |
---|
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 17 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
---|
| 18 | * details. |
---|
[476] | 19 | * |
---|
[362] | 20 | * You should have received a copy of the GNU General Public License along with |
---|
| 21 | * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. |
---|
| 22 | */ |
---|
| 23 | |
---|
[339] | 24 | /* |
---|
| 25 | * example.cli.php - An example of a command-line interface script using the Strangecode Codebase. |
---|
[362] | 26 | * |
---|
[476] | 27 | * |
---|
[339] | 28 | * @author Quinn Comendant <quinn@strangecode.com> |
---|
| 29 | * @version 1.0 |
---|
| 30 | * @since 28 Oct 2008 16:44:24 |
---|
| 31 | */ |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | /******************************************************************** |
---|
| 35 | * STARTUP |
---|
| 36 | ********************************************************************/ |
---|
| 37 | |
---|
| 38 | $this_script = basename($_SERVER['argv'][0]); |
---|
| 39 | |
---|
| 40 | // First things first. Define the globally used directory paths. |
---|
[476] | 41 | // The parent directory of all application DocRoots. |
---|
| 42 | define('COMMON_BASE', realpath(dirname(__FILE__) . '/../')); |
---|
[339] | 43 | |
---|
| 44 | // Set include path for all templates and libraries. |
---|
| 45 | ini_set('include_path', get_include_path() |
---|
| 46 | . PATH_SEPARATOR . COMMON_BASE |
---|
| 47 | ); |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | /******************************************************************** |
---|
| 51 | * CONFIG |
---|
| 52 | ********************************************************************/ |
---|
| 53 | |
---|
[476] | 54 | // This will disable sessions and things not needed by a cli script. |
---|
| 55 | define('_CLI', true); |
---|
| 56 | |
---|
[339] | 57 | // Include core libraries. |
---|
| 58 | require_once 'codebase/lib/App.inc.php'; |
---|
| 59 | require_once 'codebase/lib/Utilities.inc.php'; |
---|
| 60 | |
---|
| 61 | // Primary application class. |
---|
| 62 | $app =& App::getInstance('cli'); |
---|
| 63 | $app->setParam(array( |
---|
| 64 | 'site_name' => 'CLI Script', |
---|
| 65 | 'site_email' => 'codebase@strangecode.com', |
---|
| 66 | 'enable_session' => false, |
---|
[340] | 67 | 'enable_db' => false, |
---|
[339] | 68 | 'db_always_debug' => false, |
---|
| 69 | 'db_debug' => true, |
---|
| 70 | 'db_die_on_failure' => true, |
---|
| 71 | 'display_errors' => true, |
---|
| 72 | 'error_reporting' => E_ALL, |
---|
| 73 | 'log_file_priority' => LOG_INFO, |
---|
| 74 | 'log_screen_priority' => LOG_DEBUG, |
---|
| 75 | 'log_directory' => COMMON_BASE . '/log', |
---|
| 76 | 'log_filename' => 'cli_log', |
---|
| 77 | )); |
---|
| 78 | |
---|
| 79 | // DB credentials for command line scripts stored in a file with read rights |
---|
| 80 | // given only to the user who will be executing the scripts: -rw------- |
---|
| 81 | // This file includes $app-> method calls so this must be included after App::getInstance(). |
---|
[340] | 82 | // require_once 'global/db_auth.inc.php'; |
---|
[339] | 83 | |
---|
| 84 | // Start application-based functionality: database, session, environment, ini setup, etc. |
---|
| 85 | // Most configuration parameters must be set before starting the App. |
---|
| 86 | $app->start(); |
---|
| 87 | |
---|
| 88 | // Global DB object. Automatically pre-configured by $app->start(). |
---|
[340] | 89 | // $db =& DB::getInstance(); |
---|
[339] | 90 | |
---|
| 91 | |
---|
| 92 | /******************************************************************** |
---|
| 93 | * MAIN |
---|
| 94 | ********************************************************************/ |
---|
| 95 | |
---|
| 96 | $options = getopt("habc"); |
---|
| 97 | |
---|
| 98 | // Give them a fighting chance. Show the help message. ;P |
---|
| 99 | if (!$options) { |
---|
| 100 | printf("%s: Syntax or usage error. Try '-h' if you are lost.\n", $this_script); |
---|
[476] | 101 | die(1); |
---|
[339] | 102 | } |
---|
| 103 | |
---|
| 104 | if (isset($options['h'])) { |
---|
| 105 | help(); |
---|
| 106 | die(1); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | if (isset($options['a'])) { |
---|
| 110 | // Run code associated with option -a |
---|
| 111 | echo "Option a\n"; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | if (isset($options['b'])) { |
---|
| 115 | // Run code associated with option -b |
---|
| 116 | echo "Option b\n"; |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | if (isset($options['c'])) { |
---|
| 120 | // Run code associated with option -c |
---|
| 121 | echo "Option c\n"; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | |
---|
| 125 | /******************************************************************** |
---|
| 126 | * FUNCTIONS |
---|
| 127 | ********************************************************************/ |
---|
| 128 | |
---|
| 129 | function help() |
---|
| 130 | { |
---|
| 131 | global $this_script; |
---|
| 132 | |
---|
| 133 | ?> |
---|
| 134 | Description of this script goes here... |
---|
| 135 | |
---|
| 136 | Usage: <?php echo $this_script; ?> [OPTIONS] |
---|
| 137 | |
---|
| 138 | OPTIONS: |
---|
[476] | 139 | |
---|
[339] | 140 | -a Blah blah blah |
---|
| 141 | -b Blah blah blah |
---|
| 142 | -c Blah blah blah |
---|
| 143 | |
---|
| 144 | Strangecode :: www.strangecode.com |
---|
| 145 | <?php |
---|
| 146 | } |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | |
---|
| 150 | |
---|