@@ -48,6 +48,7 @@ class View
4848 */
4949 protected array $ viewsPaths = [];
5050 protected string $ instanceName ;
51+ protected bool $ throwExceptionsInDestructor = true ;
5152
5253 public function __construct (?string $ baseDir = null , string $ extension = '.php ' )
5354 {
@@ -59,7 +60,7 @@ public function __construct(?string $baseDir = null, string $extension = '.php')
5960
6061 public function __destruct ()
6162 {
62- if ($ this ->openBlocks ) {
63+ if ($ this ->isThrowExceptionsInDestructor () && $ this -> openBlocks ) {
6364 throw new LogicException (
6465 'Trying to destruct a View instance while the following blocks stayed open: '
6566 . \implode (', ' , \array_map (static function ($ name ) {
@@ -69,6 +70,24 @@ public function __destruct()
6970 }
7071 }
7172
73+ public function isThrowExceptionsInDestructor () : bool
74+ {
75+ return $ this ->throwExceptionsInDestructor ;
76+ }
77+
78+ /**
79+ * Enables/disables exceptions in the destructor.
80+ *
81+ * @param bool $active True to throw exceptions, false otherwise
82+ *
83+ * @return static
84+ */
85+ public function setThrowExceptionsInDestructor (bool $ active = true ) : static
86+ {
87+ $ this ->throwExceptionsInDestructor = $ active ;
88+ return $ this ;
89+ }
90+
7291 public function setBaseDir (string $ baseDir ) : static
7392 {
7493 $ real = \realpath ($ baseDir );
0 commit comments