本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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));
}
示例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;
}
示例6: testCleanString
/**
* @covers \Magento\Framework\Stdlib\StringUtils::cleanString
*/
public function testCleanString()
{
$string = '12345';
$this->assertEquals($string, $this->_string->cleanString($string));
}
示例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;
}