/** * 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; }
/** * 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; }
/** * 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; }
/** * @covers \Magento\Framework\Stdlib\String::cleanString */ public function testCleanString() { $string = '12345'; $this->assertEquals($string, $this->_string->cleanString($string)); }
/** * 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)); }