当前位置: 首页>>代码示例>>PHP>>正文


PHP StringUtils::cleanString方法代码示例

本文整理汇总了PHP中Magento\Framework\Stdlib\StringUtils::cleanString方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtils::cleanString方法的具体用法?PHP StringUtils::cleanString怎么用?PHP StringUtils::cleanString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Framework\Stdlib\StringUtils的用法示例。


在下文中一共展示了StringUtils::cleanString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: textValidation

 /**
  * @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;
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:18,代码来源:Validator.php

示例2: _getHttpCleanValue

 /**
  * 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;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:Header.php

示例3: getHttpHost

 /**
  * 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;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:21,代码来源:Request.php

示例4: getRawQueryText

 /**
  * 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));
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:10,代码来源:QueryFactory.php

示例5: isAttributeValid

 /**
  * 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;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:52,代码来源:AbstractEntity.php

示例6: testCleanString

 /**
  * @covers \Magento\Framework\Stdlib\StringUtils::cleanString
  */
 public function testCleanString()
 {
     $string = '12345';
     $this->assertEquals($string, $this->_string->cleanString($string));
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:8,代码来源:StringUtilsTest.php

示例7: isAttributeValid

 /**
  * 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;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:62,代码来源:AbstractEntity.php


注:本文中的Magento\Framework\Stdlib\StringUtils::cleanString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。