From 4ace454c597fb0669e88ec7f64ba40c0ccdaf358 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 14 Apr 2018 23:21:30 +0200 Subject: [PATCH] Continued: - assignVariable() should validate $variableName if NULL or empty MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Roland Häder --- .../template/class_BaseTemplateEngine.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/framework/main/classes/template/class_BaseTemplateEngine.php b/framework/main/classes/template/class_BaseTemplateEngine.php index 67a4baef..adcfda26 100644 --- a/framework/main/classes/template/class_BaseTemplateEngine.php +++ b/framework/main/classes/template/class_BaseTemplateEngine.php @@ -7,6 +7,7 @@ use Org\Mxchange\CoreFramework\Bootstrap\FrameworkBootstrap; use Org\Mxchange\CoreFramework\EntryPoint\ApplicationEntryPoint; use Org\Mxchange\CoreFramework\Factory\ObjectFactory; use Org\Mxchange\CoreFramework\Filesystem\FileNotFoundException; +use Org\Mxchange\CoreFramework\Generic\NullPointerException; use Org\Mxchange\CoreFramework\Manager\ManageableApplication; use Org\Mxchange\CoreFramework\Object\BaseFrameworkSystem; use Org\Mxchange\CoreFramework\Registry\GenericRegistry; @@ -1114,17 +1115,21 @@ abstract class BaseTemplateEngine extends BaseFrameworkSystem { * @param $variableName The variable we are looking for * @param $value The value we want to store in the variable * @return void + * @throws NullPointerException If $variableName is NULL * @throws InvalidArgumentException If the variable name is left empty */ public final function assignVariable ($variableName, $value) { - // Replace all dashes to underscores to match variables with configuration entries - $variableName = trim(StringUtils::convertDashesToUnderscores($variableName)); - - // Empty variable found? - if (empty($variableName)) { + // Validate parameter + if (is_null($variableName)) { + // Throw NPE + throw new NullPointerException($this, self::EXCEPTION_IS_NULL_POINTER); + } elseif (empty($variableName)) { // Throw an exception throw new InvalidArgumentException('Parameter "variableName" is empty'); - } // END - if + } + + // Replace all dashes to underscores to match variables with configuration entries + $variableName = trim(StringUtils::convertDashesToUnderscores($variableName)); // First search for the variable if it was already added $index = $this->getVariableIndex($variableName); -- 2.39.5