本文整理汇总了PHP中Doctrine\Common\Persistence\Event\LifecycleEventArgs::getObjectManager方法的典型用法代码示例。如果您正苦于以下问题:PHP LifecycleEventArgs::getObjectManager方法的具体用法?PHP LifecycleEventArgs::getObjectManager怎么用?PHP LifecycleEventArgs::getObjectManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\Event\LifecycleEventArgs
的用法示例。
在下文中一共展示了LifecycleEventArgs::getObjectManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preRemove
public function preRemove(LifecycleEventArgs $args)
{
$entity = $args->getObject();
if ($entity instanceof Page) {
$menuElements = $args->getObjectManager()->getRepository('SKCMSCoreBundle:MenuElement')->findBy(['entityClass' => '\\' . get_class($entity), 'entityId' => $entity->getId()]);
foreach ($menuElements as $menuElement) {
$args->getObjectManager()->remove($menuElement);
}
}
}
示例2: postPersist
/**
* @param LifecycleEventArgs $args
*/
public function postPersist(LifecycleEventArgs $args)
{
$entity = $args->getObject();
if ($entity instanceof Dog || $entity instanceof Member || $entity instanceof Affiliate) {
if (!$entity->getRegNumber()) {
$entity->setRegNumber($this->generateRegNumber($entity->getId()));
$tableName = $args->getObjectManager()->getClassMetadata(get_class($entity))->getTableName();
$dbConnection = $args->getObjectManager()->getConnection();
$dbConnection->executeUpdate('UPDATE ' . $tableName . ' SET regNumber = ? WHERE id = ?', array($entity->getRegNumber(), $entity->getId()));
}
}
}
示例3: PostUpdate
public function PostUpdate(LifecycleEventArgs $args)
{
$entity = $args->getObject();
$em = $args->getObjectManager();
$classMetaData = $em->getClassMetadata(get_class($entity));
foreach ($classMetaData->associationMappings as $associationMappingKey => $associationMappingDatas) {
if ($associationMappingDatas['type'] == \Doctrine\ORM\Mapping\ClassMetadataInfo::ONE_TO_MANY) {
$repo = $em->getRepository($associationMappingDatas['targetEntity']);
$associated = $repo->findBy([$associationMappingDatas['mappedBy'] => $entity]);
$newAssociated = call_user_func([$entity, 'get' . ucfirst($associationMappingKey)]);
$changed = false;
foreach ($associated as $associatedEntity) {
if (!$newAssociated->contains($associatedEntity)) {
$changed = true;
$em->remove($associatedEntity);
}
}
if ($changed) {
$em->flush();
}
//
}
}
// dump($classMetaData);
// die();
}
示例4: postPersist
/**
* @param EventArgs|LifecycleEventArgs $args
*/
public function postPersist(LifecycleEventArgs $args)
{
$entity = $args->getObject();
$em = $args->getObjectManager();
if ($entity instanceof Comment) {
if ($entity->getArticleId() != null) {
if ($entity->getUserId()->getId() != $entity->getArticleId()->getUserId()->getId()) {
$n = new Notification();
$n->setUser($entity->getUserId())->setArticle($entity->getArticleId());
$em->persist($n);
$em->flush();
}
} else {
if ($entity->getVideoId() != null) {
if ($entity->getUserId()->getId() != $entity->getVideoId()->getUserId()->getId()) {
$n = new Notification();
$n->setUser($entity->getUserId())->setVideo($entity->getVideoId());
$em->persist($n);
$em->flush();
}
} else {
if ($entity->getLinkId() != null) {
if ($entity->getUserId()->getId() != $entity->getLinkId()->getUserId()->getId()) {
$n = new Notification();
$n->setUser($entity->getUserId())->setLink($entity->getLinkId());
$em->persist($n);
$em->flush();
}
}
}
}
}
}
示例5: preUpdate
/**
* Pre update
* PreUpdate event needs to recompute change set
*
* @param LifecycleEventArgs $args
*/
public function preUpdate(LifecycleEventArgs $args)
{
$product = $args->getObject();
if ($product instanceof ProductInterface) {
$dm = $args->getObjectManager();
$this->convertMetricValues($dm, $product);
}
}
示例6: postTruncate
/**
* Post-truncate
*
* @param \Doctrine\Common\Persistence\Event\LifecyleEventArgs $args
*/
public function postTruncate(LifecycleEventArgs $args)
{
$connection = $args->getObjectManager()->getConnection();
$platform = $connection->getDatabasePlatform();
if ($platform instanceof MySqlPlatform) {
$connection->exec('SET foreign_key_checks = 1;');
}
}
示例7: preUpdate
/**
* Pre update listener based on doctrine common
*
* @param LifecycleEventArgs $args
*/
public function preUpdate(LifecycleEventArgs $args)
{
$object = $args->getObject();
if ($object instanceof UserInterface) {
$this->updateUserFields($object);
$this->recomputeChangeSet($args->getObjectManager(), $object);
}
}
示例8: updateSlug
/**
* @param LifecycleEventArgs $lifecycleEventArgs
*/
private function updateSlug(LifecycleEventArgs $lifecycleEventArgs)
{
$object = $lifecycleEventArgs->getObject();
$productTranslationRepository = $lifecycleEventArgs->getObjectManager()->getRepository(get_class($object));
$slug = $this->slugify($object->getName(), $productTranslationRepository);
$object->setSlug($slug);
$this->generatedSlugs[] = $slug;
}
示例9: prePersist
public function prePersist(LifecycleEventArgs $args)
{
$entity = $args->getObject();
if ($entity instanceof PaymentInterface) {
$generator = new UuidGenerator();
$token = $generator->generate($args->getObjectManager(), null);
$entity->setToken($token);
}
}
示例10: preUpdate
/**
* Pre update
* PreUpdate event needs to recompute change set
*
* @param LifecycleEventArgs $args
*/
public function preUpdate(LifecycleEventArgs $args)
{
$object = $args->getObject();
if ($object instanceof MetricInterface && $object->getUnit()) {
$this->createMetricBaseValues($object);
$class = new ClassMetadata($object);
$args->getObjectManager()->getUnitOfWork()->recomputeSingleDocumentChangeSet($class, $object);
}
}
示例11: postLoad
public function postLoad(LifecycleEventArgs $args)
{
$object = $args->getObject();
if ($object instanceof ComponentInterface) {
$resolver = new Resolver($args->getObjectManager());
$resolverComponent = new ResolverComponentModelIdentifier($object->getModel(), $object->getIdentifier());
$object->setData($resolver->resolve($resolverComponent));
}
}
示例12: deleteChildren
/**
* @ORM\PreRemove
* @param LifecycleEventArgs $args
* @throws \Exception
*/
public function deleteChildren(LifecycleEventArgs $args)
{
$objectManager = $args->getObjectManager();
$entityType = $objectManager->getRepository('Comment\\Entity\\EntityType')->findOneByAlias('comment');
$commentRepository = $objectManager->getRepository('Comment\\Entity\\Comment');
$comments = $commentRepository->findBy(array('entityType' => $entityType, 'entityId' => $this->getId()));
foreach ($comments as $comment) {
$objectManager->remove($comment);
}
}
示例13: prePersist
public function prePersist(LifecycleEventArgs $args)
{
/** @var User $entity */
$entity = $args->getObject();
/** @var EntityManager $em */
$em = $args->getObjectManager();
if ($entity instanceof User && $entity->getTeamId() && !$entity->getTeam()) {
/** @var Team $team */
$team = $em->getRepository('Patgod85TeamBundle:Team')->find($entity->getTeamId());
$entity->setTeam($team);
}
}
示例14: handleTimestamp
/**
* Set the timestamps. If created is NULL then set it. Always
* set the changed field.
*
* @param LifecycleEventArgs $event
*/
private function handleTimestamp(LifecycleEventArgs $event)
{
$entity = $event->getObject();
if (!$entity instanceof TimestampableInterface) {
return;
}
$meta = $event->getObjectManager()->getClassMetadata(get_class($entity));
$created = $meta->getFieldValue($entity, self::CREATED_FIELD);
if (null === $created) {
$meta->setFieldValue($entity, self::CREATED_FIELD, new \DateTime());
}
$meta->setFieldValue($entity, self::CHANGED_FIELD, new \DateTime());
}
示例15: clearCache
protected function clearCache(LifecycleEventArgs $args)
{
$entity = $args->getObject();
$classes = $this->classes;
foreach ($classes as $class) {
if ($entity instanceof $class) {
$this->app['monolog']->debug('clear result cache: ' . $class);
$cache = $args->getObjectManager()->getConfiguration()->getResultCacheImpl();
$cache->deleteAll();
break;
}
}
}