當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Stdlib\String類代碼示例

本文整理匯總了PHP中Magento\Framework\Stdlib\String的典型用法代碼示例。如果您正苦於以下問題:PHP String類的具體用法?PHP String怎麽用?PHP String使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了String類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setUp

 protected function setUp()
 {
     $this->filesystemMock = $this->getMock('Magento\\Framework\\App\\Filesystem', array(), array(), '', false, false);
     $this->directoryMock = $this->getMock('Magento\\Framework\\Filesystem\\Directory\\Read', array(), array(), '', false, false);
     $this->_stringMock = $this->getMock('Magento\\Framework\\Stdlib\\String', array(), array(), '', false, false);
     $this->_stringMock->expects($this->once())->method('upperCaseWords')->will($this->returnValue('Test/Module'));
     $this->filesystemMock->expects($this->once())->method('getDirectoryRead')->will($this->returnValue($this->directoryMock));
     $this->_model = new \Magento\Framework\Module\Dir($this->filesystemMock, $this->_stringMock);
 }
開發者ID:,項目名稱:,代碼行數:9,代碼來源:

示例2: getVariable

 /**
  * Return variable value for var construction
  *
  * @param string $value raw parameters
  * @param string $default default value
  * @return string
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function getVariable($value, $default = '{no_value_defined}')
 {
     \Magento\Framework\Profiler::start('email_template_processing_variables');
     $tokenizer = new Template\Tokenizer\Variable();
     $tokenizer->setString($value);
     $stackVars = $tokenizer->tokenize();
     $result = $default;
     $last = 0;
     for ($i = 0; $i < count($stackVars); $i++) {
         if ($i == 0 && isset($this->templateVars[$stackVars[$i]['name']])) {
             // Getting of template value
             $stackVars[$i]['variable'] =& $this->templateVars[$stackVars[$i]['name']];
         } elseif (isset($stackVars[$i - 1]['variable']) && $stackVars[$i - 1]['variable'] instanceof \Magento\Framework\Object) {
             // If object calling methods or getting properties
             if ($stackVars[$i]['type'] == 'property') {
                 $caller = 'get' . $this->string->upperCaseWords($stackVars[$i]['name'], '_', '');
                 $stackVars[$i]['variable'] = method_exists($stackVars[$i - 1]['variable'], $caller) ? $stackVars[$i - 1]['variable']->{$caller}() : $stackVars[$i - 1]['variable']->getData($stackVars[$i]['name']);
             } elseif ($stackVars[$i]['type'] == 'method') {
                 // Calling of object method
                 if (method_exists($stackVars[$i - 1]['variable'], $stackVars[$i]['name']) || substr($stackVars[$i]['name'], 0, 3) == 'get') {
                     $stackVars[$i]['args'] = $this->getStackArgs($stackVars[$i]['args']);
                     $stackVars[$i]['variable'] = call_user_func_array([$stackVars[$i - 1]['variable'], $stackVars[$i]['name']], $stackVars[$i]['args']);
                 }
             }
             $last = $i;
         }
     }
     if (isset($stackVars[$last]['variable'])) {
         // If value for construction exists set it
         $result = $stackVars[$last]['variable'];
     }
     \Magento\Framework\Profiler::stop('email_template_processing_variables');
     return $result;
 }
開發者ID:nja78,項目名稱:magento2,代碼行數:42,代碼來源:Template.php

示例3: validateValue

 /**
  * Validate data
  * Return true or array of errors
  *
  * @param array|string $value
  * @return bool|array
  */
 public function validateValue($value)
 {
     $errors = array();
     $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:aiesh,項目名稱:magento2,代碼行數:42,代碼來源:Text.php

示例4: validateValue

 /**
  * {@inheritdoc}
  */
 public function validateValue($value)
 {
     $errors = array();
     $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 (!is_null($minTextLength) && $length < $minTextLength) {
         $errors[] = __('"%1" length must be equal or greater than %2 characters.', $label, $minTextLength);
     }
     $maxTextLength = ArrayObjectSearch::getArrayElementByName($validateRules, 'max_text_length');
     if (!is_null($maxTextLength) && $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:pavelnovitsky,項目名稱:magento2,代碼行數:38,代碼來源:Text.php

示例5: draw

 /**
  * Draw item line
  *
  * @return void
  */
 public function draw()
 {
     $item = $this->getItem();
     $pdf = $this->getPdf();
     $page = $this->getPage();
     $lines = array();
     // draw Product name
     $lines[0] = array(array('text' => $this->string->split($item->getName(), 60, true, true), 'feed' => 100));
     // draw QTY
     $lines[0][] = array('text' => $item->getQty() * 1, 'feed' => 35);
     // draw SKU
     $lines[0][] = array('text' => $this->string->split($this->getSku($item), 25), 'feed' => 565, 'align' => 'right');
     // Custom options
     $options = $this->getItemOptions();
     if ($options) {
         foreach ($options as $option) {
             // draw options label
             $lines[][] = array('text' => $this->string->split($this->filterManager->stripTags($option['label']), 70, true, true), 'font' => 'italic', 'feed' => 110);
             // draw options value
             if ($option['value']) {
                 $printValue = isset($option['print_value']) ? $option['print_value'] : $this->filterManager->stripTags($option['value']);
                 $values = explode(', ', $printValue);
                 foreach ($values as $value) {
                     $lines[][] = array('text' => $this->string->split($value, 50, true, true), 'feed' => 115);
                 }
             }
         }
     }
     $lineBlock = array('lines' => $lines, 'height' => 20);
     $page = $pdf->drawLineBlocks($page, array($lineBlock), array('table_header' => true));
     $this->setPage($page);
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:37,代碼來源:DefaultShipment.php

示例6: draw

 /**
  * Draw item line
  *
  * @return void
  */
 public function draw()
 {
     $order = $this->getOrder();
     $item = $this->getItem();
     $pdf = $this->getPdf();
     $page = $this->getPage();
     $lines = [];
     // draw Product name
     $lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];
     // draw SKU
     $lines[0][] = ['text' => $this->string->split($this->getSku($item), 17), 'feed' => 290, 'align' => 'right'];
     // draw QTY
     $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 435, 'align' => 'right'];
     // draw item Prices
     $i = 0;
     $prices = $this->getItemPricesForDisplay();
     $feedPrice = 395;
     $feedSubtotal = $feedPrice + 170;
     foreach ($prices as $priceData) {
         if (isset($priceData['label'])) {
             // draw Price label
             $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
             // draw Subtotal label
             $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
             $i++;
         }
         // draw Price
         $lines[$i][] = ['text' => $priceData['price'], 'feed' => $feedPrice, 'font' => 'bold', 'align' => 'right'];
         // draw Subtotal
         $lines[$i][] = ['text' => $priceData['subtotal'], 'feed' => $feedSubtotal, 'font' => 'bold', 'align' => 'right'];
         $i++;
     }
     // draw Tax
     $lines[0][] = ['text' => $order->formatPriceTxt($item->getTaxAmount()), 'feed' => 495, 'font' => 'bold', 'align' => 'right'];
     // custom options
     $options = $this->getItemOptions();
     if ($options) {
         foreach ($options as $option) {
             // draw options label
             $lines[][] = ['text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true), 'font' => 'italic', 'feed' => 35];
             if ($option['value']) {
                 if (isset($option['print_value'])) {
                     $printValue = $option['print_value'];
                 } else {
                     $printValue = $this->filterManager->stripTags($option['value']);
                 }
                 $values = explode(', ', $printValue);
                 foreach ($values as $value) {
                     $lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];
                 }
             }
         }
     }
     $lineBlock = ['lines' => $lines, 'height' => 20];
     $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true]);
     $this->setPage($page);
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:62,代碼來源:DefaultInvoice.php

示例7: render

 /**
  * Renders grid column
  *
  * @param \Magento\Framework\Object $row
  * @return string
  */
 public function render(\Magento\Framework\Object $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:shabbirvividads,項目名稱:magento2,代碼行數:16,代碼來源:Wrapline.php

示例8: render

 /**
  * Renders a column
  *
  * @param   \Magento\Framework\Object $row
  * @return  string
  */
 public function render(\Magento\Framework\Object $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, array('length' => 30))) . '</span>';
     } else {
         $value = $this->escapeHtml($value);
     }
     return $value;
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:16,代碼來源:Searchquery.php

示例9: 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:opexsw,項目名稱:magento2,代碼行數:20,代碼來源:Sku.php

示例10: getDir

 /**
  * Retrieve full path to a directory of certain type within a module
  *
  * @param string $moduleName Fully-qualified module name
  * @param string $type Type of module's directory to retrieve
  * @return string
  * @throws \InvalidArgumentException
  */
 public function getDir($moduleName, $type = '')
 {
     $path = $this->_string->upperCaseWords($moduleName, '_', '/');
     if ($type) {
         if (!in_array($type, array('etc', 'sql', 'data', 'i18n', 'view', 'Controller'))) {
             throw new \InvalidArgumentException("Directory type '{$type}' is not recognized.");
         }
         $path .= '/' . $type;
     }
     $result = $this->_modulesDirectory->getAbsolutePath($path);
     return $result;
 }
開發者ID:,項目名稱:,代碼行數:20,代碼來源:

示例11: 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\Object $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(__('The password must have at least %1 characters.', self::MIN_PASSWORD_LENGTH));
         }
         if ($this->string->substr($password, 0, 1) == ' ' || $this->string->substr($password, $length - 1, 1) == ' ') {
             throw new LocalizedException(__('The password can not begin or end with a space.'));
         }
         $object->setPasswordHash($object->hashPassword($password));
     }
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:23,代碼來源:Password.php

示例12: getDir

 /**
  * Retrieve full path to a directory of certain type within a module
  *
  * @param string $moduleName Fully-qualified module name
  * @param string $type Type of module's directory to retrieve
  * @return string
  * @throws \InvalidArgumentException
  */
 public function getDir($moduleName, $type = '')
 {
     if (null === ($path = $this->moduleRegistry->getModulePath($moduleName))) {
         $relativePath = $this->_string->upperCaseWords($moduleName, '_', '/');
         $path = $this->_modulesDirectory->getAbsolutePath($relativePath);
     }
     if ($type) {
         if (!in_array($type, [self::MODULE_ETC_DIR, self::MODULE_I18N_DIR, self::MODULE_VIEW_DIR, self::MODULE_CONTROLLER_DIR])) {
             throw new \InvalidArgumentException("Directory type '{$type}' is not recognized.");
         }
         $path .= '/' . $type;
     }
     return $path;
 }
開發者ID:vasiljok,項目名稱:magento2,代碼行數:22,代碼來源:Dir.php

示例13: testGetTooLongQuery

 public function testGetTooLongQuery()
 {
     $queryId = 123;
     $this->mapScopeConfig([self::XML_PATH_MAX_QUERY_LENGTH => 12]);
     $rawQueryText = 'This is very long search query text';
     $preparedQueryText = 'This is very';
     $this->stringMock->expects($this->once())->method('substr')->with($this->equalTo($rawQueryText))->will($this->returnValue($preparedQueryText));
     $this->requestMock->expects($this->once())->method('getParam')->with($this->equalTo(self::QUERY_VAR_NAME))->will($this->returnValue($rawQueryText));
     $this->objectManagerMock->expects($this->once())->method('create')->with($this->equalTo('Magento\\Search\\Model\\Query'))->will($this->returnValue($this->queryMock));
     $this->queryMock->expects($this->once())->method('loadByQuery')->with($this->equalTo($preparedQueryText))->will($this->returnSelf());
     $this->queryMock->expects($this->once())->method('getId')->will($this->returnValue($queryId));
     $this->queryMock->expects($this->once())->method('setIsQueryTextExceeded')->with($this->equalTo(true))->will($this->returnSelf());
     $query = $this->queryFactory->get();
     $this->assertSame($this->queryMock, $query);
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:15,代碼來源:QueryFactoryTest.php

示例14: load

 /**
  * Load search results
  *
  * @return $this
  */
 public function load()
 {
     $result = array();
     if (!$this->hasStart() || !$this->hasLimit() || !$this->hasQuery()) {
         $this->setResults($result);
         return $this;
     }
     $collection = $this->_catalogSearchData->getQuery()->getSearchCollection()->addAttributeToSelect('name')->addAttributeToSelect('description')->addBackendSearchFilter($this->getQuery())->setCurPage($this->getStart())->setPageSize($this->getLimit())->load();
     foreach ($collection as $product) {
         $description = strip_tags($product->getDescription());
         $result[] = array('id' => 'product/1/' . $product->getId(), 'type' => __('Product'), 'name' => $product->getName(), 'description' => $this->string->substr($description, 0, 30), 'url' => $this->_adminhtmlData->getUrl('catalog/product/edit', array('id' => $product->getId())));
     }
     $this->setResults($result);
     return $this;
 }
開發者ID:aiesh,項目名稱:magento2,代碼行數:20,代碼來源:Catalog.php

示例15: createAttribute

 /**
  * Create attribute model
  *
  * @param string $name
  * @return \Magento\GoogleShopping\Model\Attribute\DefaultAttribute
  */
 public function createAttribute($name)
 {
     $modelName = 'Magento\\GoogleShopping\\Model\\Attribute\\' . $this->_string->upperCaseWords($this->_googleShoppingHelper->normalizeName($name));
     try {
         /** @var \Magento\GoogleShopping\Model\Attribute\DefaultAttribute $attributeModel */
         $attributeModel = $this->_objectManager->create($modelName);
         if (!$attributeModel) {
             $attributeModel = $this->_objectManager->create('Magento\\GoogleShopping\\Model\\Attribute\\DefaultAttribute');
         }
     } catch (\Exception $e) {
         $attributeModel = $this->_objectManager->create('Magento\\GoogleShopping\\Model\\Attribute\\DefaultAttribute');
     }
     $attributeModel->setName($name);
     return $attributeModel;
 }
開發者ID:shabbirvividads,項目名稱:magento2,代碼行數:21,代碼來源:AttributeFactory.php


注:本文中的Magento\Framework\Stdlib\String類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。