@@ -28,6 +28,7 @@ class Debugger
2828 */
2929 protected array $ options = [];
3030 protected string $ debugbarView = __DIR__ . '/Views/debugbar/debugbar.php ' ;
31+ protected bool $ debugbarEnabled = true ;
3132
3233 public function addCollection (Collection $ collection ) : static
3334 {
@@ -141,6 +142,9 @@ public function getDebugbarView() : string
141142
142143 public function renderDebugbar () : string
143144 {
145+ if (!$ this ->isDebugbarEnabled ()) {
146+ return '' ;
147+ }
144148 \ob_start ();
145149 Isolation::require ($ this ->getDebugbarView (), [
146150 'collections ' => $ this ->getCollections (),
@@ -150,6 +154,44 @@ public function renderDebugbar() : string
150154 return \ob_get_clean (); // @phpstan-ignore-line
151155 }
152156
157+ /**
158+ * Tells if debugbar rendering is enabled.
159+ *
160+ * @since 4.2
161+ *
162+ * @return bool
163+ */
164+ public function isDebugbarEnabled () : bool
165+ {
166+ return $ this ->debugbarEnabled ;
167+ }
168+
169+ /**
170+ * Enables debugbar rendering.
171+ *
172+ * @since 4.2
173+ *
174+ * @return static
175+ */
176+ public function enableDebugbar () : static
177+ {
178+ $ this ->debugbarEnabled = true ;
179+ return $ this ;
180+ }
181+
182+ /**
183+ * Disables debugbar rendering.
184+ *
185+ * @since 4.2
186+ *
187+ * @return static
188+ */
189+ public function disableDebugbar () : static
190+ {
191+ $ this ->debugbarEnabled = false ;
192+ return $ this ;
193+ }
194+
153195 public static function makeSafeName (string $ name ) : string
154196 {
155197 return \strtr (\trim (\strip_tags (\strtolower ($ name ))), [
0 commit comments