forked from GSA/digital-strategy-report-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
load.php
71 lines (55 loc) · 2.24 KB
/
load.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
<?php
/**
* Main bootstrap for the slash digital strategy generator
* Will auto-propegate local copies of data files if they don't exist
*/
if ( !file_exists( dirname( __FILE__ ) . '/config/config.php' ) )
die( 'Please copy `config-sample.php` to `config.php` in the project\'s `config` directory' );
//grab config file
require_once( dirname( __FILE__ ) . '/config/config.php' );
//get core functions
require_once DGS_BASE_DIR . '/includes/functions.php';
//bootrstrap form generator
require_once DGS_BASE_DIR . '/includes/forms/load.php';
//generator version, bump with each release
define( 'DGS_VERSION', '1.1' );
//bootstrap DSG Generator Core
foreach ( array( 'items', 'agencies' ) as $plural ) {
//for readability, we need both singular and plural names
$singular = dgs_singular( $plural );
//bootstrap core DGS classes
require_once DGS_BASE_DIR . "/includes/class.dgs-{$singular}.php";
//each data type array will be loaded into the global scope
$global_var = "dgs_{$plural}";
//Hierarchy of where the generator looks for agencies and action items
// (1) Global variable established prior to load.php running
// (2) Persistant cache (APC)
// (3) Local /data/ directory, for non-expired cached files
// (4) GSA GitHub Repo
// (5) /config/ directory
// Note: change DGS_SCHEMA_BASE to FALSE and DGS_TTL to 0 in config.php to force local refresh
//look for global var already established, no need to re-parse
if ( isset( $$global_var ) )
continue;
//check APC Cache, if it's installed
if ( function_exists( 'apc_fetch' ) && $cache = apc_fetch ( $global_var ) ) {
$$global_var = $cache->$plural;
continue;
}
//look for /data/ files and parse (disk cache)
if ( $file = dgs_get_disk_cache( $plural ) ) {
$$global_var = $file->$plural;
continue;
}
//try GitHub (mmm... dogfood)
if ( DGS_SCHEMA_BASE && $file = dgs_get_live( $plural ) ) {
$$global_var = $file->$plural;
continue;
}
//fallback to local config and rebuild action items
//note, we don't set our pseudo-ttl for these files since we don't really trust local config
//on next run, we'll check if GitHub's reachable and will overwrite what we generated here
require_once DGS_BASE_DIR . "/includes/build-{$plural}.php";
$var = $$global_var;
$$global_var = $var[$plural];
}