Skip to content

Commit

Permalink
Merge pull request #624 from phel-lang/feat/614-improve-deprecated-notes
Browse files Browse the repository at this point in the history
Define a custom registerDeprecatedHandler
  • Loading branch information
Chemaclass committed Oct 21, 2023
2 parents d68f97d + 8756c7e commit c1ae0e5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.

* Fix do not create the entrypoint when namespace isn't set
* Fix AtomParser decimal regex
* Improve deprecated notes output

## 0.11.0 (2023-08-26)

Expand Down
31 changes: 31 additions & 0 deletions src/php/Command/Domain/Handler/ExceptionHandler.php
Expand Up @@ -11,6 +11,7 @@
final class ExceptionHandler
{
private static string $previousNotice = '';
private static string $previousDeprecated = '';

public function __construct(
private ExceptionPrinterInterface $exceptionPrinter,
Expand All @@ -21,6 +22,7 @@ public function register(): void
{
$this->registerExceptionHandler();
$this->registerNoticeHandler();
$this->registerDeprecatedHandler();
}

private function registerExceptionHandler(): void
Expand Down Expand Up @@ -61,4 +63,33 @@ private function registerNoticeHandler(): void
return true;
}, E_NOTICE);
}

private function registerDeprecatedHandler(): void
{
set_error_handler(function (
int $errno,
string $errstr,
string $errfile = '',
int $errline = 0,
array $errcontext = [],
): bool {
$text = sprintf(
"[%s] DEPRECATED found!\nmessage: \"%s\"\nfile: %s:%d\ncontext: %s",
date(DATE_ATOM),
$errstr,
$errfile,
$errline,
json_encode(array_merge($errcontext, ['errno' => $errno])),
);

if (self::$previousDeprecated !== $text) {
$this->exceptionPrinter->printError($text);
} else {
$this->exceptionPrinter->printError('and again');
}

self::$previousDeprecated = $text;
return true;
}, E_DEPRECATED);
}
}

0 comments on commit c1ae0e5

Please sign in to comment.