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


PHP ResourceConnection::getConnectionByName方法代码示例

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


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

示例1: execute

 /**
  * @param string $entityType
  * @param array $data
  * @return array
  */
 public function execute($entityType, $data)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName());
     $connection->update($metadata->getEntityTable(), $this->prepareData($metadata, $connection, $data), [$metadata->getLinkField() . ' = ?' => $data[$metadata->getLinkField()]]);
     return $data;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:12,代码来源:UpdateRow.php

示例2: execute

 /**
  * @param string $entityType
  * @param array $data
  * @return array
  */
 public function execute($entityType, $data)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $linkField = $metadata->getLinkField();
     $entityTable = $metadata->getEntityTable();
     $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName());
     $connection->insert($entityTable, $this->prepareData($metadata, $connection, $data));
     $data[$linkField] = $connection->lastInsertId($entityTable);
     return $data;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:15,代码来源:CreateRow.php

示例3: execute

 /**
  * @param CustomerInterface $entity
  * @param array $arguments
  * @return CustomerInterface
  * @throws \Exception
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entity, $arguments = [])
 {
     $metadata = $this->metadataPool->getMetadata(ExtensionAttributeInterface::class);
     $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName());
     $id = $connection->fetchOne($connection->select()->from($metadata->getEntityTable(), [$metadata->getIdentifierField()])->where('customer_id = ?', $entity->getId())->limit(1));
     $extensionAttribute = $this->extensionAttributeFactory->create();
     $extensionAttribute = $this->entityManager->load($extensionAttribute, $id);
     $customerExtension = $this->customerExtensionFactory->create(['data' => ['extension_attribute' => $extensionAttribute]]);
     $entity->setExtensionAttributes($customerExtension);
     return $entity;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:18,代码来源:ReadHandler.php

示例4: execute

 /**
  * @param string $entityType
  * @param string $identifier
  * @param array $context
  * @return array
  * @throws \Exception
  */
 public function execute($entityType, $identifier, $context = [])
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName());
     $metadata = $this->metadataPool->getMetadata($entityType);
     $select = $connection->select()->from(['t' => $metadata->getEntityTable()])->where($metadata->getIdentifierField() . ' = ?', $identifier);
     foreach ($context as $field => $value) {
         $select->where($connection->quoteIdentifier($field) . ' = ?', $value);
     }
     $data = $connection->fetchRow($select);
     return $data ?: [];
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:19,代码来源:ReadRow.php

示例5: execute

 /**
  * @param object $entity
  * @param array $arguments
  * @return bool
  * @throws \Exception
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entity, $arguments = [])
 {
     $entityType = $this->typeResolver->resolve($entity);
     $metadata = $this->metadataPool->getMetadata($entityType);
     $hydrator = $this->hydratorPool->getHydrator($entityType);
     $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName());
     $entityData = $hydrator->extract($entity);
     if (!isset($entityData[$metadata->getIdentifierField()])) {
         return false;
     }
     return (bool) $connection->fetchOne($connection->select()->from($metadata->getEntityTable(), [$metadata->getIdentifierField()])->where($metadata->getIdentifierField() . ' = ?', $entityData[$metadata->getIdentifierField()])->limit(1));
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:19,代码来源:CheckIfExists.php

示例6: delete

 /**
  * @param string $entityType
  * @param int $identifier
  * @return int
  * @throws \Exception
  */
 public function delete($entityType, $identifier)
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $sequenceInfo = $this->sequenceRegistry->retrieve($entityType);
     if (!isset($sequenceInfo['sequenceTable'])) {
         throw new \Exception('TODO: use correct Exception class' . PHP_EOL . ' Sequence table doesnt exists');
     }
     try {
         $connection = $this->appResource->getConnectionByName($metadata->getEntityConnectionName());
         return $connection->delete($this->appResource->getTableName($sequenceInfo['sequenceTable']), ['sequence_value = ?' => $identifier]);
     } catch (\Exception $e) {
         $this->logger->critical($e->getMessage(), $e->getTrace());
         throw new \Exception('TODO: use correct Exception class' . PHP_EOL . $e->getMessage());
     }
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:21,代码来源:SequenceManager.php

示例7: execute

 /**
  * @param string $entityType
  * @param object $entity
  * @param array $arguments
  * @return object
  * @throws \Exception
  */
 public function execute($entityType, $entity, $arguments = [])
 {
     $metadata = $this->metadataPool->getMetadata($entityType);
     $connection = $this->resourceConnection->getConnectionByName($metadata->getEntityConnectionName());
     $this->transactionManager->start($connection);
     try {
         $this->eventManager->dispatch(
             'entity_manager_delete_before',
             [
                 'entity_type' => $entityType,
                 'entity' => $entity
             ]
         );
         $this->eventManager->dispatchEntityEvent($entityType, 'delete_before', ['entity' => $entity]);
         $entity = $this->deleteExtensions->execute($entityType, $entity, $arguments);
         $entity = $this->deleteAttributes->execute($entityType, $entity, $arguments);
         $entity = $this->deleteMain->execute($entityType, $entity, $arguments);
         $this->eventManager->dispatchEntityEvent($entityType, 'delete_after', ['entity' => $entity]);
         $this->eventManager->dispatch(
             'entity_manager_delete_before',
             [
                 'entity_type' => $entityType,
                 'entity' => $entity
             ]
         );
         $this->transactionManager->commit();
     } catch (\Exception $e) {
         $this->transactionManager->rollBack();
         throw $e;
     }
     return $entity;
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:39,代码来源:Delete.php

示例8: testGetConnectionFail

 /**
  * @expectedException \DomainException
  * @expectedExceptionMessage Connection "invalid" is not defined
  */
 public function testGetConnectionFail()
 {
     $this->resource->getConnectionByName('invalid');
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:8,代码来源:AclResourceTest.php

示例9: getEntityConnection

 /**
  * @return \Magento\Framework\DB\Adapter\AdapterInterface
  */
 public function getEntityConnection()
 {
     return $this->appResource->getConnectionByName($this->connectionName);
 }
开发者ID:koliaGI,项目名称:magento2,代码行数:7,代码来源:EntityMetadata.php


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