Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
CallbackHandler Class Reference

Public Member Functions

 __construct (MetadataPool $metadataPool, LoggerInterface $logger)
 
 process ($entityType)
 
 attach ($entityType, $callback)
 
 clear ($entityType)
 

Protected Attributes

 $metadataPool
 
 $logger
 

Detailed Description

Class CallbackHandler

Definition at line 15 of file CallbackHandler.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( MetadataPool  $metadataPool,
LoggerInterface  $logger 
)

CallbackHandler constructor.

Parameters
MetadataPool$metadataPool
LoggerInterface$logger

Definition at line 33 of file CallbackHandler.php.

Member Function Documentation

◆ attach()

attach (   $entityType,
  $callback 
)
Parameters
string$entityType
array$callback
Exceptions

Definition at line 70 of file CallbackHandler.php.

71  {
72  $metadata = $this->metadataPool->getMetadata($entityType);
73  CallbackPool::attach(spl_object_hash($metadata->getEntityConnection()), $callback);
74  }
static attach($hashKey, $callback)

◆ clear()

clear (   $entityType)
Parameters
string$entityType
Exceptions

Definition at line 81 of file CallbackHandler.php.

82  {
83  $metadata = $this->metadataPool->getMetadata($entityType);
84  CallbackPool::clear(spl_object_hash($metadata->getEntityConnection()));
85  }

◆ process()

process (   $entityType)
Parameters
string$entityType
Exceptions

Definition at line 46 of file CallbackHandler.php.

47  {
48  $metadata = $this->metadataPool->getMetadata($entityType);
49  $connection = $metadata->getEntityConnection();
50  $hash = spl_object_hash($connection);
51  if ($connection->getTransactionLevel() === 0) {
52  $callbacks = CallbackPool::get($hash);
53  try {
54  foreach ($callbacks as $callback) {
55  call_user_func($callback);
56  }
57  } catch (\Exception $e) {
58  $this->logger->error($e->getMessage(), $e->getTrace());
59  throw $e;
60  }
61  }
62  }
$connection
Definition: bulk.php:13

Field Documentation

◆ $logger

$logger
protected

Definition at line 25 of file CallbackHandler.php.

◆ $metadataPool

$metadataPool
protected

Definition at line 20 of file CallbackHandler.php.


The documentation for this class was generated from the following file: