-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
54 lines (48 loc) · 1.58 KB
/
bootstrap.php
File metadata and controls
54 lines (48 loc) · 1.58 KB
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
<?php
/**
* Bootstrap for restruct/dot-static
*
* OS-aware path resolver for Graphviz dot binary.
* Safe to include multiple times — guarded by defined() check.
*
* Priority:
* 1. Already defined GRAPHVIZ_DOT_PATH constant (co-existence with docsys-tools)
* 2. GRAPHVIZ_DOT_PATH environment variable
* 3. macOS: Homebrew paths (ARM + Intel)
* 4. Linux: bundled x64/dot_static binary
*/
if (!defined('GRAPHVIZ_DOT_PATH')) {
$dotPath = null;
# Check environment variable first
$envPath = getenv('GRAPHVIZ_DOT_PATH');
if ($envPath !== false && $envPath !== '' && is_executable($envPath)) {
$dotPath = $envPath;
}
if ($dotPath === null) {
switch (PHP_OS_FAMILY) {
case 'Darwin':
# macOS: check Homebrew paths (ARM first, then Intel)
$candidates = [
'/opt/homebrew/bin/dot', # Apple Silicon (ARM)
'/usr/local/bin/dot', # Intel
];
foreach ($candidates as $candidate) {
if (is_executable($candidate)) {
$dotPath = $candidate;
break;
}
}
break;
case 'Linux':
# Linux: use the bundled statically compiled binary
$bundled = __DIR__ . '/x64/dot_static';
if (is_executable($bundled)) {
$dotPath = $bundled;
}
break;
}
}
if ($dotPath !== null) {
define('GRAPHVIZ_DOT_PATH', $dotPath);
}
}