• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Json\EncoderInterface类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: setUp

 /**
  * Setup
  *
  * @return void
  */
 public function setUp()
 {
     $this->config = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Config')->disableOriginalConstructor()->setMethods(['isNewRelicEnabled'])->getMock();
     $this->collectMock = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Module\\Collect')->disableOriginalConstructor()->setMethods(['getModuleData'])->getMock();
     $this->systemFactoryMock = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\SystemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->systemModelMock = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\System')->disableOriginalConstructor()->getMock();
     $this->jsonEncoderMock = $this->getMockBuilder('Magento\\Framework\\Json\\EncoderInterface')->getMock();
     $this->systemFactoryMock->expects($this->any())->method('create')->willReturn($this->systemModelMock);
     $this->jsonEncoderMock->expects($this->any())->method('encode')->willReturn('json_string');
     $this->model = new ReportModulesInfo($this->config, $this->collectMock, $this->systemFactoryMock, $this->jsonEncoderMock);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:16,代码来源:ReportModulesInfoTest.php


示例2: setUp

 /**
  * Setup
  *
  * @return void
  */
 public function setUp()
 {
     $this->config = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Config')->disableOriginalConstructor()->setMethods(['isNewRelicEnabled'])->getMock();
     $this->collect = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Module\\Collect')->disableOriginalConstructor()->setMethods(['getModuleData'])->getMock();
     $this->systemFactory = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\SystemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->systemModel = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\System')->disableOriginalConstructor()->getMock();
     $this->jsonEncoder = $this->getMockBuilder('Magento\\Framework\\Json\\EncoderInterface')->getMock();
     $this->dateTime = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime')->disableOriginalConstructor()->setMethods(['formatDate'])->getMock();
     $this->systemFactory->expects($this->any())->method('create')->willReturn($this->systemModel);
     $this->jsonEncoder->expects($this->any())->method('encode')->willReturn('json_string');
     $this->dateTime->expects($this->any())->method('formatDate')->willReturn('1970-01-01 00:00:00');
     $this->model = new ReportModulesInfo($this->config, $this->collect, $this->systemFactory, $this->jsonEncoder, $this->dateTime);
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:18,代码来源:ReportModulesInfoTest.php


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


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


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


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


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


示例8: _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


示例9: testAfterGetOptions

 public function testAfterGetOptions()
 {
     $resultJson = '[]';
     $this->jsonDecoder->expects($this->once())->method('decode')->with('[]')->willReturn([]);
     $expected = ['configurable_attribute_1' => [['mediaType' => 'type', 'videoUrl' => 'url', 'isBase' => true]]];
     $this->jsonEncoder->expects($this->any())->method('encode')->with($expected)->willReturn(json_encode($expected));
     $blockMock = $this->getMockBuilder('\\Magento\\ProductVideo\\Block\\Product\\View\\Gallery')->disableOriginalConstructor()->getMock();
     $result = $this->plugin->afterGetOptionsMediaGalleryDataJson($blockMock, $resultJson);
     $this->assertEquals(json_encode($expected), $result);
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:10,代码来源:GalleryTest.php


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


示例11: testGetWidgetOptions

 public function testGetWidgetOptions()
 {
     $rand = rand();
     $this->mathRandom->expects($this->any())->method('getUniqueHash')->with('id_')->willReturn('id_' . $rand);
     $saveVideoUrl = 'http://host/index.php/admin/catalog/product_gallery/upload/key/';
     $saveRemoteVideoUrl = 'http://host/index.php/admin/product_video/product_gallery/retrieveImage/';
     $this->urlBuilder->expects($this->exactly(2))->method('getUrl')->willReturnOnConsecutiveCalls($saveVideoUrl, $saveRemoteVideoUrl);
     $value = ['saveVideoUrl' => $saveVideoUrl, 'saveRemoteVideoUrl' => $saveRemoteVideoUrl, 'htmlId' => 'id_' . $rand];
     $this->jsonEncoderMock->expects($this->once())->method('encode')->with($value)->willReturn(json_encode($value));
     $this->block->getWidgetOptions();
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:11,代码来源:NewVideoTest.php


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


示例13: testReportSystemCacheFlush

 /**
  * Test case when module is enabled in config
  *
  * @return void
  */
 public function testReportSystemCacheFlush()
 {
     $testType = 'systemCacheFlush';
     $testAction = 'JSON string';
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->jsonEncoder->expects($this->once())->method('encode')->willReturn($testAction);
     $this->systemModel->expects($this->once())->method('setData')->with(['type' => $testType, 'action' => $testAction])->willReturnSelf();
     $this->systemModel->expects($this->once())->method('save');
     $this->model->execute($eventObserver);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:17,代码来源:ReportSystemCacheFlushTest.php


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


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


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


示例17: testGetUsersPositiveNumberOfRolesAndJsonTrue

 public function testGetUsersPositiveNumberOfRolesAndJsonTrue()
 {
     $roleId = 1;
     $roles = ['role1', 'role2', 'role3'];
     /** @var \Magento\Authorization\Model\Role|\PHPUnit_Framework_MockObject_MockObject */
     $roleModelMock = $this->getMockBuilder('Magento\\Authorization\\Model\\Role')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->requestInterfaceMock->expects($this->at(0))->method('getParam')->willReturn("");
     $this->requestInterfaceMock->expects($this->at(1))->method('getParam')->willReturn($roleId);
     $this->requestInterfaceMock->expects($this->at(2))->method('getParam')->willReturn($roleId);
     $this->registryMock->expects($this->once())->method('registry')->with(\Magento\User\Controller\Adminhtml\User\Role\SaveRole::IN_ROLE_USER_FORM_DATA_SESSION_KEY)->willReturn('role1=value1&role2=value2&role3=value3');
     $this->roleFactoryMock->expects($this->never())->method('create')->willReturn($roleModelMock);
     $this->jsonEncoderMock->expects($this->once())->method('encode')->willReturn($roles);
     $this->assertEquals($roles, $this->model->getUsers(true));
 }
开发者ID:BlackIkeEagle,项目名称:magento2-continuousphp,代码行数:14,代码来源:UserTest.php


示例18: _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


示例19: testGetUsersPositiveNumberOfRolesAndJsonTrue

 public function testGetUsersPositiveNumberOfRolesAndJsonTrue()
 {
     $roleId = 1;
     $roles = ['role1', 'role2', 'role3'];
     /** @var \Magento\Authorization\Model\Role|\PHPUnit_Framework_MockObject_MockObject */
     $roleModelMock = $this->getMockBuilder('Magento\\Authorization\\Model\\Role')->disableOriginalConstructor()->setMethods([])->getMock();
     $this->requestInterfaceMock->expects($this->at(0))->method('getParam')->willReturn("");
     $this->requestInterfaceMock->expects($this->at(1))->method('getParam')->willReturn($roleId);
     $this->requestInterfaceMock->expects($this->at(2))->method('getParam')->willReturn($roleId);
     $this->roleFactoryMock->expects($this->once())->method('create')->willReturn($roleModelMock);
     $roleModelMock->expects($this->once())->method('setId')->willReturnSelf();
     $roleModelMock->expects($this->once())->method('getRoleUsers')->willReturn($roles);
     $this->jsonEncoderMock->expects($this->once())->method('encode')->willReturn($roles);
     $this->assertEquals($roles, $this->model->getUsers(true));
 }
开发者ID:hientruong90,项目名称:magento2_installer,代码行数:15,代码来源:UserTest.php


示例20: testGetImagesJson

 public function testGetImagesJson()
 {
     $url = [['file_1.jpg', 'url_to_the_image/image_1.jpg'], ['file_2.jpg', 'url_to_the_image/image_2.jpg']];
     $mediaPath = [['file_1.jpg', 'catalog/product/image_1.jpg'], ['file_2.jpg', 'catalog/product/image_2.jpg']];
     $sizeMap = [['catalog/product/image_1.jpg', ['size' => 399659]], ['catalog/product/image_2.jpg', ['size' => 879394]]];
     $imagesResult = [['value_id' => '2', 'file' => 'file_2.jpg', 'media_type' => 'image', 'position' => '0', 'url' => 'url_to_the_image/image_2.jpg', 'size' => 879394], ['value_id' => '1', 'file' => 'file_1.jpg', 'media_type' => 'image', 'position' => '1', 'url' => 'url_to_the_image/image_1.jpg', 'size' => 399659]];
     $images = ['images' => [['value_id' => '1', 'file' => 'file_1.jpg', 'media_type' => 'image', 'position' => '1'], ['value_id' => '2', 'file' => 'file_2.jpg', 'media_type' => 'image', 'position' => '0']]];
     $this->content->setElement($this->galleryMock);
     $this->galleryMock->expects($this->once())->method('getImages')->willReturn($images);
     $this->fileSystemMock->expects($this->once())->method('getDirectoryRead')->willReturn($this->readMock);
     $this->mediaConfigMock->expects($this->any())->method('getMediaUrl')->willReturnMap($url);
     $this->mediaConfigMock->expects($this->any())->method('getMediaPath')->willReturnMap($mediaPath);
     $this->readMock->expects($this->any())->method('stat')->willReturnMap($sizeMap);
     $this->jsonEncoderMock->expects($this->once())->method('encode')->willReturnCallback('json_encode');
     $this->assertSame(json_encode($imagesResult), $this->content->getImagesJson());
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:16,代码来源:ContentTest.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Helper\Data类代码示例发布时间:2022-05-23
下一篇:
PHP Indexer\IndexerRegistry类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap