From 62b6f612eed0beb0d5acb7f8111615433440925c Mon Sep 17 00:00:00 2001 From: Ibrahim BinAlshikh Date: Wed, 3 Jan 2024 17:37:57 +0300 Subject: [PATCH] Rename `ParamTypes` to `ParamType` --- tests/loader.php | 2 +- .../tests/http/RequestParameterTest.php | 4 +- tests/webfiori/tests/http/WebServiceTest.php | 4 +- .../testServices/CreateUserProfileService.php | 8 +-- webfiori/http/APIFilter.php | 52 +++++++++---------- webfiori/http/ManagerInfoService.php | 2 +- .../http/{ParamTypes.php => ParamType.php} | 2 +- webfiori/http/RequestParameter.php | 26 +++++----- 8 files changed, 50 insertions(+), 50 deletions(-) rename webfiori/http/{ParamTypes.php => ParamType.php} (99%) diff --git a/tests/loader.php b/tests/loader.php index 2e124e2..eb56134 100644 --- a/tests/loader.php +++ b/tests/loader.php @@ -53,7 +53,7 @@ require_once $rootDir.'webfiori'.$DS.'http'.$DS.'HttpHeader.php'; require_once $rootDir.'webfiori'.$DS.'http'.$DS.'HttpCookie.php'; require_once $rootDir.'webfiori'.$DS.'http'.$DS.'HeadersPool.php'; -require_once $rootDir.'webfiori'.$DS.'http'.$DS.'ParamTypes.php'; +require_once $rootDir.'webfiori'.$DS.'http'.$DS.'ParamType.php'; require_once $rootDir.'webfiori'.$DS.'http'.$DS.'ParamOption.php'; require_once $rootDir.'webfiori'.$DS.'http'.$DS.'AbstractWebService.php'; require_once $rootDir.'webfiori'.$DS.'http'.$DS.'APIFilter.php'; diff --git a/tests/webfiori/tests/http/RequestParameterTest.php b/tests/webfiori/tests/http/RequestParameterTest.php index ee12a1a..42c0089 100644 --- a/tests/webfiori/tests/http/RequestParameterTest.php +++ b/tests/webfiori/tests/http/RequestParameterTest.php @@ -5,7 +5,7 @@ use PHPUnit\Framework\TestCase; use webfiori\http\APIFilter; use webfiori\http\ParamOption; -use webfiori\http\ParamTypes; +use webfiori\http\ParamType; use webfiori\http\RequestParameter; /** * Description of RequestParameterTest @@ -58,7 +58,7 @@ public function testCreateParameter02() { public function testCreateParameter03() { $param = RequestParameter::create([ 'name'=>'ok', - ParamOption::TYPE => ParamTypes::STRING, + ParamOption::TYPE => ParamType::STRING, ParamOption::DEFAULT => 'Ibrahim', ParamOption::EMPTY => true, ParamOption::DESCRIPTION => 'Super param.' diff --git a/tests/webfiori/tests/http/WebServiceTest.php b/tests/webfiori/tests/http/WebServiceTest.php index 295b59b..c458243 100644 --- a/tests/webfiori/tests/http/WebServiceTest.php +++ b/tests/webfiori/tests/http/WebServiceTest.php @@ -3,7 +3,7 @@ use PHPUnit\Framework\TestCase; use webfiori\http\ParamOption; -use webfiori\http\ParamTypes; +use webfiori\http\ParamType; use webfiori\http\RequestMethod; use webfiori\http\RequestParameter; use webfiori\tests\http\testServices\NoAuthService; @@ -75,7 +75,7 @@ public function testAddParameter01() { $action = new TestServiceObj('add-user'); $this->assertTrue($action->addParameter([ ParamOption::NAME => 'new-param', - ParamOption::TYPE => ParamTypes::BOOL + ParamOption::TYPE => ParamType::BOOL ])); $this->assertEquals(1,count($action->getParameters())); diff --git a/tests/webfiori/tests/http/testServices/CreateUserProfileService.php b/tests/webfiori/tests/http/testServices/CreateUserProfileService.php index ae33dac..3504e0d 100644 --- a/tests/webfiori/tests/http/testServices/CreateUserProfileService.php +++ b/tests/webfiori/tests/http/testServices/CreateUserProfileService.php @@ -4,7 +4,7 @@ use Exception; use webfiori\http\ParamOption; -use webfiori\http\ParamTypes; +use webfiori\http\ParamType; use webfiori\http\RequestMethod; use webfiori\http\RequestParameter; use webfiori\json\Json; @@ -21,13 +21,13 @@ public function __construct() { $this->getParameterByName('id')->setIsOptional(true); $this->addParameters([ 'name' => [ - ParamOption::TYPE => ParamTypes::STRING + ParamOption::TYPE => ParamType::STRING ], 'username' => [ - ParamOption::TYPE => ParamTypes::STRING + ParamOption::TYPE => ParamType::STRING ], 'x' => [ - ParamOption::TYPE => ParamTypes::INT, + ParamOption::TYPE => ParamType::INT, ParamOption::OPTIONAL => true, ParamOption::DEFAULT => 3 ] diff --git a/webfiori/http/APIFilter.php b/webfiori/http/APIFilter.php index 32c9710..c300ba2 100644 --- a/webfiori/http/APIFilter.php +++ b/webfiori/http/APIFilter.php @@ -82,21 +82,21 @@ public function addRequestParameter(RequestParameter $reqParam) { } $paramType = $reqParam->getType(); - if ($paramType == ParamTypes::INT) { + if ($paramType == ParamType::INT) { $attribute[$filterIdx][] = FILTER_VALIDATE_INT; $this->checkNumericRange($reqParam, $attribute); - } else if ($paramType == ParamTypes::STRING) { + } else if ($paramType == ParamType::STRING) { $attribute[$optIdx][$optIdx]['allow-empty'] = $reqParam->isEmptyStringAllowed(); $attribute[$filterIdx][] = FILTER_DEFAULT; $this->checkStringLength($reqParam, $attribute); - } else if ($paramType == ParamTypes::DOUBLE) { + } else if ($paramType == ParamType::DOUBLE) { $attribute[$filterIdx][] = FILTER_VALIDATE_FLOAT; $this->checkNumericRange($reqParam, $attribute); - } else if ($paramType == ParamTypes::EMAIL) { + } else if ($paramType == ParamType::EMAIL) { $attribute[$filterIdx][] = FILTER_SANITIZE_EMAIL; $attribute[$filterIdx][] = FILTER_VALIDATE_EMAIL; $this->checkStringLength($reqParam, $attribute); - } else if ($paramType == ParamTypes::URL) { + } else if ($paramType == ParamType::URL) { $attribute[$filterIdx][] = FILTER_SANITIZE_URL; $attribute[$filterIdx][] = FILTER_VALIDATE_URL; $this->checkStringLength($reqParam, $attribute); @@ -176,7 +176,7 @@ public static function filter(APIFilter $apiFilter, array $arr): array { } else { $retVal[$filteredIdx][$name] = self::applyBasicFilterOnly($def, $toBeFiltered); } - $booleanCheck = $paramType == ParamTypes::BOOL && $retVal[$filteredIdx][$name] === true || $retVal[$filteredIdx][$name] === false; + $booleanCheck = $paramType == ParamType::BOOL && $retVal[$filteredIdx][$name] === true || $retVal[$filteredIdx][$name] === false; if (!$booleanCheck && $retVal[$filteredIdx][$name] == self::INVALID && $defaultVal !== null) { $retVal[$filteredIdx][$name] = $defaultVal; @@ -347,9 +347,9 @@ private static function applyBasicFilterOnly($def,$toBeFiltered) { $paramType = $paramObj->getType(); $optIdx = 'options'; - if ($paramType == ParamTypes::BOOL) { + if ($paramType == ParamType::BOOL) { $returnVal = self::filterBoolean($toBeFiltered); - } else if ($paramType == ParamTypes::ARR) { + } else if ($paramType == ParamType::ARR) { $returnVal = self::filterArray(filter_var($toBeFiltered)); } else { $returnVal = filter_var($toBeFiltered); @@ -357,22 +357,22 @@ private static function applyBasicFilterOnly($def,$toBeFiltered) { foreach ($def['filters'] as $val) { $returnVal = filter_var($returnVal, $val, $def[$optIdx]); - if ($paramType == ParamTypes::DOUBLE) { + if ($paramType == ParamType::DOUBLE) { $returnVal = self::minMaxValueCheck($returnVal, $def['options']['options']); } - if (in_array($paramType, ParamTypes::getStringTypes())) { + if (in_array($paramType, ParamType::getStringTypes())) { $returnVal = self::minMaxLengthCheck($returnVal, $def['options']['options']); } } if ($returnVal === false || - (($paramType == ParamTypes::URL || $paramType == ParamTypes::EMAIL) && strlen($returnVal) == 0) || - (($paramType == ParamTypes::INT || $paramType == ParamTypes::DOUBLE) && strlen($returnVal) == 0)) { + (($paramType == ParamType::URL || $paramType == ParamType::EMAIL) && strlen($returnVal) == 0) || + (($paramType == ParamType::INT || $paramType == ParamType::DOUBLE) && strlen($returnVal) == 0)) { $returnVal = self::INVALID; } - if ($paramType == ParamTypes::STRING && + if ($paramType == ParamType::STRING && $returnVal != self::INVALID && strlen($returnVal) == 0 && $def['options']['options']['allow-empty'] === false) { @@ -401,7 +401,7 @@ private static function applyCustomFilterFunc($def, $toBeFiltered) { $returnVal = $filterFuncResult; } - if ($returnVal === false && $paramObj->getType() != ParamTypes::BOOL) { + if ($returnVal === false && $paramObj->getType() != ParamType::BOOL) { $returnVal = self::INVALID; } @@ -417,16 +417,16 @@ private function applyJsonBasicFilter(Json $extraClean, $toBeFiltered, $def) { $toBeFiltered = strip_tags($toBeFiltered); } - if ($paramType == $toBeFilteredType || $toBeFilteredType == 'object' && $paramType == ParamTypes::JSON_OBJ) { - if ($paramType == ParamTypes::BOOL) { + if ($paramType == $toBeFilteredType || $toBeFilteredType == 'object' && $paramType == ParamType::JSON_OBJ) { + if ($paramType == ParamType::BOOL) { $extraClean->addBoolean($name, $toBeFiltered); - } else if ($paramType == ParamTypes::DOUBLE || $paramType == ParamTypes::INT) { + } else if ($paramType == ParamType::DOUBLE || $paramType == ParamType::INT) { $extraClean->addNumber($name, $toBeFiltered); } else if ($paramType == 'string') { $this->cleanJsonStr($extraClean, $def, $toBeFiltered); - } else if ($paramType == ParamTypes::ARR) { + } else if ($paramType == ParamType::ARR) { $extraClean->addArray($name, $this->cleanJsonArray($toBeFiltered, true)); - } else if ($paramType == ParamTypes::JSON_OBJ) { + } else if ($paramType == ParamType::JSON_OBJ) { if ($toBeFiltered instanceof Json) { $extraClean->add($name, $toBeFiltered); } else { @@ -607,7 +607,7 @@ private static function filterArray($arr) { if ($result['parsed'] === true) { $x = $result['end']; - $arrayValues[] = filter_var(strip_tags($result[ParamTypes::STRING])); + $arrayValues[] = filter_var(strip_tags($result[ParamType::STRING])); $tmpArrValue = ''; continue; } else { @@ -709,7 +709,7 @@ private function filterJson(Json $toBeCleaned) { if (isset($def[$optIdx]['filter-func'])) { $filteredValue = self::applyCustomFilterFunc($def, $toBeFiltered); - if ($paramType == ParamTypes::STRING && + if ($paramType == ParamType::STRING && $filteredValue != self::INVALID && strlen($filteredValue) == 0 && $def[$optIdx][$optIdx]['allow-empty'] === false) { @@ -736,9 +736,9 @@ private static function getBasicFilterResultForCustomFilter($def, $toBeFiltered) } $paramType = $def['parameter']->getType(); - if ($paramType == ParamTypes::BOOL) { + if ($paramType == ParamType::BOOL) { $filteredValue = self::filterBoolean(filter_var($toBeFiltered)); - } else if ($paramType == ParamTypes::ARR) { + } else if ($paramType == ParamType::ARR) { $filteredValue = self::filterArray($toBeFiltered); } else { $filteredValue = filter_var($toBeFiltered); @@ -746,11 +746,11 @@ private static function getBasicFilterResultForCustomFilter($def, $toBeFiltered) foreach ($def['filters'] as $val) { $filteredValue = filter_var($filteredValue, $val, $def['options']); - if ($paramType == ParamTypes::DOUBLE) { + if ($paramType == ParamType::DOUBLE) { $filteredValue = self::minMaxValueCheck($filteredValue, $def['options']['options']); } - if (in_array($paramType, ParamTypes::getStringTypes())) { + if (in_array($paramType, ParamType::getStringTypes())) { $filteredValue = self::minMaxLengthCheck($filteredValue, $def['options']['options']); } } @@ -759,7 +759,7 @@ private static function getBasicFilterResultForCustomFilter($def, $toBeFiltered) $filteredValue = self::INVALID; } - if ($paramType == ParamTypes::STRING && + if ($paramType == ParamType::STRING && $filteredValue != self::INVALID && strlen($filteredValue) == 0 && $def['options']['options']['allow-empty'] === false) { diff --git a/webfiori/http/ManagerInfoService.php b/webfiori/http/ManagerInfoService.php index eadeb9c..f0ba60c 100644 --- a/webfiori/http/ManagerInfoService.php +++ b/webfiori/http/ManagerInfoService.php @@ -32,7 +32,7 @@ public function __construct() { .'under given manager.'); $this->addParameter([ ParamOption::NAME => 'version', - ParamOption::TYPE => ParamTypes::STRING, + ParamOption::TYPE => ParamType::STRING, ParamOption::OPTIONAL => true, ParamOption::DESCRIPTION => 'Optional parameter. ' .'If set, the information that will be returned will be specific ' diff --git a/webfiori/http/ParamTypes.php b/webfiori/http/ParamType.php similarity index 99% rename from webfiori/http/ParamTypes.php rename to webfiori/http/ParamType.php index 356ceac..5a44a2d 100644 --- a/webfiori/http/ParamTypes.php +++ b/webfiori/http/ParamType.php @@ -18,7 +18,7 @@ * * @since 1.5.2 */ -class ParamTypes { +class ParamType { /** * A constant to indicate that a parameter is of type array. * diff --git a/webfiori/http/RequestParameter.php b/webfiori/http/RequestParameter.php index fe80b59..a35e317 100644 --- a/webfiori/http/RequestParameter.php +++ b/webfiori/http/RequestParameter.php @@ -451,9 +451,9 @@ public function setDefault($val) : bool { $RPType = $this->getType(); if ($valType == $RPType || - ($valType == 'integer' && $RPType == ParamTypes::DOUBLE) || - ($valType == 'double' && $RPType == ParamTypes::DOUBLE) || - (($RPType == ParamTypes::EMAIL || $RPType == ParamTypes::URL) && $valType == ParamTypes::STRING) || + ($valType == 'integer' && $RPType == ParamType::DOUBLE) || + ($valType == 'double' && $RPType == ParamType::DOUBLE) || + (($RPType == ParamType::EMAIL || $RPType == ParamType::URL) && $valType == ParamType::STRING) || ($val instanceof Json && $RPType == 'json-obj')) { $this->default = $val; @@ -490,7 +490,7 @@ public function setDescription(string $desc) { * @since 1.2.1 */ public function setIsEmptyStringAllowed(bool $bool) : bool { - if ($this->getType() == ParamTypes::STRING) { + if ($this->getType() == ParamType::STRING) { //in php 5.6, primitive type hinting is not allowed. //this will resolve the issue. $this->isEmptyStrAllowed = $bool; @@ -529,7 +529,7 @@ public function setIsOptional(bool $bool) { public function setMaxLength(int $val) : bool { $type = $this->getType(); - if (in_array($type, ParamTypes::getStringTypes())) { + if (in_array($type, ParamType::getStringTypes())) { $min = $this->getMinLength() === null ? 0 : $this->getMinLength(); if ($val >= $min && $val > 0) { @@ -561,11 +561,11 @@ public function setMaxLength(int $val) : bool { public function setMaxValue(float $val) : bool { $type = $this->getType(); - if (in_array($type, ParamTypes::getNumericTypes())) { + if (in_array($type, ParamType::getNumericTypes())) { $min = $this->getMinValue(); if ($min !== null && $val > $min) { - $this->maxVal = $type === ParamTypes::INT ? intval($val) : $val; + $this->maxVal = $type === ParamType::INT ? intval($val) : $val; return true; } @@ -592,7 +592,7 @@ public function setMaxValue(float $val) : bool { public function setMinLength(int $val) : bool { $type = $this->getType(); - if (in_array($type, ParamTypes::getStringTypes())) { + if (in_array($type, ParamType::getStringTypes())) { $max = $this->getMaxLength() === null ? PHP_INT_MAX : $this->getMaxLength(); if ($val <= $max && $val > 0) { @@ -623,11 +623,11 @@ public function setMinLength(int $val) : bool { public function setMinValue(float $val) : bool { $type = $this->getType(); - if (in_array($type, ParamTypes::getNumericTypes())) { + if (in_array($type, ParamType::getNumericTypes())) { $max = $this->getMaxValue(); if ($max !== null && $val < $max) { - $this->minVal = $type == ParamTypes::INT ? intval($val) : $val; + $this->minVal = $type == ParamType::INT ? intval($val) : $val; return true; } @@ -683,13 +683,13 @@ public function setType(string $type) : bool { $sType = 'integer'; } - if (in_array($sType, ParamTypes::getTypes())) { + if (in_array($sType, ParamType::getTypes())) { $this->type = $sType; - if ($sType == ParamTypes::DOUBLE && PHP_MAJOR_VERSION >= 7 && PHP_MINOR_VERSION >= 2) { + if ($sType == ParamType::DOUBLE && PHP_MAJOR_VERSION >= 7 && PHP_MINOR_VERSION >= 2) { $this->maxVal = PHP_FLOAT_MAX; $this->minVal = PHP_FLOAT_MIN; - } else if ($sType == ParamTypes::INT || $sType == ParamTypes::DOUBLE) { + } else if ($sType == ParamType::INT || $sType == ParamType::DOUBLE) { $this->minVal = defined('PHP_INT_MIN') ? PHP_INT_MIN : ~PHP_INT_MAX; $this->maxVal = PHP_INT_MAX; } else {