@@ -48,6 +48,7 @@ class View
48
48
*/
49
49
protected array $ viewsPaths = [];
50
50
protected string $ instanceName ;
51
+ protected bool $ throwExceptionsInDestructor = true ;
51
52
52
53
public function __construct (?string $ baseDir = null , string $ extension = '.php ' )
53
54
{
@@ -59,7 +60,7 @@ public function __construct(?string $baseDir = null, string $extension = '.php')
59
60
60
61
public function __destruct ()
61
62
{
62
- if ($ this ->openBlocks ) {
63
+ if ($ this ->isThrowExceptionsInDestructor () && $ this -> openBlocks ) {
63
64
throw new LogicException (
64
65
'Trying to destruct a View instance while the following blocks stayed open: '
65
66
. \implode (', ' , \array_map (static function ($ name ) {
@@ -69,6 +70,24 @@ public function __destruct()
69
70
}
70
71
}
71
72
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
+
72
91
public function setBaseDir (string $ baseDir ) : static
73
92
{
74
93
$ real = \realpath ($ baseDir );
0 commit comments