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


PHP DataObject::addData方法代码示例

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


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

示例1: testAddData

 /**
  * Tests \Magento\Framework\DataObject->addData()
  */
 public function testAddData()
 {
     $this->_object->addData(['test' => 'value']);
     $this->assertEquals('value', $this->_object->getData('test'));
     $this->_object->addData(['test' => 'value1']);
     $this->assertEquals('value1', $this->_object->getData('test'));
     $this->_object->addData(['test2' => 'value2']);
     $this->assertEquals(['test' => 'value1', 'test2' => 'value2'], $this->_object->getData());
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:12,代码来源:ObjectTest.php

示例2: postRequest

 /**
  * Post request into gateway
  *
  * @param DataObject $request
  * @param ConfigInterface $config
  *
  * @return DataObject
  * @throws \Zend_Http_Client_Exception
  */
 public function postRequest(DataObject $request, ConfigInterface $config)
 {
     $result = new DataObject();
     $clientConfig = ['maxredirects' => 5, 'timeout' => 30, 'verifypeer' => $config->getValue('verify_peer')];
     if ($config->getValue('use_proxy')) {
         $clientConfig['proxy'] = $config->getValue('proxy_host') . ':' . $config->getValue('proxy_port');
         $clientConfig['httpproxytunnel'] = true;
         $clientConfig['proxytype'] = CURLPROXY_HTTP;
     }
     /** @var ZendClient $client */
     $client = $this->httpClientFactory->create();
     $client->setUri((bool) $config->getValue('sandbox_flag') ? $config->getValue('transaction_url_test_mode') : $config->getValue('transaction_url'));
     $client->setConfig($clientConfig);
     $client->setMethod(\Zend_Http_Client::POST);
     $client->setParameterPost($request->getData());
     $client->setHeaders(['X-VPS-VIT-CLIENT-CERTIFICATION-ID' => '33baf5893fc2123d8b191d2d011b7fdc', 'X-VPS-Request-ID' => $this->mathRandom->getUniqueHash(), 'X-VPS-CLIENT-TIMEOUT' => 45]);
     $client->setUrlEncodeBody(false);
     try {
         $response = $client->request();
         $responseArray = [];
         parse_str(strstr($response->getBody(), 'RESULT'), $responseArray);
         $result->setData(array_change_key_case($responseArray, CASE_LOWER));
         $result->setData('result_code', $result->getData('result'));
     } catch (\Zend_Http_Client_Exception $e) {
         $result->addData(['response_code' => -1, 'response_reason_code' => $e->getCode(), 'response_reason_text' => $e->getMessage()]);
         throw $e;
     } finally {
         $this->logger->debug(['request' => $request->getData(), 'result' => $result->getData()], (array) $config->getValue('getDebugReplacePrivateDataKeys'), (bool) $config->getValue('debug'));
     }
     return $result;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:40,代码来源:Gateway.php

示例3: execute

 /**
  * @return \Magento\Framework\Controller\Result\Json
  */
 public function execute()
 {
     $response = new DataObject();
     $id = $this->getRequest()->getParam('id');
     if (intval($id) > 0) {
         $product = $this->productRepository->getById($id);
         $response->setId($id);
         $response->addData($product->getData());
         $response->setError(0);
     } else {
         $response->setError(1);
         $response->setMessage(__('We can\'t retrieve the product ID.'));
     }
     /** @var \Magento\Framework\Controller\Result\Json $resultJson */
     $resultJson = $this->resultFactory->create(ResultFactory::TYPE_JSON);
     $resultJson->setData($response->toArray());
     return $resultJson;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:21,代码来源:JsonProductInfo.php

示例4: match

 /**
  * Math path
  *
  * @param string $pathInfo
  * @return bool|DataObject
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * 
@SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function match($pathInfo)
 {
     $identifier = trim($pathInfo, '/');
     $parts = explode('/', $identifier);
     if (count($parts) == 1) {
         $parts[0] = $this->getUrlKeyWithoutSuffix($parts[0]);
     }
     if (isset($parts[0]) && !isset($this->configB[$parts[0]])) {
         return false;
     }
     $module = $this->configB[$parts[0]];
     if (!$this->isEnabled($module)) {
         return false;
     }
     if (count($parts) > 1) {
         unset($parts[0]);
         $urlKey = implode('/', $parts);
         $urlKey = urldecode($urlKey);
         $urlKey = $this->getUrlKeyWithoutSuffix($urlKey);
     } else {
         $urlKey = '';
     }
     # check on static urls (urls for static pages, ex. lists)
     $type = $rewrite = false;
     foreach ($this->config[$module] as $t => $key) {
         if ($key === $urlKey) {
             if ($t == '_BASE_PATH') {
                 continue;
             }
             $type = $t;
             break;
         }
     }
     # check on dynamic urls (ex. urls of products, categories etc)
     if (!$type) {
         $collection = $this->urlRewriteCollectionFactory->create()->addFieldToFilter('url_key', $urlKey)->addFieldToFilter('module', $module);
         if ($collection->count()) {
             /** @var \Mirasvit\Core\Model\UrlRewrite $rewrite */
             $rewrite = $collection->getFirstItem();
             $type = $rewrite->getType();
         } else {
             return false;
         }
     }
     if ($type) {
         $action = $this->configB[$module . '_' . $type]['ACTION'];
         $params = $this->configB[$module . '_' . $type]['PARAMS'];
         $result = new DataObject();
         $actionParts = explode('_', $action);
         $result->addData(['route_name' => $actionParts[0], 'module_name' => $actionParts[0], 'controller_name' => $actionParts[1], 'action_name' => $actionParts[2], 'action_params' => $params]);
         if ($rewrite) {
             $result->setData('entity_id', $rewrite->getEntityId());
         }
         return $result;
     }
     return false;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:66,代码来源:UrlRewrite.php


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