@@ -88,9 +88,9 @@ final class WebView implements ViewInterface
8888
8989 /**
9090 * @param string $basePath The full path to the base directory of views.
91- * @param EventDispatcherInterface $eventDispatcher The event dispatcher instance.
91+ * @param EventDispatcherInterface|null $eventDispatcher The event dispatcher instance.
9292 */
93- public function __construct (string $ basePath , EventDispatcherInterface $ eventDispatcher )
93+ public function __construct (string $ basePath , ? EventDispatcherInterface $ eventDispatcher = null )
9494 {
9595 $ this ->basePath = $ basePath ;
9696 $ this ->state = new WebViewState ();
@@ -117,7 +117,7 @@ public function withClearedState(): static
117117 public function head (): void
118118 {
119119 echo sprintf (self ::PLACEHOLDER_HEAD , $ this ->getPlaceholderSignature ());
120- $ this ->eventDispatcher ->dispatch (new Head ($ this ));
120+ $ this ->eventDispatcher ? ->dispatch(new Head ($ this ));
121121 }
122122
123123 /**
@@ -126,15 +126,15 @@ public function head(): void
126126 public function beginBody (): void
127127 {
128128 echo sprintf (self ::PLACEHOLDER_BODY_BEGIN , $ this ->getPlaceholderSignature ());
129- $ this ->eventDispatcher ->dispatch (new BodyBegin ($ this ));
129+ $ this ->eventDispatcher ? ->dispatch(new BodyBegin ($ this ));
130130 }
131131
132132 /**
133133 * Marks the ending of an HTML body section.
134134 */
135135 public function endBody (): void
136136 {
137- $ this ->eventDispatcher ->dispatch (new BodyEnd ($ this ));
137+ $ this ->eventDispatcher ? ->dispatch(new BodyEnd ($ this ));
138138 echo sprintf (self ::PLACEHOLDER_BODY_END , $ this ->getPlaceholderSignature ());
139139 }
140140
@@ -145,7 +145,7 @@ public function beginPage(): void
145145 {
146146 ob_start ();
147147 ob_implicit_flush (false );
148- $ this ->eventDispatcher ->dispatch (new PageBegin ($ this ));
148+ $ this ->eventDispatcher ? ->dispatch(new PageBegin ($ this ));
149149 }
150150
151151 /**
@@ -157,7 +157,7 @@ public function beginPage(): void
157157 */
158158 public function endPage (bool $ ajaxMode = false ): void
159159 {
160- $ this ->eventDispatcher ->dispatch (new PageEnd ($ this ));
160+ $ this ->eventDispatcher ? ->dispatch(new PageEnd ($ this ));
161161
162162 $ content = ob_get_clean ();
163163
0 commit comments