From 897f9906f948000c06360640449f88ee09cfebf4 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Fri, 21 Oct 2022 10:08:31 +1300 Subject: [PATCH] FIX Handle calling Deprecation::notice() before manifests are available --- src/Core/Injector/InjectorLoader.php | 4 +++- src/Dev/Deprecation.php | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Core/Injector/InjectorLoader.php b/src/Core/Injector/InjectorLoader.php index 54bd6b4b5e0..4b5a857a5a6 100644 --- a/src/Core/Injector/InjectorLoader.php +++ b/src/Core/Injector/InjectorLoader.php @@ -9,6 +9,8 @@ */ class InjectorLoader { + public const NO_MANIFESTS_AVAILABLE = 'No injector manifests available'; + /** * @internal * @var self @@ -42,7 +44,7 @@ public function getManifest() ); } if (empty($this->manifests)) { - throw new BadMethodCallException("No injector manifests available"); + throw new BadMethodCallException(self::NO_MANIFESTS_AVAILABLE); } return $this->manifests[count($this->manifests) - 1]; } diff --git a/src/Dev/Deprecation.php b/src/Dev/Deprecation.php index acd4094707e..5a222100e75 100644 --- a/src/Dev/Deprecation.php +++ b/src/Dev/Deprecation.php @@ -2,8 +2,11 @@ namespace SilverStripe\Dev; +use BadMethodCallException; +use Exception; use SilverStripe\Control\Director; use SilverStripe\Core\Environment; +use SilverStripe\Core\Injector\InjectorLoader; use SilverStripe\Core\Manifest\Module; /** @@ -234,6 +237,14 @@ public static function notice($atVersion, $string = '', $scope = Deprecation::SC } else { user_error($string, self::$notice_level); } + } catch (BadMethodCallException $e) { + if ($e->getMessage() === InjectorLoader::NO_MANIFESTS_AVAILABLE) { + // noop + // this can happen when calling Deprecation::notice() before manifests are available, i.e. + // some of the code involved in creating the manifests calls Deprecation::notice() + } else { + throw $e; + } } finally { static::$inside_notice = false; }