本文整理匯總了PHP中Magento\Framework\Stdlib\String::cleanString方法的典型用法代碼示例。如果您正苦於以下問題:PHP String::cleanString方法的具體用法?PHP String::cleanString怎麽用?PHP String::cleanString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Magento\Framework\Stdlib\String
的用法示例。
在下文中一共展示了String::cleanString方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: _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;
}
示例2: _saveVisitorInfo
/**
* Saving visitor information
*
* @param \Magento\Log\Model\Visitor $visitor
* @return \Magento\Log\Model\Resource\Visitor
*/
protected function _saveVisitorInfo($visitor)
{
$referer = $this->string->cleanString($visitor->getHttpReferer());
$referer = $this->string->substr($referer, 0, 255);
$userAgent = $this->string->cleanString($visitor->getHttpUserAgent());
$userAgent = $this->string->substr($userAgent, 0, 255);
$charset = $this->string->cleanString($visitor->getHttpAcceptCharset());
$charset = $this->string->substr($charset, 0, 255);
$language = $this->string->cleanString($visitor->getHttpAcceptLanguage());
$language = $this->string->substr($language, 0, 255);
$data = new \Magento\Framework\Object(array('visitor_id' => $visitor->getId(), 'http_referer' => $referer, 'http_user_agent' => $userAgent, 'http_accept_charset' => $charset, 'http_accept_language' => $language, 'server_addr' => $visitor->getServerAddr(), 'remote_addr' => $visitor->getRemoteAddr()));
$bind = $this->_prepareDataForTable($data, $this->getTable('log_visitor_info'));
$adapter = $this->_getWriteAdapter();
$adapter->insert($this->getTable('log_visitor_info'), $bind);
return $this;
}
示例3: 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)
{
switch ($attributeParams['type']) {
case 'varchar':
$value = $this->string->cleanString($rowData[$attributeCode]);
$valid = $this->string->strlen($value) < self::DB_MAX_VARCHAR_LENGTH;
break;
case 'decimal':
$value = trim($rowData[$attributeCode]);
$valid = (double) $value == $value && is_numeric($value);
break;
case 'select':
case 'multiselect':
$valid = isset($attributeParams['options'][strtolower($rowData[$attributeCode])]);
break;
case 'int':
$value = trim($rowData[$attributeCode]);
$valid = (int) $value == $value && is_numeric($value);
break;
case 'datetime':
$value = trim($rowData[$attributeCode]);
$valid = strtotime($value) !== false;
break;
case 'text':
$value = $this->string->cleanString($rowData[$attributeCode]);
$valid = $this->string->strlen($value) < self::DB_MAX_TEXT_LENGTH;
break;
default:
$valid = true;
break;
}
if (!$valid) {
$this->addRowError(__("Please correct the value for '%s'."), $rowNumber, $attributeCode);
} elseif (!empty($attributeParams['is_unique'])) {
if (isset($this->_uniqueAttributes[$attributeCode][$rowData[$attributeCode]])) {
$this->addRowError(__("Duplicate Unique Attribute for '%s'"), $rowNumber, $attributeCode);
return false;
}
$this->_uniqueAttributes[$attributeCode][$rowData[$attributeCode]] = true;
}
return (bool) $valid;
}
示例4: testCleanString
/**
* @covers \Magento\Framework\Stdlib\String::cleanString
*/
public function testCleanString()
{
$string = '12345';
$this->assertEquals($string, $this->_string->cleanString($string));
}
示例5: 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));
}