Skip to content

Commit

Permalink
FIX Handle calling Deprecation::notice() before manifests are available
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Oct 20, 2022
1 parent 421b706 commit a3fe1d1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Core/Injector/InjectorLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
class InjectorLoader
{
public const NO_MANIFESTS_AVAILABLE = 'No injector manifests available';

/**
* @internal
* @var self
Expand Down Expand Up @@ -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];
}
Expand Down
11 changes: 11 additions & 0 deletions src/Dev/Deprecation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -234,6 +237,14 @@ public static function notice($atVersion, $string = '', $scope = Deprecation::SC
} else {
user_error($string, self::$notice_level);
}
} catch (Exception $e) {
if ($e instanceof BadMethodCallException && $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;
}
Expand Down

0 comments on commit a3fe1d1

Please sign in to comment.