Skip to content

Commit

Permalink
Removed E_STRICT constant
Browse files Browse the repository at this point in the history
  • Loading branch information
solital committed Dec 24, 2024
1 parent ce9970d commit 48b9d06
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 35 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Released Notes

## v3.3.7 - (2024-12-24)

### Removed

- Removed `E_STRICT` constant

--------------------------------------------------------------------------

## v3.3.6 - (2024-09-28)

### Added
Expand Down
65 changes: 51 additions & 14 deletions src/Console/CliMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ public function printMessage(mixed $message): self
public static function success(mixed $message, bool $space = false): static
{
self::generateColors();
self::$message = self::prepareMessage($message, self::$color_success, $space);
self::$message = self::prepareMessage(
$message,
self::$color_success,
$space
);

return new static;
}

Expand All @@ -100,7 +105,12 @@ public static function success(mixed $message, bool $space = false): static
public static function info(mixed $message, bool $space = false): static
{
self::generateColors();
self::$message = self::prepareMessage($message, self::$color_info, $space);
self::$message = self::prepareMessage(
$message,
self::$color_info,
$space
);

return new static;
}

Expand All @@ -115,7 +125,12 @@ public static function info(mixed $message, bool $space = false): static
public static function warning(mixed $message, bool $space = false): static
{
self::generateColors();
self::$message = self::prepareMessage($message, self::$color_warning, $space);
self::$message = self::prepareMessage(
$message,
self::$color_warning,
$space
);

return new static;
}

Expand All @@ -130,7 +145,12 @@ public static function warning(mixed $message, bool $space = false): static
public static function lineNumbers(mixed $message, bool $space = false): static
{
self::generateColors();
self::$message = self::prepareMessage($message, self::$color_gray, $space);
self::$message = self::prepareMessage(
$message,
self::$color_gray,
$space
);

return new static;
}

Expand All @@ -145,7 +165,12 @@ public static function lineNumbers(mixed $message, bool $space = false): static
public static function error(mixed $message, bool $space = false): static
{
self::generateColors();
self::$message = self::prepareMessage($message, self::$color_error, $space);
self::$message = self::prepareMessage(
$message,
self::$color_error,
$space
);

return new static;
}

Expand All @@ -160,7 +185,12 @@ public static function error(mixed $message, bool $space = false): static
public static function errorLine(mixed $message, bool $space = false): static
{
self::generateColors();
self::$message = self::prepareMessage($message, self::$color_error_line, $space);
self::$message = self::prepareMessage(
$message,
self::$color_error_line,
$space
);

return new static;
}

Expand All @@ -175,7 +205,12 @@ public static function errorLine(mixed $message, bool $space = false): static
public static function line(mixed $message, bool $space = false): static
{
self::generateColors();
self::$message = self::prepareMessage($message, self::$color_line, $space);
self::$message = self::prepareMessage(
$message,
self::$color_line,
$space
);

return new static;
}

Expand All @@ -191,12 +226,9 @@ public static function line(mixed $message, bool $space = false): static
private static function prepareMessage(mixed $message, mixed $color, bool $space = false): string
{
$space_line = "";

if ($space == true) {
$space_line = " ";
}

if ($space == true) $space_line = " ";
$message = $space_line . $color . $message . self::$color_reset;

return $message;
}

Expand Down Expand Up @@ -262,11 +294,15 @@ private static function generateColors(): void
public static function colorIsSupported(): bool
{
if (DIRECTORY_SEPARATOR === '\\') {
if (function_exists('sapi_windows_vt100_support') && @sapi_windows_vt100_support(STDOUT)) {
if (
function_exists('sapi_windows_vt100_support') &&
@sapi_windows_vt100_support(STDOUT)
) {
return true;
} elseif (getenv('ANSICON') !== false || getenv('ConEmuANSI') === 'ON') {
return true;
}

return false;
} else {
return function_exists('posix_isatty') && @posix_isatty(STDOUT);
Expand All @@ -279,7 +315,8 @@ public static function colorIsSupported(): bool
public static function are256ColorsSupported(): bool
{
if (DIRECTORY_SEPARATOR === '\\') {
return function_exists('sapi_windows_vt100_support') && @sapi_windows_vt100_support(STDOUT);
return function_exists('sapi_windows_vt100_support') &&
@sapi_windows_vt100_support(STDOUT);
} else {
return str_starts_with(getenv('TERM'), '256color');
}
Expand Down
8 changes: 7 additions & 1 deletion src/Database/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,13 @@ public static function getInstance(): \PDO

if (!isset(self::$pdo)) {
try {
self::$pdo = new \PDO(self::$dns, self::$username, self::$password, self::$options);
self::$pdo = new \PDO(
self::$dns,
self::$username,
self::$password,
self::$options
);

self::$pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
self::$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);

Expand Down
33 changes: 26 additions & 7 deletions src/ModernPHPException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ModernPHPException
{
use HelpersTrait, HandlerAssetsTrait, RenderTrait;

public const VERSION = "3.3.6";
public const VERSION = "3.3.7";

/**
* @var Bench
Expand Down Expand Up @@ -178,9 +178,21 @@ private function setConfigFile(string $config_file): void
if (!empty(self::$config_yaml)) {
$this->message_production = self::$config_yaml["error_message"] ?? "";
$this->config["title"] = self::$config_yaml["title"] ?? "";
$this->config["dark_mode"] = filter_var(self::$config_yaml["dark_mode"], FILTER_VALIDATE_BOOLEAN);
$this->config["production_mode"] = filter_var(self::$config_yaml["production_mode"], FILTER_VALIDATE_BOOLEAN);
$this->config["enable_cdn_assets"] = filter_var(self::$config_yaml["enable_cdn_assets"], FILTER_VALIDATE_BOOLEAN);

$this->config["dark_mode"] = filter_var(
self::$config_yaml["dark_mode"],
FILTER_VALIDATE_BOOLEAN
);

$this->config["production_mode"] = filter_var(
self::$config_yaml["production_mode"],
FILTER_VALIDATE_BOOLEAN
);

$this->config["enable_cdn_assets"] = filter_var(
self::$config_yaml["enable_cdn_assets"],
FILTER_VALIDATE_BOOLEAN
);
}
}

Expand All @@ -193,6 +205,7 @@ private function shutdown(): void
{
if (isset(self::$config_yaml)) {
if (isset(self::$config_yaml['enable_logs']) && self::$config_yaml['enable_logs'] == true) {

if (isset(self::$config_yaml['dir_logs']) && self::$config_yaml['dir_logs'] != "") {
Debug::dirLogger(self::$config_yaml['dir_logs']);
}
Expand Down Expand Up @@ -231,7 +244,6 @@ public function setError(int $code): ModernPHPException
E_RECOVERABLE_ERROR => 'Recoverable Warning',
E_NOTICE => 'Notice',
E_USER_NOTICE => 'User Notice',
E_STRICT => 'Strict',
E_DEPRECATED => 'Deprecated',
E_USER_DEPRECATED => 'User Deprecated'
};
Expand Down Expand Up @@ -325,7 +337,11 @@ public function errorHandler(int $code, string $message, string $file, int $line
$this->bench->end();

if (!empty($this->ignore_errors)) {
if (!is_int(array_search($this->error_code, $this->ignore_errors, true))) $this->render();
if (!is_int(array_search(
$this->error_code,
$this->ignore_errors,
true
))) $this->render();
} else {
$this->render();
}
Expand Down Expand Up @@ -354,7 +370,10 @@ public function exceptionHandler(mixed $exception): void
if ($this->getTitle() == "" || empty($this->getTitle()))
$this->setTitle("ModernPHPException: " . $message);

$reflection_class = new \ReflectionClass($this->info_error_exception['namespace_exception']);
$reflection_class = new \ReflectionClass(
$this->info_error_exception['namespace_exception']
);

$class_name = $reflection_class->newInstanceWithoutConstructor();
if (method_exists($exception, "getSolution")) $class_name->getSolution();

Expand Down
1 change: 0 additions & 1 deletion src/Resources/Markup.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public function __call($tag, $content)

/**
* Alias for getParent()
* @return Markup
*/
public function __invoke()
{
Expand Down
3 changes: 2 additions & 1 deletion src/Solution.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public function setDescription(string $description): Solution

/**
* If a documentation exists, this method will display a button for a documentation.
* By default, the name of the button will be `Read More`, but you can change the name by changing the second parameter of the method
* By default, the name of the button will be `Read More`, but you can change the name
* by changing the second parameter of the method
*
* @param string $docs_link
* @param string $button_name
Expand Down
56 changes: 45 additions & 11 deletions src/Trait/RenderTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,16 @@ public static function renderFatalError(\Throwable $e, string $message): void
$style = HtmlTag::createElement('style')->text($css);

$container = HtmlTag::createElement('body');
$container->addElement('p')->set('class', 'title')->text('Modern PHP Exception: Fatal Error');
$container->addElement('p')
->set('class', 'title')
->text('Modern PHP Exception: Fatal Error');

$container->addElement('h4')->text($e->getMessage());
$container->addElement('span')->set('class', 'solution')->text('Solution: ');

$container->addElement('span')
->set('class', 'solution')
->text('Solution: ');

$container->addElement('span')->text($message);

echo $title . PHP_EOL;
Expand All @@ -61,10 +68,15 @@ protected function registerOccurrence(): void
if ($this->type == 'error') {
$type_error = $this->getError() . "-Error";
} elseif ($this->type == 'exception') {
$type_error = $this->info_error_exception['type_exception'] . "-" . $this->info_error_exception['namespace_exception'];
$type_error = $this->info_error_exception['type_exception'] . "-" .
$this->info_error_exception['namespace_exception'];
}

Occurrences::enable($this->info_error_exception, $type_error, $this->config['production_mode']);
Occurrences::enable(
$this->info_error_exception,
$type_error,
$this->config['production_mode']
);
}

/**
Expand Down Expand Up @@ -122,7 +134,10 @@ private function productionMode(): void
private function filterTrace(array $trace): array
{
foreach ($trace as $key => $value) {
if (!array_key_exists('file', $value) && !array_key_exists('line', $value)) unset($trace[$key]);
if (
!array_key_exists('file', $value) &&
!array_key_exists('line', $value)
) unset($trace[$key]);
}

return $trace;
Expand Down Expand Up @@ -192,12 +207,16 @@ private function renderCli(): void
CliMessage::error($this->info_error_exception['type_exception'])->print() :
CliMessage::error($this->getError())->print();

CliMessage::line(" : " . $this->info_error_exception['message'])->print()->break(true);
CliMessage::line(" : " . $this->info_error_exception['message'])
->print()->break(true);

$this->renderSolutionCli();

echo "at ";
CliMessage::warning($this->info_error_exception['file'])->print();
echo " : ";
CliMessage::warning($this->info_error_exception['line'])->print()->break(true);

$this->getLines($this->info_error_exception['file'], $this->info_error_exception['line']);

if (!empty($this->trace)) {
Expand Down Expand Up @@ -296,7 +315,10 @@ private function getLines(string $context, int $line): self
private function renderSolutionCli(): void
{
if (isset($this->info_error_exception['type_exception'])) {
$reflection = new \ReflectionClass($this->info_error_exception['namespace_exception']);
$reflection = new \ReflectionClass(
$this->info_error_exception['namespace_exception']
);

$exception = $reflection->newInstanceWithoutConstructor();

if (method_exists($exception, "getSolution")) {
Expand All @@ -311,7 +333,8 @@ private function renderSolutionCli(): void
}

if (!empty($this->solution->getDocs()) || $this->solution->getDocs() != "") {
CliMessage::info(" See more in: " . $solution->getDocs()["link"])->print()->break(true);
CliMessage::info(" See more in: " . $solution->getDocs()["link"])
->print()->break(true);
}
}
}
Expand All @@ -325,11 +348,22 @@ private function renderSolutionCli(): void
public function consoleJS(): void
{
if ($this->type == "error") {
$message = str_replace(["'", '"'], "", $this->info_error_exception['message']);
$message = str_replace(
["'", '"'],
"",
$this->info_error_exception['message']
);

echo "console.error('[" . $this->getError() . "] " . $message . "')" . PHP_EOL;
} elseif ($this->type == "exception") {
$message = str_replace(["'", '"'], "", $this->info_error_exception['message']);
echo "console.error('[" . $this->info_error_exception['type_exception'] . "] " . $message . "')" . PHP_EOL;
$message = str_replace(
["'", '"'],
"",
$this->info_error_exception['message']
);

echo "console.error('[" . $this->info_error_exception['type_exception'] .
"] " . $message . "')" . PHP_EOL;
}

echo 'var user = {
Expand Down

0 comments on commit 48b9d06

Please sign in to comment.