本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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 ?: [];
}
示例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));
}
示例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());
}
}
示例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;
}
示例8: testGetConnectionFail
/**
* @expectedException \DomainException
* @expectedExceptionMessage Connection "invalid" is not defined
*/
public function testGetConnectionFail()
{
$this->resource->getConnectionByName('invalid');
}
示例9: getEntityConnection
/**
* @return \Magento\Framework\DB\Adapter\AdapterInterface
*/
public function getEntityConnection()
{
return $this->appResource->getConnectionByName($this->connectionName);
}