-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.php
More file actions
107 lines (94 loc) · 3.03 KB
/
bootstrap.php
File metadata and controls
107 lines (94 loc) · 3.03 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
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
103
104
105
106
107
<?php
/**
* Bootstrap for restruct/docsys-tools (umbrella package)
*
* Defines system tool paths for tools that are NOT bundled but expected
* to be installed on the system. Sub-packages handle their own bootstrapping:
* - restruct/cpdf-static → CPDF_PATH
* - restruct/wkhtmltopdf-static → WKHTMLTOPDF_PATH, WKHTMLTOPDF_DOCKER_IMAGE
* - restruct/xpdf-static → XPDF_BIN_DIR
* - restruct/dot-static → GRAPHVIZ_DOT_PATH
*
* This bootstrap defines:
* - GS_PATH (Ghostscript)
* - CONVERT_PATH (ImageMagick/GraphicsMagick)
* - SOFFICE_PATH (LibreOffice headless)
*
* Priority for each:
* 1. Already defined constant
* 2. Environment variable
* 3. macOS: Homebrew paths (ARM first, then Intel)
* 4. Linux: standard system paths
*/
# --- GS_PATH (Ghostscript) ---
if (!defined('GS_PATH')) {
$gsPath = null;
$envPath = getenv('GS_PATH');
if ($envPath !== false && $envPath !== '' && is_executable($envPath)) {
$gsPath = $envPath;
}
if ($gsPath === null) {
$candidates = match (PHP_OS_FAMILY) {
'Darwin' => ['/opt/homebrew/bin/gs', '/usr/local/bin/gs'],
'Linux' => ['/usr/bin/gs', '/usr/local/bin/gs'],
default => [],
};
foreach ($candidates as $candidate) {
if (is_executable($candidate)) {
$gsPath = $candidate;
break;
}
}
}
if ($gsPath !== null) {
define('GS_PATH', $gsPath);
}
}
# --- CONVERT_PATH (ImageMagick/GraphicsMagick) ---
if (!defined('CONVERT_PATH')) {
$convertPath = null;
$envPath = getenv('CONVERT_PATH');
if ($envPath !== false && $envPath !== '' && is_executable($envPath)) {
$convertPath = $envPath;
}
if ($convertPath === null) {
$candidates = match (PHP_OS_FAMILY) {
'Darwin' => ['/opt/homebrew/bin/convert', '/usr/local/bin/convert'],
'Linux' => ['/usr/bin/convert', '/usr/local/bin/convert'],
default => [],
};
foreach ($candidates as $candidate) {
if (is_executable($candidate)) {
$convertPath = $candidate;
break;
}
}
}
if ($convertPath !== null) {
define('CONVERT_PATH', $convertPath);
}
}
# --- SOFFICE_PATH (LibreOffice headless) ---
if (!defined('SOFFICE_PATH')) {
$sofficePath = null;
$envPath = getenv('SOFFICE_PATH');
if ($envPath !== false && $envPath !== '' && is_executable($envPath)) {
$sofficePath = $envPath;
}
if ($sofficePath === null) {
$candidates = match (PHP_OS_FAMILY) {
'Darwin' => ['/opt/homebrew/bin/soffice', '/usr/local/bin/soffice'],
'Linux' => ['/usr/bin/soffice', '/usr/local/bin/soffice'],
default => [],
};
foreach ($candidates as $candidate) {
if (is_executable($candidate)) {
$sofficePath = $candidate;
break;
}
}
}
if ($sofficePath !== null) {
define('SOFFICE_PATH', $sofficePath);
}
}