forked from dri/DRI-SugarCRM-Framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.php
77 lines (63 loc) · 1.75 KB
/
build.php
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
<?php
ini_set('display_errors', 'On');
require_once 'bob/libs/helpers.php';
// determine $env and if we're running from browser or command line
$env = '';
$runFrom = '';
$args = $_SERVER['argv'];
if (empty($args)) {
define('EOL', '<br />');
$env = $_REQUEST['env'];
$runFrom = 'browser';
} else if (count($args) > 1) {
define('EOL', "\n");
$env = $args[1];
$runFrom = 'command-line';
}
/**
* No environment found: print basic help and die
*/
if ($env == '') {
require_once 'bob/libs/Documentation.php';
Documentation::printHelp();
}
// Sugar init
if (!defined('sugarEntry'))
define('sugarEntry', true);
require_once ('include/entryPoint.php');
$files = scandir('bob');
$toBeExecuted = array();
// see which classes are to be executed in this environment
foreach ($files as $file) {
if ($file == '.' || $file == '..' || $file == 'libs') {
continue;
}
require_once 'bob/' . $file;
try {
$className = str_replace('.php', '', $file);
$builderClass = new $className();
// make sure this is to be ran in this environment
if (!$builderClass->checkEnv($env)) {
continue;
}
$toBeExecuted[$className] = array(
'priority' => $builderClass->getPriority(),
'object' => $builderClass
);
} catch (Exception $e) {
echo "Failed: " . $e->getMessage() . EOL;
}
}
if (empty($toBeExecuted)) {
return true;
}
// sort the array so we run the classes in the right order
usort($toBeExecuted, 'comparePriorities');
foreach ($toBeExecuted as $builderA) {
try {
$builderA['object']->execute();
} catch (Exception $e) {
echo "Failed: " . $e->getMessage() . EOL;
}
}
return true;