fix: option to supress vendor deprecation
This commit is contained in:
@@ -2,6 +2,7 @@ APP_NAME=CoreCore
|
||||
APP_URL=http://localhost:8080
|
||||
APP_ENV=dev
|
||||
APP_DEBUG=true
|
||||
APP_VENDOR_PHP_ISSUES_MODE=suppress_deprecations
|
||||
APP_CONFIG_VALIDATE=true
|
||||
APP_TIMEZONE=Europe/Berlin
|
||||
APP_STORAGE_PATH=./storage
|
||||
|
||||
@@ -2,6 +2,7 @@ APP_NAME=CoreCore
|
||||
APP_URL=https://example.com
|
||||
APP_ENV=prod
|
||||
APP_DEBUG=false
|
||||
APP_VENDOR_PHP_ISSUES_MODE=strict
|
||||
APP_CONFIG_VALIDATE=true
|
||||
APP_TIMEZONE=Europe/Berlin
|
||||
APP_STORAGE_PATH=./storage
|
||||
|
||||
@@ -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)";
|
||||
|
||||
@@ -30,6 +30,7 @@ final class ErrorDataCollector
|
||||
'APP_TIMEZONE',
|
||||
'APP_LOCALE',
|
||||
'APP_URL',
|
||||
'APP_VENDOR_PHP_ISSUES_MODE',
|
||||
'TENANT_SCOPE_STRICT',
|
||||
];
|
||||
|
||||
|
||||
@@ -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/');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -713,6 +713,7 @@ $openOverrideCard = $detailsOpenAll;
|
||||
$openLdapSetupCard = $detailsOpenAll || !$ldapEnabled || ($ldapEnabled && !$ldapConfigComplete);
|
||||
?>
|
||||
<hr>
|
||||
<div data-tenant-ldap-root>
|
||||
<h4><?php e(t('LDAP Authentication')); ?></h4>
|
||||
|
||||
<div class="app-form-info-tiles">
|
||||
@@ -747,9 +748,11 @@ $openOverrideCard = $detailsOpenAll;
|
||||
<div class="app-details-card-container">
|
||||
<label class="app-field">
|
||||
<input type="checkbox" role="switch" name="ldap_enabled" value="1"
|
||||
data-tenant-ldap-enabled
|
||||
<?php e($ldapEnabled ? 'checked' : ''); ?> <?php e($disabledAttr); ?>>
|
||||
<span><?php e(t('Enable LDAP login for this tenant')); ?></span>
|
||||
</label>
|
||||
<div data-tenant-ldap-when-enabled>
|
||||
<hr>
|
||||
<div class="grid grid-1-1">
|
||||
<label>
|
||||
|
||||
@@ -113,6 +113,27 @@ final class EnvValidatorTest extends TestCase
|
||||
$this->assertContains('APP_URL must not use localhost or an IP host in production', $errors);
|
||||
}
|
||||
|
||||
public function testValidateArrayAcceptsSupportedVendorPhpIssuesMode(): void
|
||||
{
|
||||
$errors = EnvValidator::validateArray($this->baseEnv([
|
||||
'APP_VENDOR_PHP_ISSUES_MODE' => 'suppress_deprecations',
|
||||
]));
|
||||
|
||||
$this->assertSame([], $errors);
|
||||
}
|
||||
|
||||
public function testValidateArrayRejectsUnsupportedVendorPhpIssuesMode(): void
|
||||
{
|
||||
$errors = EnvValidator::validateArray($this->baseEnv([
|
||||
'APP_VENDOR_PHP_ISSUES_MODE' => 'disable_everything',
|
||||
]));
|
||||
|
||||
$this->assertContains(
|
||||
'APP_VENDOR_PHP_ISSUES_MODE must be one of: strict, suppress_deprecations, suppress_deprecations_warnings',
|
||||
$errors
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $override
|
||||
* @return array<string, string>
|
||||
@@ -125,6 +146,7 @@ final class EnvValidatorTest extends TestCase
|
||||
'APP_NAME' => 'CoreCore',
|
||||
'APP_ENV' => 'dev',
|
||||
'APP_DEBUG' => 'true',
|
||||
'APP_VENDOR_PHP_ISSUES_MODE' => 'strict',
|
||||
'APP_TIMEZONE' => 'Europe/Berlin',
|
||||
'APP_STORAGE_PATH' => $storagePath,
|
||||
'APP_LOCALE' => 'de',
|
||||
|
||||
@@ -10,10 +10,15 @@ use PHPUnit\Framework\TestCase;
|
||||
class ErrorHandlerTest extends TestCase
|
||||
{
|
||||
private array $serverBackup = [];
|
||||
private int $errorReportingBackup = 0;
|
||||
private string|false $vendorIssueModeBackup = false;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->serverBackup = $_SERVER;
|
||||
$this->errorReportingBackup = error_reporting();
|
||||
error_reporting(E_ALL);
|
||||
$this->vendorIssueModeBackup = getenv('APP_VENDOR_PHP_ISSUES_MODE');
|
||||
RequestContext::resetForTests();
|
||||
Debugger::$enabled = false;
|
||||
header_remove();
|
||||
@@ -23,6 +28,12 @@ class ErrorHandlerTest extends TestCase
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$_SERVER = $this->serverBackup;
|
||||
error_reporting($this->errorReportingBackup);
|
||||
if ($this->vendorIssueModeBackup === false) {
|
||||
putenv('APP_VENDOR_PHP_ISSUES_MODE');
|
||||
} else {
|
||||
putenv('APP_VENDOR_PHP_ISSUES_MODE=' . $this->vendorIssueModeBackup);
|
||||
}
|
||||
RequestContext::resetForTests();
|
||||
Debugger::$enabled = false;
|
||||
header_remove();
|
||||
@@ -75,4 +86,44 @@ class ErrorHandlerTest extends TestCase
|
||||
|
||||
$this->assertSame(500, http_response_code());
|
||||
}
|
||||
|
||||
public function testHandleErrorThrowsForVendorDeprecationInStrictMode(): void
|
||||
{
|
||||
putenv('APP_VENDOR_PHP_ISSUES_MODE=strict');
|
||||
|
||||
$this->expectException(\ErrorException::class);
|
||||
ErrorHandler::handleError(E_DEPRECATED, 'deprecated', '/var/www/vendor/mintyphp/core/src/Router.php', 69);
|
||||
}
|
||||
|
||||
public function testHandleErrorSuppressesVendorDeprecationsWhenConfigured(): void
|
||||
{
|
||||
putenv('APP_VENDOR_PHP_ISSUES_MODE=suppress_deprecations');
|
||||
|
||||
$result = ErrorHandler::handleError(E_DEPRECATED, 'deprecated', '/var/www/vendor/mintyphp/core/src/Router.php', 69);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testHandleErrorSuppressesVendorWarningsOnlyInWarningMode(): void
|
||||
{
|
||||
putenv('APP_VENDOR_PHP_ISSUES_MODE=suppress_deprecations');
|
||||
|
||||
try {
|
||||
ErrorHandler::handleError(E_WARNING, 'warning', '/var/www/vendor/mintyphp/core/src/Router.php', 69);
|
||||
$this->fail('Expected ErrorException for vendor warning in suppress_deprecations mode.');
|
||||
} catch (\ErrorException) {
|
||||
// expected
|
||||
}
|
||||
|
||||
putenv('APP_VENDOR_PHP_ISSUES_MODE=suppress_deprecations_warnings');
|
||||
$result = ErrorHandler::handleError(E_WARNING, 'warning', '/var/www/vendor/mintyphp/core/src/Router.php', 69);
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testHandleErrorNeverSuppressesNonVendorWarnings(): void
|
||||
{
|
||||
putenv('APP_VENDOR_PHP_ISSUES_MODE=suppress_deprecations_warnings');
|
||||
|
||||
$this->expectException(\ErrorException::class);
|
||||
ErrorHandler::handleError(E_WARNING, 'warning', '/var/www/lib/Http/ErrorHandler.php', 69);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user