mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-10 02:15:36 +08:00
Suggestions
This commit is contained in:
@@ -32,7 +32,7 @@ class BuilderProvider
|
|||||||
};
|
};
|
||||||
|
|
||||||
// bind the builder to ExceptionHandler
|
// bind the builder to ExceptionHandler
|
||||||
ExceptionHandler::$bind_builder = self::$builder;
|
ExceptionHandler::setBindBuilder(self::$builder);
|
||||||
|
|
||||||
return self::$builder;
|
return self::$builder;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ class BuildPHPCommand extends BuildCommand
|
|||||||
$this->printFormatInfo($indent_texts);
|
$this->printFormatInfo($indent_texts);
|
||||||
|
|
||||||
// bind extra info to exception handler
|
// bind extra info to exception handler
|
||||||
ExceptionHandler::$bind_build_php_extra_info = $indent_texts;
|
ExceptionHandler::setBindBuildPhpExtraInfo($indent_texts);
|
||||||
|
|
||||||
logger()->notice('Build will start after 2s ...');
|
logger()->notice('Build will start after 2s ...');
|
||||||
sleep(2);
|
sleep(2);
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ declare(strict_types=1);
|
|||||||
namespace SPC\exception;
|
namespace SPC\exception;
|
||||||
|
|
||||||
use SPC\builder\BuilderBase;
|
use SPC\builder\BuilderBase;
|
||||||
|
use SPC\builder\freebsd\BSDBuilder;
|
||||||
|
use SPC\builder\linux\LinuxBuilder;
|
||||||
|
use SPC\builder\macos\MacOSBuilder;
|
||||||
|
use SPC\builder\windows\WindowsBuilder;
|
||||||
use ZM\Logger\ConsoleColor;
|
use ZM\Logger\ConsoleColor;
|
||||||
|
|
||||||
class ExceptionHandler
|
class ExceptionHandler
|
||||||
@@ -28,10 +32,10 @@ class ExceptionHandler
|
|||||||
];
|
];
|
||||||
|
|
||||||
/** @var null|BuilderBase Builder binding */
|
/** @var null|BuilderBase Builder binding */
|
||||||
public static ?BuilderBase $bind_builder = null;
|
private static ?BuilderBase $bind_builder = null;
|
||||||
|
|
||||||
/** @var array<string, mixed> Build PHP extra info binding */
|
/** @var array<string, mixed> Build PHP extra info binding */
|
||||||
public static array $bind_build_php_extra_info = [];
|
private static array $bind_build_php_extra_info = [];
|
||||||
|
|
||||||
public static function handleSPCException(SPCException $e): void
|
public static function handleSPCException(SPCException $e): void
|
||||||
{
|
{
|
||||||
@@ -47,7 +51,7 @@ class ExceptionHandler
|
|||||||
SPCInternalException::class => "✗ SPC internal error: {$e->getMessage()}",
|
SPCInternalException::class => "✗ SPC internal error: {$e->getMessage()}",
|
||||||
ValidationException::class => "⚠ Validation failed: {$e->getMessage()}",
|
ValidationException::class => "⚠ Validation failed: {$e->getMessage()}",
|
||||||
WrongUsageException::class => $e->getMessage(),
|
WrongUsageException::class => $e->getMessage(),
|
||||||
default => "✗Unknown SPC exception {$class}: {$e->getMessage()}",
|
default => "✗ Unknown SPC exception {$class}: {$e->getMessage()}",
|
||||||
};
|
};
|
||||||
self::logError($head_msg);
|
self::logError($head_msg);
|
||||||
|
|
||||||
@@ -61,12 +65,19 @@ class ExceptionHandler
|
|||||||
self::logError("----------------------------------------\n");
|
self::logError("----------------------------------------\n");
|
||||||
|
|
||||||
// get the SPCException module
|
// get the SPCException module
|
||||||
if ($php_info = $e->getBuildPHPInfo()) {
|
if ($lib_info = $e->getLibraryInfo()) {
|
||||||
self::logError('Failed module: ' . ConsoleColor::yellow("Builder for {$php_info['os']}"));
|
|
||||||
} elseif ($lib_info = $e->getLibraryInfo()) {
|
|
||||||
self::logError('Failed module: ' . ConsoleColor::yellow("library {$lib_info['library_name']} builder for {$lib_info['os']}"));
|
self::logError('Failed module: ' . ConsoleColor::yellow("library {$lib_info['library_name']} builder for {$lib_info['os']}"));
|
||||||
} elseif ($ext_info = $e->getExtensionInfo()) {
|
} elseif ($ext_info = $e->getExtensionInfo()) {
|
||||||
self::logError('Failed module: ' . ConsoleColor::yellow("shared extension {$ext_info['extension_name']} builder"));
|
self::logError('Failed module: ' . ConsoleColor::yellow("shared extension {$ext_info['extension_name']} builder"));
|
||||||
|
} elseif (self::$bind_builder) {
|
||||||
|
$os = match (get_class(self::$bind_builder)) {
|
||||||
|
WindowsBuilder::class => 'Windows',
|
||||||
|
MacOSBuilder::class => 'macOS',
|
||||||
|
LinuxBuilder::class => 'Linux',
|
||||||
|
BSDBuilder::class => 'FreeBSD',
|
||||||
|
default => 'Unknown OS',
|
||||||
|
};
|
||||||
|
self::logError('Failed module: ' . ConsoleColor::yellow("Builder for {$os}"));
|
||||||
} elseif (!in_array($class, self::KNOWN_EXCEPTIONS)) {
|
} elseif (!in_array($class, self::KNOWN_EXCEPTIONS)) {
|
||||||
self::logError('Failed From: ' . ConsoleColor::yellow('Unknown SPC module ' . $class));
|
self::logError('Failed From: ' . ConsoleColor::yellow('Unknown SPC module ' . $class));
|
||||||
}
|
}
|
||||||
@@ -118,12 +129,14 @@ class ExceptionHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get the full builder options if possible
|
// get the full builder options if possible
|
||||||
if (self::$bind_builder && $e->getBuildPHPInfo()) {
|
if ($e->getBuildPHPInfo()) {
|
||||||
$info = $e->getBuildPHPInfo();
|
$info = $e->getBuildPHPInfo();
|
||||||
self::logError('', output_log: defined('DEBUG_MODE'));
|
self::logError('', output_log: defined('DEBUG_MODE'));
|
||||||
self::logError('Builder function: ' . ConsoleColor::yellow($info['builder_function']), output_log: defined('DEBUG_MODE'));
|
self::logError('Builder function: ' . ConsoleColor::yellow($info['builder_function']), output_log: defined('DEBUG_MODE'));
|
||||||
self::logError('Builder options:', output_log: defined('DEBUG_MODE'));
|
if (self::$bind_builder) {
|
||||||
self::printArrayInfo(self::$bind_builder->getOptions());
|
self::logError('Builder options:', output_log: defined('DEBUG_MODE'));
|
||||||
|
self::printArrayInfo(self::$bind_builder->getOptions());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self::logError("\n----------------------------------------\n");
|
self::logError("\n----------------------------------------\n");
|
||||||
@@ -151,6 +164,16 @@ class ExceptionHandler
|
|||||||
self::logError('⚠ Please report this exception to: https://github.com/crazywhalecc/static-php-cli/issues');
|
self::logError('⚠ Please report this exception to: https://github.com/crazywhalecc/static-php-cli/issues');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function setBindBuilder(?BuilderBase $bind_builder): void
|
||||||
|
{
|
||||||
|
self::$bind_builder = $bind_builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function setBindBuildPhpExtraInfo(array $bind_build_php_extra_info): void
|
||||||
|
{
|
||||||
|
self::$bind_build_php_extra_info = $bind_build_php_extra_info;
|
||||||
|
}
|
||||||
|
|
||||||
private static function logError($message, int $indent_space = 0, bool $output_log = true): void
|
private static function logError($message, int $indent_space = 0, bool $output_log = true): void
|
||||||
{
|
{
|
||||||
$spc_log = fopen(SPC_OUTPUT_LOG, 'a');
|
$spc_log = fopen(SPC_OUTPUT_LOG, 'a');
|
||||||
|
|||||||
@@ -5,15 +5,11 @@ declare(strict_types=1);
|
|||||||
namespace SPC\exception;
|
namespace SPC\exception;
|
||||||
|
|
||||||
use SPC\builder\BuilderBase;
|
use SPC\builder\BuilderBase;
|
||||||
use SPC\builder\freebsd\BSDBuilder;
|
|
||||||
use SPC\builder\freebsd\library\BSDLibraryBase;
|
use SPC\builder\freebsd\library\BSDLibraryBase;
|
||||||
use SPC\builder\LibraryBase;
|
use SPC\builder\LibraryBase;
|
||||||
use SPC\builder\linux\library\LinuxLibraryBase;
|
use SPC\builder\linux\library\LinuxLibraryBase;
|
||||||
use SPC\builder\linux\LinuxBuilder;
|
|
||||||
use SPC\builder\macos\library\MacOSLibraryBase;
|
use SPC\builder\macos\library\MacOSLibraryBase;
|
||||||
use SPC\builder\macos\MacOSBuilder;
|
|
||||||
use SPC\builder\windows\library\WindowsLibraryBase;
|
use SPC\builder\windows\library\WindowsLibraryBase;
|
||||||
use SPC\builder\windows\WindowsBuilder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for SPC exceptions.
|
* Base class for SPC exceptions.
|
||||||
@@ -70,10 +66,7 @@ abstract class SPCException extends \Exception
|
|||||||
* Returns an array containing information about the PHP build process.
|
* Returns an array containing information about the PHP build process.
|
||||||
*
|
*
|
||||||
* @return null|array{
|
* @return null|array{
|
||||||
* builder_class: string,
|
|
||||||
* builder_options: array<string, mixed>,
|
|
||||||
* builder_function: string,
|
* builder_function: string,
|
||||||
* os: string,
|
|
||||||
* file: null|string,
|
* file: null|string,
|
||||||
* line: null|int,
|
* line: null|int,
|
||||||
* } an array containing PHP build information
|
* } an array containing PHP build information
|
||||||
@@ -143,19 +136,8 @@ abstract class SPCException extends \Exception
|
|||||||
|
|
||||||
// Check if the class is a subclass of BuilderBase and the method is buildPHP
|
// Check if the class is a subclass of BuilderBase and the method is buildPHP
|
||||||
if (!$this->build_php_info && is_a($frame['class'], BuilderBase::class, true)) {
|
if (!$this->build_php_info && is_a($frame['class'], BuilderBase::class, true)) {
|
||||||
$options = ExceptionHandler::$bind_builder?->getOptions() ?? [];
|
|
||||||
$os = match (get_class(ExceptionHandler::$bind_builder ?? $frame['class'])) {
|
|
||||||
BSDBuilder::class => 'BSD',
|
|
||||||
LinuxBuilder::class => 'Linux',
|
|
||||||
MacOSBuilder::class => 'macOS',
|
|
||||||
WindowsBuilder::class => 'Windows',
|
|
||||||
default => 'Unknown',
|
|
||||||
};
|
|
||||||
$this->build_php_info = [
|
$this->build_php_info = [
|
||||||
'builder_class' => $frame['class'],
|
|
||||||
'builder_options' => $options,
|
|
||||||
'builder_function' => $frame['function'],
|
'builder_function' => $frame['function'],
|
||||||
'os' => $os,
|
|
||||||
'file' => $frame['file'] ?? null,
|
'file' => $frame['file'] ?? null,
|
||||||
'line' => $frame['line'] ?? null,
|
'line' => $frame['line'] ?? null,
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user