5
5
namespace SPC \exception ;
6
6
7
7
use SPC \builder \BuilderBase ;
8
+ use SPC \builder \freebsd \BSDBuilder ;
9
+ use SPC \builder \linux \LinuxBuilder ;
10
+ use SPC \builder \macos \MacOSBuilder ;
11
+ use SPC \builder \windows \WindowsBuilder ;
8
12
use ZM \Logger \ConsoleColor ;
9
13
10
14
class ExceptionHandler
@@ -28,10 +32,10 @@ class ExceptionHandler
28
32
];
29
33
30
34
/** @var null|BuilderBase Builder binding */
31
- public static ?BuilderBase $ bind_builder = null ;
35
+ private static ?BuilderBase $ bind_builder = null ;
32
36
33
37
/** @var array<string, mixed> Build PHP extra info binding */
34
- public static array $ bind_build_php_extra_info = [];
38
+ private static array $ bind_build_php_extra_info = [];
35
39
36
40
public static function handleSPCException (SPCException $ e ): void
37
41
{
@@ -47,7 +51,7 @@ public static function handleSPCException(SPCException $e): void
47
51
SPCInternalException::class => "✗ SPC internal error: {$ e ->getMessage ()}" ,
48
52
ValidationException::class => "⚠ Validation failed: {$ e ->getMessage ()}" ,
49
53
WrongUsageException::class => $ e ->getMessage (),
50
- default => "✗Unknown SPC exception {$ class }: {$ e ->getMessage ()}" ,
54
+ default => "✗ Unknown SPC exception {$ class }: {$ e ->getMessage ()}" ,
51
55
};
52
56
self ::logError ($ head_msg );
53
57
@@ -61,12 +65,19 @@ public static function handleSPCException(SPCException $e): void
61
65
self ::logError ("---------------------------------------- \n" );
62
66
63
67
// get the SPCException module
64
- if ($ php_info = $ e ->getBuildPHPInfo ()) {
65
- self ::logError ('Failed module: ' . ConsoleColor::yellow ("Builder for {$ php_info ['os ' ]}" ));
66
- } elseif ($ lib_info = $ e ->getLibraryInfo ()) {
68
+ if ($ lib_info = $ e ->getLibraryInfo ()) {
67
69
self ::logError ('Failed module: ' . ConsoleColor::yellow ("library {$ lib_info ['library_name ' ]} builder for {$ lib_info ['os ' ]}" ));
68
70
} elseif ($ ext_info = $ e ->getExtensionInfo ()) {
69
71
self ::logError ('Failed module: ' . ConsoleColor::yellow ("shared extension {$ ext_info ['extension_name ' ]} builder " ));
72
+ } elseif (self ::$ bind_builder ) {
73
+ $ os = match (get_class (self ::$ bind_builder )) {
74
+ WindowsBuilder::class => 'Windows ' ,
75
+ MacOSBuilder::class => 'macOS ' ,
76
+ LinuxBuilder::class => 'Linux ' ,
77
+ BSDBuilder::class => 'FreeBSD ' ,
78
+ default => 'Unknown OS ' ,
79
+ };
80
+ self ::logError ('Failed module: ' . ConsoleColor::yellow ("Builder for {$ os }" ));
70
81
} elseif (!in_array ($ class , self ::KNOWN_EXCEPTIONS )) {
71
82
self ::logError ('Failed From: ' . ConsoleColor::yellow ('Unknown SPC module ' . $ class ));
72
83
}
@@ -118,12 +129,14 @@ public static function handleSPCException(SPCException $e): void
118
129
}
119
130
120
131
// get the full builder options if possible
121
- if (self :: $ bind_builder && $ e ->getBuildPHPInfo ()) {
132
+ if ($ e ->getBuildPHPInfo ()) {
122
133
$ info = $ e ->getBuildPHPInfo ();
123
134
self ::logError ('' , output_log: defined ('DEBUG_MODE ' ));
124
135
self ::logError ('Builder function: ' . ConsoleColor::yellow ($ info ['builder_function ' ]), output_log: defined ('DEBUG_MODE ' ));
125
- self ::logError ('Builder options: ' , output_log: defined ('DEBUG_MODE ' ));
126
- self ::printArrayInfo (self ::$ bind_builder ->getOptions ());
136
+ if (self ::$ bind_builder ) {
137
+ self ::logError ('Builder options: ' , output_log: defined ('DEBUG_MODE ' ));
138
+ self ::printArrayInfo (self ::$ bind_builder ->getOptions ());
139
+ }
127
140
}
128
141
129
142
self ::logError ("\n---------------------------------------- \n" );
@@ -151,6 +164,16 @@ public static function handleDefaultException(\Throwable $e): void
151
164
self ::logError ('⚠ Please report this exception to: https://github.com/crazywhalecc/static-php-cli/issues ' );
152
165
}
153
166
167
+ public static function setBindBuilder (?BuilderBase $ bind_builder ): void
168
+ {
169
+ self ::$ bind_builder = $ bind_builder ;
170
+ }
171
+
172
+ public static function setBindBuildPhpExtraInfo (array $ bind_build_php_extra_info ): void
173
+ {
174
+ self ::$ bind_build_php_extra_info = $ bind_build_php_extra_info ;
175
+ }
176
+
154
177
private static function logError ($ message , int $ indent_space = 0 , bool $ output_log = true ): void
155
178
{
156
179
$ spc_log = fopen (SPC_OUTPUT_LOG , 'a ' );
0 commit comments