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


PHP StringUtils::strlen方法代码示例

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


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

示例1: validateValue

 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function validateValue($value)
 {
     $errors = [];
     $attribute = $this->getAttribute();
     $label = __($attribute->getStoreLabel());
     if ($value === false) {
         // try to load original value and validate it
         $value = $this->_value;
     }
     if ($attribute->isRequired() && empty($value) && $value !== '0') {
         $errors[] = __('"%1" is a required value.', $label);
     }
     if (!$errors && !$attribute->isRequired() && empty($value)) {
         return true;
     }
     // validate length
     $length = $this->_string->strlen(trim($value));
     $validateRules = $attribute->getValidationRules();
     $minTextLength = ArrayObjectSearch::getArrayElementByName($validateRules, 'min_text_length');
     if ($minTextLength !== null && $length < $minTextLength) {
         $errors[] = __('"%1" length must be equal or greater than %2 characters.', $label, $minTextLength);
     }
     $maxTextLength = ArrayObjectSearch::getArrayElementByName($validateRules, 'max_text_length');
     if ($maxTextLength !== null && $length > $maxTextLength) {
         $errors[] = __('"%1" length must be equal or less than %2 characters.', $label, $maxTextLength);
     }
     $result = $this->_validateInputRule($value);
     if ($result !== true) {
         $errors = array_merge($errors, $result);
     }
     if (count($errors) == 0) {
         return true;
     }
     return $errors;
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:40,代码来源:Text.php

示例2: validateValue

 /**
  * Validate data
  * Return true or array of errors
  *
  * @param array|string $value
  * @return bool|array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function validateValue($value)
 {
     $errors = [];
     $attribute = $this->getAttribute();
     $label = __($attribute->getStoreLabel());
     if ($value === false) {
         // try to load original value and validate it
         $value = $this->getEntity()->getDataUsingMethod($attribute->getAttributeCode());
     }
     if ($attribute->getIsRequired() && empty($value) && $value !== '0') {
         $errors[] = __('"%1" is a required value.', $label);
     }
     if (!$errors && !$attribute->getIsRequired() && empty($value)) {
         return true;
     }
     // validate length
     $length = $this->_string->strlen(trim($value));
     $validateRules = $attribute->getValidateRules();
     if (!empty($validateRules['min_text_length']) && $length < $validateRules['min_text_length']) {
         $v = $validateRules['min_text_length'];
         $errors[] = __('"%1" length must be equal or greater than %2 characters.', $label, $v);
     }
     if (!empty($validateRules['max_text_length']) && $length > $validateRules['max_text_length']) {
         $v = $validateRules['max_text_length'];
         $errors[] = __('"%1" length must be equal or less than %2 characters.', $label, $v);
     }
     $result = $this->_validateInputRule($value);
     if ($result !== true) {
         $errors = array_merge($errors, $result);
     }
     if (count($errors) == 0) {
         return true;
     }
     return $errors;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:44,代码来源:Text.php

示例3: render

 /**
  * Renders a column
  *
  * @param   \Magento\Framework\DataObject $row
  * @return  string
  */
 public function render(\Magento\Framework\DataObject $row)
 {
     $value = $row->getData($this->getColumn()->getIndex());
     if ($this->stringHelper->strlen($value) > 30) {
         $value = '<span title="' . $this->escapeHtml($value) . '">' . $this->escapeHtml($this->filterManager->truncate($value, ['length' => 30])) . '</span>';
     } else {
         $value = $this->escapeHtml($value);
     }
     return $value;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:16,代码来源:Searchquery.php

示例4: render

 /**
  * Renders grid column
  *
  * @param \Magento\Framework\DataObject $row
  * @return string
  */
 public function render(\Magento\Framework\DataObject $row)
 {
     $line = parent::_getValue($row);
     $wrappedLine = '';
     $lineLength = $this->getColumn()->getData('lineLength') ? $this->getColumn()->getData('lineLength') : $this->_defaultMaxLineLength;
     for ($i = 0, $n = floor($this->string->strlen($line) / $lineLength); $i <= $n; $i++) {
         $wrappedLine .= $this->string->substr($line, $lineLength * $i, $lineLength) . "<br />";
     }
     return $wrappedLine;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:16,代码来源:Wrapline.php

示例5: validate

 /**
  * Validate SKU
  *
  * @param Product $object
  * @return bool
  * @throws \Magento\Framework\Exception\LocalizedException
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function validate($object)
 {
     $attrCode = $this->getAttribute()->getAttributeCode();
     $value = $object->getData($attrCode);
     if ($this->getAttribute()->getIsRequired() && strlen($value) === 0) {
         throw new \Magento\Framework\Exception\LocalizedException(__('The value of attribute "%1" must be set', $attrCode));
     }
     if ($this->string->strlen($object->getSku()) > self::SKU_MAX_LENGTH) {
         throw new \Magento\Framework\Exception\LocalizedException(__('SKU length should be %1 characters maximum.', self::SKU_MAX_LENGTH));
     }
     return true;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:20,代码来源:Sku.php

示例6: 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

示例7: beforeSave

 /**
  * Special processing before attribute save:
  * a) check some rules for password
  * b) transform temporary attribute 'password' into real attribute 'password_hash'
  *
  * @param \Magento\Framework\DataObject $object
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function beforeSave($object)
 {
     $password = $object->getPassword();
     $length = $this->string->strlen($password);
     if ($length > 0) {
         if ($length < self::MIN_PASSWORD_LENGTH) {
             throw new LocalizedException(__('Please enter a password with at least %1 characters.', self::MIN_PASSWORD_LENGTH));
         }
         if (trim($password) != $password) {
             throw new LocalizedException(__('The password can not begin or end with a space.'));
         }
         $object->setPasswordHash($object->hashPassword($password));
     }
 }
开发者ID:IlyaGluschenko,项目名称:test001,代码行数:23,代码来源:Password.php

示例8: saveStoreLabels

 /**
  * Save rule labels for different store views
  *
  * @param int $ruleId
  * @param array $labels
  * @throws \Exception
  * @return $this
  */
 public function saveStoreLabels($ruleId, $labels)
 {
     $deleteByStoreIds = [];
     $table = $this->getTable('salesrule_label');
     $connection = $this->getConnection();
     $data = [];
     foreach ($labels as $storeId => $label) {
         if ($this->string->strlen($label)) {
             $data[] = ['rule_id' => $ruleId, 'store_id' => $storeId, 'label' => $label];
         } else {
             $deleteByStoreIds[] = $storeId;
         }
     }
     $connection->beginTransaction();
     try {
         if (!empty($data)) {
             $connection->insertOnDuplicate($table, $data, ['label']);
         }
         if (!empty($deleteByStoreIds)) {
             $connection->delete($table, ['rule_id=?' => $ruleId, 'store_id IN (?)' => $deleteByStoreIds]);
         }
     } catch (\Exception $e) {
         $connection->rollback();
         throw $e;
     }
     $connection->commit();
     return $this;
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:36,代码来源:Rule.php

示例9: validateUserValue

 /**
  * Validate user input for option
  *
  * @param array $values All product option values, i.e. array (option_id => mixed, option_id => mixed...)
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function validateUserValue($values)
 {
     parent::validateUserValue($values);
     $option = $this->getOption();
     $value = trim($this->getUserValue());
     // Check requires option to have some value
     if (strlen($value) == 0 && $option->getIsRequire() && !$this->getSkipCheckRequiredOption()) {
         $this->setIsValid(false);
         throw new LocalizedException(__('Please specify product\'s required option(s).'));
     }
     // Check maximal length limit
     $maxCharacters = $option->getMaxCharacters();
     if ($maxCharacters > 0 && $this->string->strlen($value) > $maxCharacters) {
         $this->setIsValid(false);
         throw new LocalizedException(__('The text is too long.'));
     }
     $this->setUserValue($value);
     return $this;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:26,代码来源:Text.php

示例10: getFormattedOptionValue

 /**
  * Accept option value and return its formatted view
  *
  * @param string|array $optionValue
  * Method works well with these $optionValue format:
  *      1. String
  *      2. Indexed array e.g. array(val1, val2, ...)
  *      3. Associative array, containing additional option info, including option value, e.g.
  *          array
  *          (
  *              [label] => ...,
  *              [value] => ...,
  *              [print_value] => ...,
  *              [option_id] => ...,
  *              [option_type] => ...,
  *              [custom_view] =>...,
  *          )
  * @param array $params
  * All keys are options. Following supported:
  *  - 'maxLength': truncate option value if needed, default: do not truncate
  *  - 'cutReplacer': replacer for cut off value part when option value exceeds maxLength
  *
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function getFormattedOptionValue($optionValue, $params = null)
 {
     // Init params
     if (!$params) {
         $params = [];
     }
     $maxLength = isset($params['max_length']) ? $params['max_length'] : null;
     $cutReplacer = isset($params['cut_replacer']) ? $params['cut_replacer'] : '...';
     // Proceed with option
     $optionInfo = [];
     // Define input data format
     if (is_array($optionValue)) {
         if (isset($optionValue['option_id'])) {
             $optionInfo = $optionValue;
             if (isset($optionInfo['value'])) {
                 $optionValue = $optionInfo['value'];
             }
         } elseif (isset($optionValue['value'])) {
             $optionValue = $optionValue['value'];
         }
     }
     // Render customized option view
     if (isset($optionInfo['custom_view']) && $optionInfo['custom_view']) {
         $_default = ['value' => $optionValue];
         if (isset($optionInfo['option_type'])) {
             try {
                 $group = $this->_productOptionFactory->create()->groupFactory($optionInfo['option_type']);
                 return ['value' => $group->getCustomizedView($optionInfo)];
             } catch (\Exception $e) {
                 return $_default;
             }
         }
         return $_default;
     }
     // Truncate standard view
     if (is_array($optionValue)) {
         $truncatedValue = implode("\n", $optionValue);
         $truncatedValue = nl2br($truncatedValue);
         return ['value' => $truncatedValue];
     } else {
         if ($maxLength) {
             $truncatedValue = $this->filter->truncate($optionValue, ['length' => $maxLength, 'etc' => '']);
         } else {
             $truncatedValue = $optionValue;
         }
         $truncatedValue = nl2br($truncatedValue);
     }
     $result = ['value' => $truncatedValue];
     if ($maxLength && $this->string->strlen($optionValue) > $maxLength) {
         $result['value'] = $result['value'] . $cutReplacer;
         $optionValue = nl2br($optionValue);
         $result['full_view'] = $optionValue;
     }
     return $result;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:81,代码来源:Configuration.php

示例11: filter

 /**
  * Filter value
  *
  * @param string $string
  * @return string
  */
 public function filter($string)
 {
     $length = $this->length;
     $this->remainder = '';
     if (0 == $length) {
         return '';
     }
     $originalLength = $this->string->strlen($string);
     if ($originalLength > $length) {
         $length -= $this->string->strlen($this->etc);
         if ($length <= 0) {
             return '';
         }
         $preparedString = $string;
         $preparedLength = $length;
         if (!$this->breakWords) {
             $preparedString = preg_replace('/\\s+?(\\S+)?$/u', '', $this->string->substr($string, 0, $length + 1));
             $preparedLength = $this->string->strlen($preparedString);
         }
         $this->remainder = $this->string->substr($string, $preparedLength, $originalLength);
         return $this->string->substr($preparedString, 0, $length) . $this->etc;
     }
     return $string;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:30,代码来源:Truncate.php

示例12: getFormatedOptionValue

 /**
  * Accept option value and return its formatted view
  *
  * @param mixed $optionValue
  * Method works well with these $optionValue format:
  *      1. String
  *      2. Indexed array e.g. array(val1, val2, ...)
  *      3. Associative array, containing additional option info, including option value, e.g.
  *          array
  *          (
  *              [label] => ...,
  *              [value] => ...,
  *              [print_value] => ...,
  *              [option_id] => ...,
  *              [option_type] => ...,
  *              [custom_view] =>...,
  *          )
  *
  * @return array
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function getFormatedOptionValue($optionValue)
 {
     $optionInfo = [];
     // define input data format
     if (is_array($optionValue)) {
         if (isset($optionValue['option_id'])) {
             $optionInfo = $optionValue;
             if (isset($optionInfo['value'])) {
                 $optionValue = $optionInfo['value'];
             }
         } elseif (isset($optionValue['value'])) {
             $optionValue = $optionValue['value'];
         }
     }
     // render customized option view
     if (isset($optionInfo['custom_view']) && $optionInfo['custom_view']) {
         $_default = ['value' => $optionValue];
         if (isset($optionInfo['option_type'])) {
             try {
                 $group = $this->_productOptionFactory->create()->groupFactory($optionInfo['option_type']);
                 return ['value' => $group->getCustomizedView($optionInfo)];
             } catch (\Exception $e) {
                 return $_default;
             }
         }
         return $_default;
     }
     // truncate standard view
     $result = [];
     if (is_array($optionValue)) {
         $truncatedValue = implode("\n", $optionValue);
         $truncatedValue = nl2br($truncatedValue);
         return ['value' => $truncatedValue];
     } else {
         $truncatedValue = $this->filterManager->truncate($optionValue, ['length' => 55, 'etc' => '']);
         $truncatedValue = nl2br($truncatedValue);
     }
     $result = ['value' => $truncatedValue];
     if ($this->string->strlen($optionValue) > 55) {
         $result['value'] = $result['value'] . ' <a href="#" class="dots tooltip toggle" onclick="return false">...</a>';
         $optionValue = nl2br($optionValue);
         $result = array_merge($result, ['full_view' => $optionValue]);
     }
     return $result;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:66,代码来源:DefaultRenderer.php

示例13: _getItemsData

 /**
  * Get data array for building attribute filter items
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  * @return array
  */
 protected function _getItemsData()
 {
     $attribute = $this->getAttributeModel();
     $this->_requestVar = $attribute->getAttributeCode();
     $options = $attribute->getFrontend()->getSelectOptions();
     $optionsCount = $this->_getResource()->getCount($this);
     foreach ($options as $option) {
         if (is_array($option['value'])) {
             continue;
         }
         if ($this->string->strlen($option['value'])) {
             // Check filter type
             if ($this->getAttributeIsFilterable($attribute) == self::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS) {
                 if (!empty($optionsCount[$option['value']])) {
                     $this->itemDataBuilder->addItemData($this->tagFilter->filter($option['label']), $option['value'], $optionsCount[$option['value']]);
                 }
             } else {
                 $this->itemDataBuilder->addItemData($this->tagFilter->filter($option['label']), $option['value'], isset($optionsCount[$option['value']]) ? $optionsCount[$option['value']] : 0);
             }
         }
     }
     return $this->itemDataBuilder->build();
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:29,代码来源:Attribute.php

示例14: checkPasswordStrength

 /**
  * Make sure that password complies with minimum security requirements.
  *
  * @param string $password
  * @return void
  * @throws InputException
  */
 protected function checkPasswordStrength($password)
 {
     $length = $this->stringHelper->strlen($password);
     if ($length < self::MIN_PASSWORD_LENGTH) {
         throw new InputException(__('Please enter a password with at least %1 characters.', self::MIN_PASSWORD_LENGTH));
     }
     if ($this->stringHelper->strlen(trim($password)) != $length) {
         throw new InputException(__('The password can\'t begin or end with a space.'));
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:17,代码来源:AccountManagement.php

示例15: isQueryTooLong

 /**
  * @param string $queryText
  * @param int|string $maxQueryLength
  * @return bool
  */
 private function isQueryTooLong($queryText, $maxQueryLength)
 {
     return $maxQueryLength !== '' && $this->string->strlen($queryText) > $maxQueryLength;
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:9,代码来源:QueryFactory.php


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