|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PSFS Bootstrap (v2) - Multi-environment aware |
|
5
|
|
|
* |
|
6
|
|
|
* Responsibilities: |
|
7
|
|
|
* - Detect framework mode: vendor / standalone / phar. |
|
8
|
|
|
* - Define base directory constants accordingly. |
|
9
|
|
|
* - Load Composer autoload (from project or from standalone mode). |
|
10
|
|
|
* - Load global helper functions. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
// ----------------------------------------------------------------------------- |
|
14
|
|
|
// 1. Runtime metrics (optional) |
|
15
|
|
|
// ----------------------------------------------------------------------------- |
|
16
|
|
|
|
|
17
|
|
|
defined('PSFS_START_TS') or define('PSFS_START_TS', microtime(true)); |
|
18
|
|
|
defined('PSFS_START_MEM') or define('PSFS_START_MEM', memory_get_usage(true)); |
|
19
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
// ----------------------------------------------------------------------------- |
|
22
|
|
|
// 2. Detect execution environment |
|
23
|
|
|
// ----------------------------------------------------------------------------- |
|
24
|
|
|
|
|
25
|
|
|
$bootstrapDir = __DIR__; // .../psfs/core/src |
|
26
|
|
|
$vendorDir = dirname($bootstrapDir, 2) . '/vendor'; |
|
27
|
|
|
$projectRoot = dirname($bootstrapDir, 2); // When running as vendor |
|
28
|
|
|
|
|
29
|
|
|
// Standalone mode: PSFS cloned and executed directly (no vendor/) |
|
30
|
|
|
$standaloneRoot = dirname($bootstrapDir, 1); // .../psfs-core |
|
31
|
|
|
|
|
32
|
|
|
// Detect vendor mode (framework inside vendor/) |
|
33
|
|
|
$runningAsVendor = file_exists($vendorDir . '/autoload.php'); |
|
34
|
|
|
|
|
35
|
|
|
// Detect standalone mode |
|
36
|
|
|
$runningStandalone = !$runningAsVendor; |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
// ----------------------------------------------------------------------------- |
|
40
|
|
|
// 3. Define base directory constants |
|
41
|
|
|
// ----------------------------------------------------------------------------- |
|
42
|
|
|
|
|
43
|
|
|
defined('SOURCE_DIR') or define('SOURCE_DIR', $bootstrapDir); |
|
44
|
|
|
if ($runningAsVendor) { |
|
45
|
|
|
// PSFS is being executed as a dependency in another project |
|
46
|
|
|
defined('BASE_DIR') or define('BASE_DIR', dirname($vendorDir, 1)); // The root of the host project |
|
47
|
|
|
defined('CORE_DIR') or define('CORE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'src'); |
|
48
|
|
|
defined('PSFS_AS_VENDOR') or define('PSFS_AS_VENDOR', true); |
|
49
|
|
|
} else { |
|
50
|
|
|
// Standalone development mode |
|
51
|
|
|
defined('BASE_DIR') or define('BASE_DIR', $standaloneRoot); |
|
52
|
|
|
defined('CORE_DIR') or define('CORE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'modules'); |
|
53
|
|
|
defined('PSFS_AS_VENDOR') or define('PSFS_AS_VENDOR', false); |
|
54
|
|
|
} |
|
55
|
|
|
defined('VENDOR_DIR') or define('VENDOR_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'vendor'); |
|
56
|
|
|
defined('LOG_DIR') or define('LOG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'logs'); |
|
57
|
|
|
defined('CACHE_DIR') or define('CACHE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'cache'); |
|
58
|
|
|
defined('CONFIG_DIR') or define('CONFIG_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'config'); |
|
59
|
|
|
defined('WEB_DIR') or define('WEB_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'html'); |
|
60
|
|
|
defined('LOCALE_DIR') or define('LOCALE_DIR', BASE_DIR . DIRECTORY_SEPARATOR . 'locale'); |
|
61
|
|
|
|
|
62
|
|
|
// ----------------------------------------------------------------------------- |
|
63
|
|
|
// 4. Load Composer autoload |
|
64
|
|
|
// ----------------------------------------------------------------------------- |
|
65
|
|
|
|
|
66
|
|
|
if ($runningAsVendor) { |
|
67
|
|
|
// Autoload from the host project's vendor directory |
|
68
|
|
|
require_once $vendorDir . '/autoload.php'; |
|
69
|
|
|
} else { |
|
70
|
|
|
// Standalone mode: PSFS itself is the project root |
|
71
|
|
|
$standaloneAutoload = BASE_DIR . '/vendor/autoload.php'; |
|
72
|
|
|
if (!file_exists($standaloneAutoload)) { |
|
73
|
|
|
throw new RuntimeException( |
|
74
|
|
|
"Composer autoload not found. Run 'composer install' in the PSFS root directory." |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
require_once $standaloneAutoload; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
|
|
81
|
|
|
// ----------------------------------------------------------------------------- |
|
82
|
|
|
// 5. Global helper functions |
|
83
|
|
|
// ----------------------------------------------------------------------------- |
|
84
|
|
|
require_once SOURCE_DIR . '/functions.php'; |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
// ----------------------------------------------------------------------------- |
|
88
|
|
|
// Bootstrap completed |
|
89
|
|
|
// ----------------------------------------------------------------------------- |