1313
1414use InvalidArgumentException ;
1515use Psr \Http \Message \ResponseInterface ;
16+ use RuntimeException ;
17+ use Throwable ;
1618
1719/**
1820 * Class PhpRenderer
@@ -49,8 +51,9 @@ public function __construct(string $templatePath = "", array $attributes = [], s
4951 *
5052 * @note $data cannot contain template as a key
5153 *
52- * @throws \InvalidArgumentException
53- * @throws \RuntimeException if $templatePath . $template does not exist
54+ * @throws InvalidArgumentException
55+ * @throws RuntimeException if $templatePath . $template does not exist
56+ * @throws Throwable
5457 */
5558 public function render (ResponseInterface $ response , string $ template , array $ data = []): ResponseInterface
5659 {
@@ -74,12 +77,12 @@ public function getLayout(): string
7477 */
7578 public function setLayout (string $ layout ): void
7679 {
77- if ($ layout === "" || $ layout === null ) {
80+ if ($ layout === '' || $ layout === null ) {
7881 $ this ->layout = null ;
7982 } else {
8083 $ layoutPath = $ this ->templatePath . $ layout ;
8184 if (!is_file ($ layoutPath )) {
82- throw new \ RuntimeException ("Layout template ` $ layout` does not exist " );
85+ throw new RuntimeException ("Layout template ` $ layout` does not exist " );
8386 }
8487 $ this ->layout = $ layout ;
8588 }
@@ -144,8 +147,9 @@ public function setTemplatePath(string $templatePath): void
144147 *
145148 * @note $data cannot contain template as a key
146149 *
147- * @throws \InvalidArgumentException
148- * @throws \RuntimeException
150+ * @throws InvalidArgumentException
151+ * @throws RuntimeException
152+ * @throws Throwable
149153 */
150154 public function fetch (string $ template , array $ data = [], bool $ useLayout = false ): string
151155 {
@@ -164,17 +168,18 @@ public function fetch(string $template, array $data = [], bool $useLayout = fals
164168 *
165169 * @note $data cannot contain template as a key
166170 *
167- * @throws \InvalidArgumentException
168- * @throws \RuntimeException
171+ * @throws InvalidArgumentException
172+ * @throws RuntimeException
173+ * @throws Throwable
169174 */
170175 public function fetchTemplate (string $ template , array $ data = []): string
171176 {
172177 if (isset ($ data ['template ' ])) {
173- throw new \ InvalidArgumentException (" Duplicate template key found " );
178+ throw new InvalidArgumentException (' Duplicate template key found ' );
174179 }
175180
176181 if (!is_file ($ this ->templatePath . $ template )) {
177- throw new \ RuntimeException ("View cannot render ` $ template` because the template does not exist " );
182+ throw new RuntimeException ("View cannot render ` $ template` because the template does not exist " );
178183 }
179184
180185 $ data = array_merge ($ this ->attributes , $ data );
@@ -183,10 +188,7 @@ public function fetchTemplate(string $template, array $data = []): string
183188 ob_start ();
184189 $ this ->protectedIncludeScope ($ this ->templatePath . $ template , $ data );
185190 $ output = ob_get_clean ();
186- } catch (\Throwable $ e ) { // PHP 7+
187- ob_end_clean ();
188- throw $ e ;
189- } catch (\Exception $ e ) { // PHP < 7
191+ } catch (Throwable $ e ) {
190192 ob_end_clean ();
191193 throw $ e ;
192194 }
0 commit comments