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

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

Adapted module maker scripts to use the new cli config file. Updated config to load codebase classes from its own codebase dir.

File size: 3.5 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// The name of the CLI.
30$cli_executed = basename($_SERVER['argv'][0]);
31
32// Enforce "relaxed" directory location, if set by the called script.
33// This script can be executed in any directory that is an ancestor 2 directories above the db_auth file.
34if (!defined('COMMON_BASE')) {
35    define('COMMON_BASE', realpath('.'));
36}
37
38// Use codebase files releative to this file.
39define('CODEBASE_PATH', realpath(dirname(__FILE__) . '/../'));
40
41$db_auth_file = false;
42$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(COMMON_BASE));
43$rii->setMaxDepth(2);
44foreach ($rii as $filename => $file) {
45    if (in_array(basename($filename), ['db_auth.inc.php', 'db_auth.json'])) {
46        $db_auth_file = $filename;
47        break;
48    }
49}
50if (!$db_auth_file) {
51    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", $cli_executed));
52}
53if (fileowner($db_auth_file) != getmyuid()) {
54    die(sprintf("%s error: you must execute this script as the owner of the web files.\n", $cli_executed));
55}
56
57// Set include path.
58ini_set('include_path', get_include_path() . PATH_SEPARATOR . COMMON_BASE);
59
60/********************************************************************
61* CONFIG
62********************************************************************/
63
64// Include core libraries.
65require_once CODEBASE_PATH . '/lib/App.inc.php';
66require_once CODEBASE_PATH . '/lib/Utilities.inc.php';
67
68define('_CLI', true);
69$app =& App::getInstance('codebase');
70$app->setParam(array(
71    'site_name' => 'codebase',
72    'site_email' => 'codebase@strangecode.com',
73    'enable_session' => false,
74    'enable_db' => true,
75    'db_create_tables' => true,
76    'db_auth_file' => $db_auth_file,
77    'db_always_debug' => false,
78    'db_debug' => true,
79    'db_die_on_failure' => true,
80    'display_errors' => true,
81    'error_reporting' => E_ALL,
82    'log_file_priority' => false,
83    'log_screen_priority' => LOG_INFO,
84    'log_directory' => '/tmp',
85    'log_filename' => 'site_log',
86));
87
88if (strtolower(getFilenameExtension($db_auth_file)) != 'json') {
89    // DB auth file is not json, and will not be automaticlaly be loaded by $app's 'db_auth_file' parser.
90    require_once $db_auth_file;
91}
92
93// Start application-based functionality: database, session, environment, ini setup, etc.
94// Most configuration parameters must be set before starting the App.
95$app->start();
96
97// Global DB object. Automatically pre-configured by $app->start().
98$db =& DB::getInstance();
Note: See TracBrowser for help on using the repository browser.