fix: option to supress vendor deprecation

This commit is contained in:
2026-03-25 07:39:08 +01:00
parent d1eeac6692
commit 80f48f4aba
8 changed files with 134 additions and 1 deletions

View File

@@ -36,7 +36,7 @@ final class EnvValidator
}
$env = [];
foreach (array_merge(self::REQUIRED_KEYS, ['APP_URL', 'APP_CRYPTO_KEY']) as $key) {
foreach (array_merge(self::REQUIRED_KEYS, ['APP_URL', 'APP_CRYPTO_KEY', 'APP_VENDOR_PHP_ISSUES_MODE']) as $key) {
$env[$key] = getenv($key);
}
@@ -97,6 +97,14 @@ final class EnvValidator
$errors[] = "TENANT_SCOPE_STRICT must be a boolean value (true/false/1/0)";
}
$vendorPhpIssuesMode = strtolower(self::value($env, 'APP_VENDOR_PHP_ISSUES_MODE'));
if (
$vendorPhpIssuesMode !== ''
&& !in_array($vendorPhpIssuesMode, ['strict', 'suppress_deprecations', 'suppress_deprecations_warnings'], true)
) {
$errors[] = 'APP_VENDOR_PHP_ISSUES_MODE must be one of: strict, suppress_deprecations, suppress_deprecations_warnings';
}
$reverseProxy = self::value($env, 'FIREWALL_REVERSE_PROXY');
if ($reverseProxy !== '' && self::parseBool($reverseProxy) === null) {
$errors[] = "FIREWALL_REVERSE_PROXY must be a boolean value (true/false/1/0)";

View File

@@ -30,6 +30,7 @@ final class ErrorDataCollector
'APP_TIMEZONE',
'APP_LOCALE',
'APP_URL',
'APP_VENDOR_PHP_ISSUES_MODE',
'TENANT_SCOPE_STRICT',
];

View File

@@ -96,6 +96,10 @@ final class ErrorHandler
return true;
}
if (self::shouldSuppressVendorIssue($severity, $file)) {
return true;
}
throw new \ErrorException($message, 0, $severity, $file, $line);
}
@@ -194,4 +198,46 @@ final class ErrorHandler
{
return defined('PHPUNIT_COMPOSER_INSTALL') || defined('__PHPUNIT_PHAR__');
}
private static function shouldSuppressVendorIssue(int $severity, string $file): bool
{
if (!self::isVendorPath($file)) {
return false;
}
return match (self::vendorIssueMode()) {
'suppress_deprecations' => self::isDeprecationSeverity($severity),
'suppress_deprecations_warnings' => self::isDeprecationSeverity($severity) || self::isWarningSeverity($severity),
default => false,
};
}
private static function vendorIssueMode(): string
{
$raw = getenv('APP_VENDOR_PHP_ISSUES_MODE');
if ($raw === false) {
return 'strict';
}
$mode = strtolower(trim((string) $raw));
return in_array($mode, ['strict', 'suppress_deprecations', 'suppress_deprecations_warnings'], true)
? $mode
: 'strict';
}
private static function isDeprecationSeverity(int $severity): bool
{
return in_array($severity, [E_DEPRECATED, E_USER_DEPRECATED], true);
}
private static function isWarningSeverity(int $severity): bool
{
return in_array($severity, [E_WARNING, E_USER_WARNING], true);
}
private static function isVendorPath(string $file): bool
{
$normalized = str_replace('\\', '/', $file);
return str_contains($normalized, '/vendor/');
}
}