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


PHP EncoderInterface::encode方法代码示例

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


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

示例1: getAlists

 public function getAlists($json = false)
 {
     //       return [1];
     $id = $this->getRequest()->getParam('id');
     $collection = $this->_testFactory->create()->setId($id);
     $listso = $this->_objectManager->create('Sugarcode\\Test\\Model\\Test')->load($id);
     $collection = unserialize($listso->getInListsGrid());
     if (sizeof($collection) > 0) {
         if ($json) {
             $jsonLists = [];
             foreach ($collection as $usrid) {
                 $jsonLists[$usrid] = 0;
             }
             return $this->_jsonEncoder->encode((object) $jsonLists);
         } else {
             return array_values($collection);
         }
     } else {
         if ($json) {
             return '{}';
         } else {
             return [];
         }
     }
 }
开发者ID:pradeeprcs,项目名称:TestModule,代码行数:25,代码来源:Gridtabs.php

示例2: _toHtml

 /**
  * Forms script response
  *
  * @return string
  */
 public function _toHtml()
 {
     $updateResult = $this->_coreRegistry->registry('composite_update_result');
     $resultJson = $this->_jsonEncoder->encode($updateResult);
     $jsVarname = $updateResult->getJsVarName();
     return $this->_jsHelper->getScript(sprintf('var %s = %s', $jsVarname, $resultJson));
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:12,代码来源:Result.php

示例3: install

 /**
  * {@inheritdoc}
  */
 public function install(SchemaSetupInterface $setup, ModuleContextInterface $context)
 {
     /** @var State[] $stateIndexers */
     $stateIndexers = [];
     $states = $this->statesFactory->create();
     foreach ($states->getItems() as $state) {
         /** @var State $state */
         $stateIndexers[$state->getIndexerId()] = $state;
     }
     foreach ($this->config->getIndexers() as $indexerId => $indexerConfig) {
         $expectedHashConfig = $this->encryptor->hash($this->encoder->encode($indexerConfig), Encryptor::HASH_VERSION_MD5);
         if (isset($stateIndexers[$indexerId])) {
             if ($stateIndexers[$indexerId]->getHashConfig() != $expectedHashConfig) {
                 $stateIndexers[$indexerId]->setStatus(StateInterface::STATUS_INVALID);
                 $stateIndexers[$indexerId]->setHashConfig($expectedHashConfig);
                 $stateIndexers[$indexerId]->save();
             }
         } else {
             /** @var State $state */
             $state = $this->stateFactory->create();
             $state->loadByIndexer($indexerId);
             $state->setHashConfig($expectedHashConfig);
             $state->setStatus(StateInterface::STATUS_INVALID);
             $state->save();
         }
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:30,代码来源:Recurring.php

示例4: report

 /**
  * Reports Modules and module changes to the database reporting_module_status table
  *
  * @return \Magento\NewRelicReporting\Model\Cron\ReportModulesInfo
  */
 public function report()
 {
     if ($this->config->isNewRelicEnabled()) {
         $moduleData = $this->collect->getModuleData();
         if (count($moduleData['changes']) > 0) {
             foreach ($moduleData['changes'] as $change) {
                 switch ($change['type']) {
                     case Config::ENABLED:
                         $modelData = ['type' => Config::MODULE_ENABLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)];
                         break;
                     case Config::DISABLED:
                         $modelData = ['type' => Config::MODULE_DISABLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)];
                         break;
                     case Config::INSTALLED:
                         $modelData = ['type' => Config::MODULE_INSTALLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)];
                         break;
                     case Config::UNINSTALLED:
                         $modelData = ['type' => Config::MODULE_UNINSTALLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)];
                         break;
                 }
                 /** @var \Magento\NewRelicReporting\Model\System $systemModel */
                 $systemModel = $this->systemFactory->create();
                 $systemModel->setData($modelData);
                 $systemModel->save();
             }
         }
     }
     return $this;
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:34,代码来源:ReportModulesInfo.php

示例5: getProductsJson

 /**
  * @return string
  */
 public function getProductsJson()
 {
     $products = $this->getCategory()->getProductsPosition();
     if (!empty($products)) {
         return $this->jsonEncoder->encode($products);
     }
     return '{}';
 }
开发者ID:Zash22,项目名称:magento,代码行数:11,代码来源:AssignProducts.php

示例6: _toOptionHtml

 /**
  * Render single action as dropdown option html
  *
  * @param array $action
  * @param \Magento\Framework\DataObject $row
  * @return string
  */
 protected function _toOptionHtml($action, \Magento\Framework\DataObject $row)
 {
     $actionAttributes = new \Magento\Framework\DataObject();
     $actionCaption = '';
     $this->_transformActionData($action, $actionCaption, $row);
     $htmlAttibutes = ['value' => $this->escapeHtml($this->_jsonEncoder->encode($action))];
     $actionAttributes->setData($htmlAttibutes);
     return '<option ' . $actionAttributes->serialize() . '>' . $actionCaption . '</option>';
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:16,代码来源:Action.php

示例7: execute

 /**
  * Reports a system cache flush to the database reporting_system_updates table
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         $jsonData = ['status' => 'updated'];
         $modelData = ['type' => Config::FLUSH_CACHE, 'action' => $this->jsonEncoder->encode($jsonData)];
         /** @var \Magento\NewRelicReporting\Model\System $systemModel */
         $systemModel = $this->systemFactory->create();
         $systemModel->setData($modelData);
         $systemModel->save();
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:18,代码来源:ReportSystemCacheFlush.php

示例8: getDataAsJSON

 /**
  * Get object data as JSON
  *
  * @return string
  */
 public function getDataAsJSON()
 {
     $result = [];
     $inputNames = $this->getInputNames();
     if ($serializeData = $this->getSerializeData()) {
         $result = $serializeData;
     } elseif (!empty($inputNames)) {
         return '{}';
     }
     return $this->_jsonEncoder->encode($result);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:16,代码来源:Serializer.php

示例9: execute

 /**
  * Reports any products deleted to the database reporting_system_updates table
  *
  * @param Observer $observer
  * @return void
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         /** @var \Magento\Catalog\Model\Product $product */
         $product = $observer->getEvent()->getProduct();
         $jsonData = ['id' => $product->getId(), 'status' => 'deleted'];
         $modelData = ['type' => Config::PRODUCT_CHANGE, 'action' => $this->jsonEncoder->encode($jsonData), 'updated_at' => $this->dateTime->formatDate(true)];
         /** @var \Magento\NewRelicReporting\Model\System $systemModel */
         $systemModel = $this->systemFactory->create();
         $systemModel->setData($modelData);
         $systemModel->save();
     }
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:19,代码来源:ReportProductDeleted.php

示例10: execute

 /**
  * Reports concurrent admins to the database reporting_users table
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         if ($this->backendAuthSession->isLoggedIn()) {
             $user = $this->backendAuthSession->getUser();
             $jsonData = ['id' => $user->getId(), 'username' => $user->getUsername(), 'name' => $user->getFirstname() . ' ' . $user->getLastname()];
             $modelData = ['type' => 'admin_activity', 'action' => $this->jsonEncoder->encode($jsonData)];
             /** @var \Magento\NewRelicReporting\Model\Users $usersModel */
             $usersModel = $this->usersFactory->create();
             $usersModel->setData($modelData);
             $usersModel->save();
         }
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:21,代码来源:ReportConcurrentAdmins.php

示例11: execute

 /**
  * Reports concurrent users to the database reporting_users table
  *
  * @param Observer $observer
  * @return void
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(Observer $observer)
 {
     if ($this->config->isNewRelicEnabled()) {
         if ($this->customerSession->isLoggedIn()) {
             $customer = $this->customerRepository->getById($this->customerSession->getCustomerId());
             $jsonData = ['id' => $customer->getId(), 'name' => $customer->getFirstname() . ' ' . $customer->getLastname(), 'store' => $this->storeManager->getStore()->getName(), 'website' => $this->storeManager->getWebsite()->getName()];
             $modelData = ['type' => 'user_action', 'action' => $this->jsonEncoder->encode($jsonData), 'updated_at' => $this->dateTime->formatDate(true)];
             /** @var \Magento\NewRelicReporting\Model\Users $usersModel */
             $usersModel = $this->usersFactory->create();
             $usersModel->setData($modelData);
             $usersModel->save();
         }
     }
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:21,代码来源:ReportConcurrentUsers.php

示例12: _toHtml

 /**
  * Render block HTML
  *
  * @return string
  */
 protected function _toHtml()
 {
     $result = [];
     $layout = $this->getLayout();
     foreach ($this->getChildNames() as $name) {
         $result[$name] = $layout->renderElement($name);
     }
     $resultJson = $this->_jsonEncoder->encode($result);
     $jsVarname = $this->getRequest()->getParam('as_js_varname');
     if ($jsVarname) {
         return $this->_jsHelper->getScript(sprintf('var %s = %s', $jsVarname, $resultJson));
     } else {
         return $resultJson;
     }
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:20,代码来源:Load.php

示例13: getJsonConfig

 /**
  * Get json representation of
  *
  * @return string
  */
 public function getJsonConfig()
 {
     $config = [];
     foreach ($this->getOptions() as $option) {
         /* @var $option \Magento\Catalog\Model\Product\Option */
         $priceValue = 0;
         if ($option->getGroupByType() == \Magento\Catalog\Model\Product\Option::OPTION_GROUP_SELECT) {
             $tmpPriceValues = [];
             foreach ($option->getValues() as $value) {
                 /* @var $value \Magento\Catalog\Model\Product\Option\Value */
                 $id = $value->getId();
                 $tmpPriceValues[$id] = $this->_getPriceConfiguration($value);
             }
             $priceValue = $tmpPriceValues;
         } else {
             $priceValue = $this->_getPriceConfiguration($option);
         }
         $config[$option->getId()] = $priceValue;
     }
     $configObj = new \Magento\Framework\DataObject(['config' => $config]);
     //pass the return array encapsulated in an object for the other modules to be able to alter it eg: weee
     $this->_eventManager->dispatch('catalog_product_option_price_configuration_after', ['configObj' => $configObj]);
     $config = $configObj->getConfig();
     return $this->_jsonEncoder->encode($config);
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:30,代码来源:Options.php

示例14: getJsonConfig

 /**
  * Get JSON encoded configuration array which can be used for JS dynamic
  * price calculation depending on product options
  *
  * @return string
  */
 public function getJsonConfig()
 {
     $config = array();
     if (!$this->hasOptions()) {
         return $this->_jsonEncoder->encode($config);
     }
     $customerId = $this->getCustomerId();
     /* @var $product \Magento\Catalog\Model\Product */
     $product = $this->getProduct();
     $defaultTax = $this->taxCalculationService->getDefaultCalculatedRate($product->getTaxClassId(), $customerId);
     $currentTax = $this->taxCalculationService->getCalculatedRate($product->getTaxClassId(), $customerId);
     $tierPrices = array();
     $tierPricesList = $product->getPriceInfo()->getPrice('tier_price')->getTierPriceList();
     foreach ($tierPricesList as $tierPrice) {
         $tierPrices[] = $this->_coreData->currency($tierPrice['price']->getValue(), false, false);
     }
     $config = array('productId' => $product->getId(), 'priceFormat' => $this->_localeFormat->getPriceFormat(), 'includeTax' => $this->_taxData->priceIncludesTax() ? 'true' : 'false', 'showIncludeTax' => $this->_taxData->displayPriceIncludingTax(), 'showBothPrices' => $this->_taxData->displayBothPrices(), 'productPrice' => $this->_coreData->currency($product->getPriceInfo()->getPrice('final_price')->getValue(), false, false), 'productOldPrice' => $this->_coreData->currency($product->getPriceInfo()->getPrice('regular_price')->getAmount()->getValue(), false, false), 'inclTaxPrice' => $this->_coreData->currency($product->getPriceInfo()->getPrice('final_price')->getAmount()->getValue(), false, false), 'exclTaxPrice' => $this->_coreData->currency($product->getPriceInfo()->getPrice('final_price')->getAmount()->getBaseAmount(), false, false), 'defaultTax' => $defaultTax, 'currentTax' => $currentTax, 'idSuffix' => '_clone', 'oldPlusDisposition' => 0, 'plusDisposition' => 0, 'plusDispositionTax' => 0, 'oldMinusDisposition' => 0, 'minusDisposition' => 0, 'tierPrices' => $tierPrices);
     $responseObject = new \Magento\Framework\Object();
     $this->_eventManager->dispatch('catalog_product_view_config', array('response_object' => $responseObject));
     if (is_array($responseObject->getAdditionalOptions())) {
         foreach ($responseObject->getAdditionalOptions() as $option => $value) {
             $config[$option] = $value;
         }
     }
     return $this->_jsonEncoder->encode($config);
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:32,代码来源:View.php

示例15: getTreeArray

 /**
  * Get categories tree as recursive array
  *
  * @param int $parentId
  * @param bool $asJson
  * @param int $recursionLevel
  * @return array
  */
 public function getTreeArray($parentId = null, $asJson = false, $recursionLevel = 3)
 {
     $productId = $this->_request->getParam('product');
     if ($productId) {
         $product = $this->_productFactory->create()->setId($productId);
         $this->_allowedCategoryIds = $product->getCategoryIds();
         unset($product);
     }
     $result = [];
     if ($parentId) {
         try {
             $category = $this->categoryRepository->get($parentId);
         } catch (NoSuchEntityException $e) {
             $category = null;
         }
         if ($category) {
             $tree = $this->_getNodesArray($this->getNode($category, $recursionLevel));
             if (!empty($tree) && !empty($tree['children'])) {
                 $result = $tree['children'];
             }
         }
     } else {
         $result = $this->_getNodesArray($this->getRoot(null, $recursionLevel));
     }
     if ($asJson) {
         return $this->_jsonEncoder->encode($result);
     }
     $this->_allowedCategoryIds = [];
     return $result;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:38,代码来源:Tree.php


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