本文整理汇总了PHP中Magento\Framework\Json\EncoderInterface类的典型用法代码示例。如果您正苦于以下问题:PHP EncoderInterface类的具体用法?PHP EncoderInterface怎么用?PHP EncoderInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EncoderInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
示例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;
}
示例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 [];
}
}
}
示例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();
}
}
}
示例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));
}
示例7: getProductsJson
/**
* @return string
*/
public function getProductsJson()
{
$products = $this->getCategory()->getProductsPosition();
if (!empty($products)) {
return $this->jsonEncoder->encode($products);
}
return '{}';
}
示例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>';
}
示例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);
}
示例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();
}
}
示例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();
}
示例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);
}
示例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);
}
示例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();
}
}
示例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();
}
}
}