From: Roland Häder Date: Sat, 14 Apr 2018 21:21:30 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?p=core.git;a=commitdiff_plain;h=4ace454c597fb0669e88ec7f64ba40c0ccdaf358 Continued: - assignVariable() should validate $variableName if NULL or empty Signed-off-by: Roland Häder --- 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);