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


PHP StringUtils::substr方法代码示例

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


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

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

示例2: load

 /**
  * Load search results
  *
  * @return $this
  */
 public function load()
 {
     $result = [];
     if (!$this->hasStart() || !$this->hasLimit() || !$this->hasQuery()) {
         $this->setResults($result);
         return $this;
     }
     $collection = $this->queryFactory->get()->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[] = ['id' => 'product/1/' . $product->getId(), 'type' => __('Product'), 'name' => $product->getName(), 'description' => $this->string->substr($description, 0, 30), 'url' => $this->_adminhtmlData->getUrl('catalog/product/edit', ['id' => $product->getId()])];
     }
     $this->setResults($result);
     return $this;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:20,代码来源:Catalog.php

示例3: getEditableOptionValue

 /**
  * Return formatted option value ready to edit, ready to parse
  *
  * @param string $optionValue Prepared for cart option value
  * @return string
  */
 public function getEditableOptionValue($optionValue)
 {
     $option = $this->getOption();
     $result = '';
     if (!$this->_isSingleSelection()) {
         foreach (explode(',', $optionValue) as $_value) {
             $_result = $option->getValueById($_value);
             if ($_result) {
                 $result .= $_result->getTitle() . ', ';
             } else {
                 if ($this->getListener()) {
                     $this->getListener()->setHasError(true)->setMessage($this->_getWrongConfigurationMessage());
                     $result = '';
                     break;
                 }
             }
         }
         $result = $this->string->substr($result, 0, -2);
     } elseif ($this->_isSingleSelection()) {
         $_result = $option->getValueById($optionValue);
         if ($_result) {
             $result = $_result->getTitle();
         } else {
             if ($this->getListener()) {
                 $this->getListener()->setHasError(true)->setMessage($this->_getWrongConfigurationMessage());
             }
             $result = '';
         }
     } else {
         $result = $optionValue;
     }
     return $result;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:39,代码来源:Select.php

示例4: _prepareLayout

 /**
  * Add meta information from product to head block
  *
  * @return \Magento\Catalog\Block\Product\View
  */
 protected function _prepareLayout()
 {
     $this->getLayout()->createBlock('Magento\\Catalog\\Block\\Breadcrumbs');
     $product = $this->getProduct();
     if (!$product) {
         return parent::_prepareLayout();
     }
     $title = $product->getMetaTitle();
     if ($title) {
         $this->pageConfig->getTitle()->set($title);
     }
     $keyword = $product->getMetaKeyword();
     $currentCategory = $this->_coreRegistry->registry('current_category');
     if ($keyword) {
         $this->pageConfig->setKeywords($keyword);
     } elseif ($currentCategory) {
         $this->pageConfig->setKeywords($product->getName());
     }
     $description = $product->getMetaDescription();
     if ($description) {
         $this->pageConfig->setDescription($description);
     } else {
         $this->pageConfig->setDescription($this->string->substr($product->getDescription(), 0, 255));
     }
     if ($this->_productHelper->canUseCanonicalTag()) {
         $this->pageConfig->addRemotePageAsset($product->getUrlModel()->getUrl($product, ['_ignore_category' => true]), 'canonical', ['attributes' => ['rel' => 'canonical']]);
     }
     $pageMainTitle = $this->getLayout()->getBlock('page.main.title');
     if ($pageMainTitle) {
         $pageMainTitle->setPageTitle($product->getName());
     }
     return parent::_prepareLayout();
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:38,代码来源:View.php

示例5: getPreparedQueryText

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

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

示例7: testSubstr

 public function testSubstr()
 {
     $this->assertSame('tring', $this->_string->substr('string', 1));
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:4,代码来源:StringUtilsTest.php

示例8: setRequest

 /**
  * Prepare and set request in property of current instance
  *
  * @param \Magento\Framework\DataObject $request
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function setRequest(\Magento\Framework\DataObject $request)
 {
     $this->_request = $request;
     $this->setStore($request->getStoreId());
     $requestObject = new \Magento\Framework\DataObject();
     $requestObject->setIsGenerateLabelReturn($request->getIsGenerateLabelReturn());
     $requestObject->setStoreId($request->getStoreId());
     if ($request->getLimitMethod()) {
         $requestObject->setService($request->getLimitMethod());
     }
     $requestObject = $this->_addParams($requestObject);
     if ($request->getDestPostcode()) {
         $requestObject->setDestPostal($request->getDestPostcode());
     }
     $requestObject->setOrigCountry($this->_getDefaultValue($request->getOrigCountry(), Shipment::XML_PATH_STORE_COUNTRY_ID))->setOrigCountryId($this->_getDefaultValue($request->getOrigCountryId(), Shipment::XML_PATH_STORE_COUNTRY_ID));
     $shippingWeight = $request->getPackageWeight();
     $requestObject->setValue(round($request->getPackageValue(), 2))->setValueWithDiscount($request->getPackageValueWithDiscount())->setCustomsValue($request->getPackageCustomsValue())->setDestStreet($this->string->substr(str_replace("\n", '', $request->getDestStreet()), 0, 35))->setDestStreetLine2($request->getDestStreetLine2())->setDestCity($request->getDestCity())->setOrigCompanyName($request->getOrigCompanyName())->setOrigCity($request->getOrigCity())->setOrigPhoneNumber($request->getOrigPhoneNumber())->setOrigPersonName($request->getOrigPersonName())->setOrigEmail($this->_scopeConfig->getValue('trans_email/ident_general/email', \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $requestObject->getStoreId()))->setOrigCity($request->getOrigCity())->setOrigPostal($request->getOrigPostal())->setOrigStreetLine2($request->getOrigStreetLine2())->setDestPhoneNumber($request->getDestPhoneNumber())->setDestPersonName($request->getDestPersonName())->setDestCompanyName($request->getDestCompanyName());
     $originStreet2 = $this->_scopeConfig->getValue(Shipment::XML_PATH_STORE_ADDRESS2, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $requestObject->getStoreId());
     $requestObject->setOrigStreet($request->getOrigStreet() ? $request->getOrigStreet() : $originStreet2);
     if (is_numeric($request->getOrigState())) {
         $requestObject->setOrigState($this->_regionFactory->create()->load($request->getOrigState())->getCode());
     } else {
         $requestObject->setOrigState($request->getOrigState());
     }
     if ($request->getDestCountryId()) {
         $destCountry = $request->getDestCountryId();
     } else {
         $destCountry = self::USA_COUNTRY_ID;
     }
     // for DHL, Puerto Rico state for US will assume as Puerto Rico country
     // for Puerto Rico, dhl will ship as international
     if ($destCountry == self::USA_COUNTRY_ID && ($request->getDestPostcode() == '00912' || $request->getDestRegionCode() == self::PUERTORICO_COUNTRY_ID)) {
         $destCountry = self::PUERTORICO_COUNTRY_ID;
     }
     $requestObject->setDestCountryId($destCountry)->setDestState($request->getDestRegionCode())->setWeight($shippingWeight)->setFreeMethodWeight($request->getFreeMethodWeight())->setOrderShipment($request->getOrderShipment());
     if ($request->getPackageId()) {
         $requestObject->setPackageId($request->getPackageId());
     }
     $requestObject->setBaseSubtotalInclTax($request->getBaseSubtotalInclTax());
     $this->setRawRequest($requestObject);
     return $this;
 }
开发者ID:IlyaGluschenko,项目名称:protection,代码行数:50,代码来源:Carrier.php


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