source: branches/eli_branch/docs/examples/example.cli.php @ 528

Last change on this file since 528 was 439, checked in by anonymous, 11 years ago

added public and private keywords to all properties and methods, changed old classname constructor function to construct, removed more ?> closing tags

  • Property svn:executable set to *
File size: 4.1 KB
Line 
1#!/usr/bin/php
2<?php
3/**
4 * The Strangecode Codebase - a general application development framework for PHP
5 * For details visit the project site: <http://trac.strangecode.com/codebase/>
6 * Copyright 2001-2012 Strangecode, LLC
7 *
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.
14 *
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.
19 *
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
24/*
25* example.cli.php - An example of a command-line interface script using the Strangecode Codebase.
26*
27*
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.
41// The parent directory of all application DocRoots, such as /home/user/www.example.com/
42define('COMMON_BASE', realpath('../..'));
43
44// Set include path for all templates and libraries.
45ini_set('include_path', get_include_path()
46    . PATH_SEPARATOR . COMMON_BASE
47);
48
49
50/********************************************************************
51* CONFIG
52********************************************************************/
53
54// Include core libraries.
55require_once 'codebase/lib/App.inc.php';
56require_once 'codebase/lib/Utilities.inc.php';
57
58// Primary application class.
59$app =& App::getInstance('cli');
60$app->setParam(array(
61    'site_name' => 'CLI Script',
62    'site_email' => 'codebase@strangecode.com',
63    'enable_session' => false,
64    'enable_db' => false,
65    'db_always_debug' => false,
66    'db_debug' => true,
67    'db_die_on_failure' => true,
68    'display_errors' => true,
69    'error_reporting' => E_ALL,
70    'log_file_priority' => LOG_INFO,
71    'log_screen_priority' => LOG_DEBUG,
72    'log_directory' => COMMON_BASE . '/log',
73    'log_filename' => 'cli_log',
74));
75
76// DB credentials for command line scripts stored in a file with read rights
77// given only to the user who will be executing the scripts: -rw-------
78// This file includes $app-> method calls so this must be included after App::getInstance().
79// require_once 'global/db_auth.inc.php';
80
81// Start application-based functionality: database, session, environment, ini setup, etc.
82// Most configuration parameters must be set before starting the App.
83$app->start();
84
85// Global DB object. Automatically pre-configured by $app->start().
86// $db =& DB::getInstance();
87
88
89/********************************************************************
90* MAIN
91********************************************************************/
92
93$options = getopt("habc");
94
95// Give them a fighting chance. Show the help message. ;P
96if (!$options) {
97    printf("%s: Syntax or usage error. Try '-h' if you are lost.\n", $this_script);
98    die(1);   
99}
100
101if (isset($options['h'])) {
102    help();
103    die(1);
104}
105
106if (isset($options['a'])) {
107    // Run code associated with option -a
108    echo "Option a\n";
109}
110
111if (isset($options['b'])) {
112    // Run code associated with option -b
113    echo "Option b\n";
114}
115
116if (isset($options['c'])) {
117    // Run code associated with option -c
118    echo "Option c\n";
119}
120
121
122/********************************************************************
123* FUNCTIONS
124********************************************************************/
125
126function help()
127{
128    global $this_script;
129
130    ?>
131Description of this script goes here...
132
133Usage: <?php echo $this_script; ?> [OPTIONS]
134
135OPTIONS:
136   
137    -a  Blah blah blah
138    -b  Blah blah blah
139    -c  Blah blah blah
140
141Strangecode :: www.strangecode.com
142<?php
143}
144
145
146
147
Note: See TracBrowser for help on using the repository browser.