Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CallbackHandler.php
Go to the documentation of this file.
1 <?php
8 
10 use Psr\Log\LoggerInterface;
11 
16 {
20  protected $metadataPool;
21 
25  protected $logger;
26 
33  public function __construct(
36  ) {
37  $this->metadataPool = $metadataPool;
38  $this->logger = $logger;
39  }
40 
46  public function process($entityType)
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  }
63 
70  public function attach($entityType, $callback)
71  {
72  $metadata = $this->metadataPool->getMetadata($entityType);
73  CallbackPool::attach(spl_object_hash($metadata->getEntityConnection()), $callback);
74  }
75 
81  public function clear($entityType)
82  {
83  $metadata = $this->metadataPool->getMetadata($entityType);
84  CallbackPool::clear(spl_object_hash($metadata->getEntityConnection()));
85  }
86 }
__construct(MetadataPool $metadataPool, LoggerInterface $logger)
static attach($hashKey, $callback)
$connection
Definition: bulk.php:13