Skip to content

Commit

Permalink
Add support for ignoring deprecations by path
Browse files Browse the repository at this point in the history
Being able to have deprecations on globally but silence problematic
parts of your application or a noisy plugin that can't be upgraded just
yet allows developers more control when upgrading.

Instead of having to hope they don't add new deprecations they can fix
a part of their application and then remove it from the deprecation
ignore patterns.

I've used glob here instead of regex as I don't think the power of regex
is needed for this.

Refs cakephp/cakephp#14915
  • Loading branch information
markstory committed Aug 23, 2020
1 parent ae5ce39 commit 54b10bb
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,16 @@ function deprecationWarning(string $message, int $stackFrame = 1): void
$frame = $trace[$stackFrame];
$frame += ['file' => '[internal]', 'line' => '??'];

$patterns = (array)Configure::read('Error.disableDeprecations');
$relative = substr($frame['file'], strlen(ROOT) + 1);
debug($relative);
foreach ($patterns as $pattern) {
$pattern = str_replace('/', DIRECTORY_SEPARATOR, $pattern);
if (fnmatch($pattern, $relative)) {
return;
}
}

$message = sprintf(
'%s - %s, line: %s' . "\n" .
' You can disable deprecation warnings by setting `Error.errorLevel` to' .
Expand Down

0 comments on commit 54b10bb

Please sign in to comment.