コード例 #1
0
ファイル: Delete.php プロジェクト: rafaelstz/magento2
 /**
  * @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;
 }
コード例 #2
0
ファイル: Read.php プロジェクト: Doability/magento2dev
 /**
  * @param object $entity
  * @param string $identifier
  * @param array $arguments
  * @return object
  * @throws \Exception
  */
 public function execute($entity, $identifier, $arguments = [])
 {
     $entityType = $this->typeResolver->resolve($entity);
     $metadata = $this->metadataPool->getMetadata($entityType);
     $hydrator = $this->hydratorPool->getHydrator($entityType);
     $this->eventManager->dispatch('entity_manager_load_before', ['entity_type' => $entityType, 'identifier' => $identifier, 'arguments' => $arguments]);
     $this->eventManager->dispatchEntityEvent($entityType, 'load_before', ['identifier' => $identifier, 'arguments' => $arguments]);
     $entity = $this->readMain->execute($entity, $identifier);
     $entityData = array_merge($hydrator->extract($entity), $arguments);
     if (isset($entityData[$metadata->getLinkField()])) {
         $entity = $this->readAttributes->execute($entity, $arguments);
         $entity = $this->readExtensions->execute($entity, $arguments);
     }
     $this->eventManager->dispatchEntityEvent($entityType, 'load_after', ['entity' => $entity, 'arguments' => $arguments]);
     $this->eventManager->dispatch('entity_manager_load_after', ['entity_type' => $entityType, 'entity' => $entity, 'arguments' => $arguments]);
     return $entity;
 }