source: trunk/bin/_config.inc.php @ 532

Last change on this file since 532 was 532, checked in by anonymous, 9 years ago

Added common config for codebase cli scripts. Changed behavior of db_auth.json loading. validSignature() now fails on empty string.

File size: 3.2 KB
Line 
1<?php
2/*
3* The Strangecode Codebase - a general application development framework for PHP
4* For details visit the project site: <http://trac.strangecode.com/>
5* Copyright © 2015 Strangecode, LLC
6*
7* This program is free software: you can redistribute it and/or modify
8* it under the terms of the GNU General Public License as published by
9* the Free Software Foundation, either version 3 of the License, or
10* (at your option) any later version.
11*
12* This program is distributed in the hope that it will be useful,
13* but WITHOUT ANY WARRANTY; without even the implied warranty of
14* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15* GNU General Public License for more details.
16*
17* You should have received a copy of the GNU General Public License
18* along with this program.  If not, see <http://www.gnu.org/licenses/>.
19*/
20
21/*
22* Small config file for cli scripts in the codebase/bin directory.
23*
24* @author   Quinn Comendant <quinn@strangecode.com>
25* @version  1.0
26* @since    12 Jul 2015 22:48:13
27*/
28
29$this_script = basename($_SERVER['argv'][0]);
30
31// Assume execution occurs while in the common app directory.
32define('COMMON_BASE', realpath('.'));
33$db_auth_file = false;
34$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(COMMON_BASE));
35$rii->setMaxDepth(2);
36foreach ($rii as $filename => $file) {
37    if (in_array(basename($filename), ['db_auth.inc.php', 'db_auth.json'])) {
38        $db_auth_file = $filename;
39        break;
40    }
41}
42if (!$db_auth_file) {
43    die(sprintf("%s error: the current directory must be common site directory (i.e. the parent directory of the document root) AND a db_auth file must exist within two directory levels.\n", $this_script));
44}
45if (fileowner($db_auth_file) != getmyuid()) {
46    die(sprintf("%s error: you must execute this script as the owner of the web files.\n", $this_script));
47}
48
49// Set include path.
50ini_set('include_path', get_include_path() . PATH_SEPARATOR . COMMON_BASE);
51
52/********************************************************************
53* CONFIG
54********************************************************************/
55
56// Include core libraries.
57require_once 'codebase/lib/App.inc.php';
58require_once 'codebase/lib/Utilities.inc.php';
59
60define('_CLI', true);
61$app =& App::getInstance('codebase');
62$app->setParam(array(
63    'site_name' => 'codebase',
64    'site_email' => 'codebase@strangecode.com',
65    'enable_session' => false,
66    'enable_db' => true,
67    'db_create_tables' => true,
68    'db_auth_file' => $db_auth_file,
69    'db_always_debug' => false,
70    'db_debug' => true,
71    'db_die_on_failure' => true,
72    'display_errors' => true,
73    'error_reporting' => E_ALL,
74    'log_file_priority' => false,
75    'log_screen_priority' => LOG_INFO,
76    'log_directory' => COMMON_BASE . '/log',
77    'log_filename' => 'site_log',
78));
79
80if (strtolower(getFilenameExtension($db_auth_file)) != 'json') {
81    // DB auth file is not json, and will not be automaticlaly be loaded by $app's 'db_auth_file' parser.
82    require_once $db_auth_file;
83}
84
85// Start application-based functionality: database, session, environment, ini setup, etc.
86// Most configuration parameters must be set before starting the App.
87$app->start();
88
89// Global DB object. Automatically pre-configured by $app->start().
90$db =& DB::getInstance();
Note: See TracBrowser for help on using the repository browser.