#!/usr/bin/php * Copyright 2001-2010 Strangecode, LLC * * This file is part of The Strangecode Codebase. * * The Strangecode Codebase is free software: you can redistribute it and/or * modify it under the terms of the GNU General Public License as published by the * Free Software Foundation, either version 3 of the License, or (at your option) * any later version. * * The Strangecode Codebase is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * The Strangecode Codebase. If not, see . */ /* * example.cli.php - An example of a command-line interface script using the Strangecode Codebase. * * * @author Quinn Comendant * @version 1.0 * @since 28 Oct 2008 16:44:24 */ /******************************************************************** * STARTUP ********************************************************************/ $this_script = basename($_SERVER['argv'][0]); // First things first. Define the globally used directory paths. // The parent directory of all application DocRoots, such as /home/user/www.example.com/ define('COMMON_BASE', realpath('../..')); // Set include path for all templates and libraries. ini_set('include_path', get_include_path() . PATH_SEPARATOR . COMMON_BASE ); /******************************************************************** * CONFIG ********************************************************************/ // Include core libraries. require_once 'codebase/lib/App.inc.php'; require_once 'codebase/lib/Utilities.inc.php'; // Primary application class. $app =& App::getInstance('cli'); $app->setParam(array( 'site_name' => 'CLI Script', 'site_email' => 'codebase@strangecode.com', 'enable_session' => false, 'enable_db' => false, 'db_always_debug' => false, 'db_debug' => true, 'db_die_on_failure' => true, 'display_errors' => true, 'error_reporting' => E_ALL, 'log_file_priority' => LOG_INFO, 'log_screen_priority' => LOG_DEBUG, 'log_directory' => COMMON_BASE . '/log', 'log_filename' => 'cli_log', )); // DB credentials for command line scripts stored in a file with read rights // given only to the user who will be executing the scripts: -rw------- // This file includes $app-> method calls so this must be included after App::getInstance(). // require_once 'global/db_auth.inc.php'; // Start application-based functionality: database, session, environment, ini setup, etc. // Most configuration parameters must be set before starting the App. $app->start(); // Global DB object. Automatically pre-configured by $app->start(). // $db =& DB::getInstance(); /******************************************************************** * MAIN ********************************************************************/ $options = getopt("habc"); // Give them a fighting chance. Show the help message. ;P if (!$options) { printf("%s: Syntax or usage error. Try '-h' if you are lost.\n", $this_script); die(1); } if (isset($options['h'])) { help(); die(1); } if (isset($options['a'])) { // Run code associated with option -a echo "Option a\n"; } if (isset($options['b'])) { // Run code associated with option -b echo "Option b\n"; } if (isset($options['c'])) { // Run code associated with option -c echo "Option c\n"; } /******************************************************************** * FUNCTIONS ********************************************************************/ function help() { global $this_script; ?> Description of this script goes here... Usage: [OPTIONS] OPTIONS: -a Blah blah blah -b Blah blah blah -c Blah blah blah Strangecode :: www.strangecode.com