-
Notifications
You must be signed in to change notification settings - Fork 39
/
elefant
executable file
·102 lines (91 loc) · 3.08 KB
/
elefant
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env php
<?php
/**
* Elefant CMS - http://www.elefantcms.com/
*
* Copyright (c) 2011 Johnny Broadway
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* This is the Elefant command line utility. It can run the Elefant
* install routines, create the scaffolding for new apps or the index
* for new translation files, or encrypt a password for you.
*
* Usage:
*
* $ cd /path/to/my/site
* $ ./elefant COMMAND
*
* To set the ELEFANT_ENV environment variable and use a specific configuration,
* call via:
*
* $ ./elefant --env=production COMMAND
*/
// Prevent non-CLI access
if (! defined ('STDIN')) {
echo "** Error: Must be run from the command line.\n";
die;
}
// Make sure we're in an Elefant site root
if (getcwd () !== __DIR__) {
chdir (__DIR__);
}
if (! file_exists ('conf/config.php')) {
echo "** Error: Must be run from the root of an Elefant website.\n";
die;
}
ini_set ('error_reporting', 247);
// Remove the script name
array_shift ($argv);
// Set ELEFANT_ENV based on --env=production parameter
if (isset ($argv[0]) && strpos ($argv[0], '--env=') === 0) {
$env = str_replace ('--env=', '', $argv[0]);
array_shift ($argv);
$argc--;
} else {
$env = 'config';
}
if (count ($argv) === 0) {
// No command, use default handler
$handler = 'cli/index';
} else {
$handler = array_shift ($argv);
if (strpos ($handler, '/') === false) {
// Built-in command
$handler = 'cli/' . $handler;
} else {
// Extended command, verify it's valid first
list ($app, $tmp) = explode ('/', $handler, 2);
if (! file_exists ('apps/' . $app . '/conf/cli.php')) {
printf ("** Error: Unknown option: %s\n", $handler);
return;
}
$parsed = parse_ini_file ('apps/' . $app . '/conf/cli.php');
if (! in_array ($handler, array_keys ($parsed['commands']))) {
printf ("** Error: Unknown option: %s\n", $handler);
return;
}
}
}
// Run the command through Elefant's CLI handling
foreach ($argv as $k => $v) {
$argv[$k] = escapeshellarg ($v);
}
system ('export ELEFANT_ENV=' . escapeshellarg ($env) . ' && php index.php ' . $handler . ' ' . join (' ', $argv));