Beispiel #1
0
 /**
  * @param mixed $attrCode
  * @param string $type
  * @return bool
  */
 protected function textValidation($attrCode, $type)
 {
     $val = $this->string->cleanString($this->_rowData[$attrCode]);
     if ($type == 'text') {
         $valid = $this->string->strlen($val) < Product::DB_MAX_TEXT_LENGTH;
     } else {
         $valid = $this->string->strlen($val) < Product::DB_MAX_VARCHAR_LENGTH;
     }
     if (!$valid) {
         $this->_addMessages([RowValidatorInterface::ERROR_EXCEEDED_MAX_LENGTH]);
     }
     return $valid;
 }
Beispiel #2
0
 /**
  * Retrieve HTTP "clean" value
  *
  * @param string $var
  * @param boolean $clean clean non UTF-8 characters
  * @return string
  */
 protected function _getHttpCleanValue($var, $clean = true)
 {
     $value = $this->_request->getServer($var, '');
     if ($clean) {
         $value = $this->_converter->cleanString($value);
     }
     return $value;
 }
 /**
  * Retrieve HTTP HOST
  *
  * @param bool $trimPort
  * @return string
  *
  * @todo getHttpHost should return only string (currently method return boolean value too)
  */
 public function getHttpHost($trimPort = true)
 {
     $httpHost = $this->getServer('HTTP_HOST');
     $httpHost = $this->converter->cleanString($httpHost);
     if (empty($httpHost)) {
         return false;
     }
     if ($trimPort) {
         $host = explode(':', $httpHost);
         return $host[0];
     }
     return $httpHost;
 }
 /**
  * Retrieve search query text
  *
  * @return string
  */
 private function getRawQueryText()
 {
     $queryText = $this->request->getParam(self::QUERY_VAR_NAME);
     return $queryText === null || is_array($queryText) ? '' : $this->string->cleanString(trim($queryText));
 }
 /**
  * Check one attribute. Can be overridden in child.
  *
  * @param string $attrCode Attribute code
  * @param array $attrParams Attribute params
  * @param array $rowData Row data
  * @param int $rowNum
  * @return boolean
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function isAttributeValid($attrCode, array $attrParams, array $rowData, $rowNum)
 {
     switch ($attrParams['type']) {
         case 'varchar':
             $val = $this->string->cleanString($rowData[$attrCode]);
             $valid = $this->string->strlen($val) < self::DB_MAX_VARCHAR_LENGTH;
             break;
         case 'decimal':
             $val = trim($rowData[$attrCode]);
             $valid = (double) $val == $val;
             break;
         case 'select':
         case 'multiselect':
             $valid = isset($attrParams['options'][strtolower($rowData[$attrCode])]);
             break;
         case 'int':
             $val = trim($rowData[$attrCode]);
             $valid = (int) $val == $val;
             break;
         case 'datetime':
             $val = trim($rowData[$attrCode]);
             $valid = strtotime($val) !== false;
             break;
         case 'text':
             $val = $this->string->cleanString($rowData[$attrCode]);
             $valid = $this->string->strlen($val) < self::DB_MAX_TEXT_LENGTH;
             break;
         default:
             $valid = true;
             break;
     }
     if (!$valid) {
         $this->addRowError(self::ERROR_CODE_ATTRIBUTE_NOT_VALID, $rowNum, $attrCode);
     } elseif (!empty($attrParams['is_unique'])) {
         if (isset($this->_uniqueAttributes[$attrCode][$rowData[$attrCode]])) {
             $this->addRowError(self::ERROR_CODE_DUPLICATE_UNIQUE_ATTRIBUTE, $rowNum, $attrCode);
             return false;
         }
         $this->_uniqueAttributes[$attrCode][$rowData[$attrCode]] = true;
     }
     return (bool) $valid;
 }
 /**
  * @covers \Magento\Framework\Stdlib\StringUtils::cleanString
  */
 public function testCleanString()
 {
     $string = '12345';
     $this->assertEquals($string, $this->_string->cleanString($string));
 }
 /**
  * Check one attribute can be overridden in child
  *
  * @param string $attributeCode Attribute code
  * @param array $attributeParams Attribute params
  * @param array $rowData Row data
  * @param int $rowNumber
  * @return bool
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function isAttributeValid($attributeCode, array $attributeParams, array $rowData, $rowNumber)
 {
     $message = '';
     switch ($attributeParams['type']) {
         case 'varchar':
             $value = $this->string->cleanString($rowData[$attributeCode]);
             $valid = $this->string->strlen($value) < self::DB_MAX_VARCHAR_LENGTH;
             $message = self::ERROR_EXCEEDED_MAX_LENGTH;
             break;
         case 'decimal':
             $value = trim($rowData[$attributeCode]);
             $valid = (double) $value == $value && is_numeric($value);
             $message = self::ERROR_INVALID_ATTRIBUTE_TYPE;
             break;
         case 'select':
         case 'multiselect':
             $valid = isset($attributeParams['options'][strtolower($rowData[$attributeCode])]);
             $message = self::ERROR_INVALID_ATTRIBUTE_OPTION;
             break;
         case 'int':
             $value = trim($rowData[$attributeCode]);
             $valid = (int) $value == $value && is_numeric($value);
             $message = self::ERROR_INVALID_ATTRIBUTE_TYPE;
             break;
         case 'datetime':
             $value = trim($rowData[$attributeCode]);
             $valid = strtotime($value) !== false;
             $message = self::ERROR_INVALID_ATTRIBUTE_TYPE;
             break;
         case 'text':
             $value = $this->string->cleanString($rowData[$attributeCode]);
             $valid = $this->string->strlen($value) < self::DB_MAX_TEXT_LENGTH;
             $message = self::ERROR_EXCEEDED_MAX_LENGTH;
             break;
         default:
             $valid = true;
             break;
     }
     if (!$valid) {
         if ($message == self::ERROR_INVALID_ATTRIBUTE_TYPE) {
             $message = sprintf($this->errorMessageTemplates[$message], $attributeCode, $attributeParams['type']);
         }
         $this->addRowError($message, $rowNumber, $attributeCode);
     } elseif (!empty($attributeParams['is_unique'])) {
         if (isset($this->_uniqueAttributes[$attributeCode][$rowData[$attributeCode]])) {
             $this->addRowError(self::ERROR_CODE_DUPLICATE_UNIQUE_ATTRIBUTE, $rowNumber, $attributeCode);
             return false;
         }
         $this->_uniqueAttributes[$attributeCode][$rowData[$attributeCode]] = true;
     }
     return (bool) $valid;
 }