From 651e9db9a5a5bd89ea603e64f69425bdee79cb6f Mon Sep 17 00:00:00 2001 From: Tim van Dijen <tvdijen@gmail.com> Date: Wed, 21 Sep 2022 15:10:50 +0200 Subject: [PATCH] Throw an exception when configured theme controller is invalid --- src/SimpleSAML/XHTML/Template.php | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/SimpleSAML/XHTML/Template.php b/src/SimpleSAML/XHTML/Template.php index 149ccb0c4..5387aea68 100644 --- a/src/SimpleSAML/XHTML/Template.php +++ b/src/SimpleSAML/XHTML/Template.php @@ -165,13 +165,19 @@ class Template extends Response // check if we need to attach a theme controller $controller = $this->configuration->getOptionalString('theme.controller', null); - if ( - $controller !== null - && class_exists($controller) - && in_array(TemplateControllerInterface::class, class_implements($controller)) - ) { - /** @var \SimpleSAML\XHTML\TemplateControllerInterface $this->controller */ - $this->controller = new $controller(); + if ($controller !== null) { + if ( + class_exists($controller) + && in_array(TemplateControllerInterface::class, class_implements($controller)) + ) { + /** @var \SimpleSAML\XHTML\TemplateControllerInterface $this->controller */ + $this->controller = new $controller(); + } else { + throw new Error\ConfigurationError( + 'Invalid controller was configured in `theme.controller`. ' . + ' Make sure the class exists and implements the TemplateControllerInterface.' + ); + } } $this->fileSystem = new Filesystem(); -- GitLab