本文整理汇总了PHP中Doctrine\ORM\UnitOfWork::computeChangeSets方法的典型用法代码示例。如果您正苦于以下问题:PHP UnitOfWork::computeChangeSets方法的具体用法?PHP UnitOfWork::computeChangeSets怎么用?PHP UnitOfWork::computeChangeSets使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\UnitOfWork
的用法示例。
在下文中一共展示了UnitOfWork::computeChangeSets方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preFlush
/**
* @param \Doctrine\ORM\Event\PreFlushEventArgs $eventArgs
*
* @author Andreas Glaser
*/
public function preFlush(PreFlushEventArgs $eventArgs)
{
$this->entityManager = $eventArgs->getEntityManager();
$this->unitOfWork = $this->entityManager->getUnitOfWork();
if ($this->config['common_entity_event_handler']) {
if (class_exists($this->config['common_entity_event_handler'])) {
$this->commonEntityEventHandler = new $this->config['common_entity_event_handler']($this->container, $this, $this->entityManager);
} else {
throw new \InvalidArgumentException(strtr('":class" does not exist', [':class' => $this->config['common_entity_event_handler']]));
}
}
$this->unitOfWork->computeChangeSets();
$max = 50;
$current = 0;
do {
$runAgain = $this->executeEvents();
$current++;
} while ($runAgain === true && $current <= $max);
if ($current >= $max) {
throw new \RuntimeException('Too many iterations... something must have gone wrong.');
}
}
示例2: setTags
/**
* Do the stuff
*
* @param TaggableInterface $entity
* @param boolean $update true if entity is being updated, false otherwise
*/
protected function setTags(TaggableInterface $entity, $update = false)
{
$tagNames = $entity->getTagNames();
if (empty($tagNames)) {
return;
}
// need to clone here, to avoid getting new tags
$oldTags = is_object($entityTags = $entity->getTags()) ? clone $entityTags : $entityTags;
$tagClassMetadata = $this->em->getClassMetadata(get_class($this->tag));
$repository = $this->em->getRepository(get_class($this->tag));
foreach ($tagNames as $tagName) {
$tag = $repository->findOneByName($tagName);
if (empty($tag)) {
// if tag doesn't exist, create it
$tag = clone $this->tag;
$tag->setName($tagName);
$this->em->persist($tag);
// see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#onflush
$this->uow->computeChangeSet($tagClassMetadata, $tag);
}
if (!$entity->hasTag($tag)) {
// add tag only if not already added
$entity->addTag($tag);
}
}
// if updating, need to check if some tags were removed
if ($update) {
foreach ($oldTags as $oldTag) {
if (!in_array($oldTag->getName(), $tagNames)) {
$entity->removeTag($oldTag);
}
}
}
// see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/events.html#onflush
$entityClassMetadata = $this->em->getClassMetadata(get_class($entity));
$this->uow->computeChangeSets($entityClassMetadata, $entity);
}
示例3: onFlush
public function onFlush(OnFlushEventArgs $e)
{
$this->init($e);
if ($this->stats) {
foreach ($this->uow->getScheduledEntityInsertions() as $entity) {
if ($entity instanceof Deposit) {
// deposit arrived
if ($entity->isConfirmed()) {
// it is confirmed
$this->addConfirmedDeposit($entity);
} else {
// it is pending
$entity->getAccount()->addTotalPendingDeposit($entity->getAmount());
$this->stats->addTotalPendingDeposit($entity->getAmount());
}
$this->stats->setLastDeposit($entity->getReceivedTime());
$this->recoumputeChanges($entity->getAccount());
}
if ($entity instanceof PayoutTx) {
// transaction has just been sent
$this->stats->addTotalTxFees($entity->getTxFee() * -1);
}
}
foreach ($this->uow->getScheduledEntityUpdates() as $entity) {
if ($entity instanceof Deposit) {
$changes = $this->uow->getEntityChangeSet($entity);
if (isset($changes['confirmed'])) {
$oldConfirmed = $changes['confirmed'][0];
$newConfirmed = $changes['confirmed'][1];
if (!$oldConfirmed && $newConfirmed) {
// subtract pending if not referrer
$this->stats->subtractTotalPendingDeposit($entity->getAmount());
$entity->getAccount()->subtractTotalPendingDeposit($entity->getAmount());
// add confirmed
$this->addConfirmedDeposit($entity);
$this->recoumputeChanges($entity->getAccount());
}
}
}
if ($entity instanceof Payout) {
$changes = $this->uow->getEntityChangeSet($entity);
if (isset($changes['paid'])) {
$oldPaid = $changes['paid'][0];
$newPaid = $changes['paid'][1];
if (!$oldPaid && $newPaid) {
if ($entity->isDefaultPayout() || $entity->isRemainingFundsReturn() || $entity->isLastPayout()) {
$this->stats->addTotalPayout($entity->getAmount());
$entity->getAccount()->addTotalPayout($entity->getAmount());
if ($entity->isDefaultPayout()) {
$this->stats->setLastPayout($entity->getPaidOutTime());
}
} elseif ($entity->isReferrerPayout()) {
$this->stats->addTotalReferralPayout($entity->getAmount());
$entity->getAccount()->addTotalReferralPayout($entity->getAmount());
}
if (!$entity->isLastAdminPayout()) {
$this->recoumputeChanges($entity->getAccount());
}
$this->stats->addTotalFees($entity->getFee());
}
}
}
}
$this->recoumputeChanges($this->stats);
$this->uow->computeChangeSets();
}
}
示例4: computeViolations
/**
* @param object $entity entity
* @param ObjectManager $entityManager entityManager
* @param UnitOfWork $uow uow
*/
private function computeViolations($entity, ObjectManager $entityManager, UnitOfWork $uow)
{
if (!($handlers = $this->handlerManager->fetch($entity))) {
return null;
}
$list = $this->violationManager->getViolationListNotFixed($entity);
$list->setFixed(true);
foreach ($handlers as $handler) {
$handler->validate($entity, $list);
}
$uow->computeChangeSets();
foreach ($list as $violation) {
$changeSet = $uow->getEntityChangeSet($violation);
if (!empty($changeSet) || !$entityManager->contains($violation)) {
$this->violations[spl_object_hash($violation)] = $violation;
}
}
}