本文整理汇总了PHP中Doctrine\ORM\Event\LifecycleEventArgs::getEntityManager方法的典型用法代码示例。如果您正苦于以下问题:PHP LifecycleEventArgs::getEntityManager方法的具体用法?PHP LifecycleEventArgs::getEntityManager怎么用?PHP LifecycleEventArgs::getEntityManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Event\LifecycleEventArgs
的用法示例。
在下文中一共展示了LifecycleEventArgs::getEntityManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postPersist
/**
* postPersist
*
* @param LifecycleEventArgs $event
*/
public function postPersist(LifecycleEventArgs $event)
{
//When the parent is created, the resource is load
if ($event->getObject() == $this->context) {
if ($this->accessor->isReadable($this->context, $this->property) && ($resource = $this->accessor->getValue($this->context, $this->property))) {
if ($resource instanceof ResourceObjectInterface) {
$resource = $this->loader->load($this->context, $this->property, $this->file);
//to avoid bubbling with the preUpdate
//$this->context = null;
$event->getEntityManager()->flush($resource);
}
}
} else {
$meta = $event->getEntityManager()->getClassMetadata(get_class($this->context));
$identifier = $meta->getSingleIdentifierColumnName();
//when the parent exists but the resource is created
if ($meta->getFieldValue($this->context, $identifier)) {
if ($this->accessor->isReadable($this->context, $this->property) && $event->getObject() == $this->accessor->getValue($this->context, $this->property)) {
if (($resource = $event->getObject()) && $resource instanceof ResourceObjectInterface) {
$this->loader->load($this->context, $this->property, $this->file);
//to avoid bubbling with the preUpdate
//$this->context = null;
$event->getEntityManager()->flush($resource);
}
}
}
}
}
示例2: prePersist
public function prePersist(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
$classHierarchyMetadata = $this->metadataFactory->getMetadataForClass(get_class($entity));
$classMetadata = $classHierarchyMetadata->classMetadata[get_class($entity)];
foreach ($classMetadata->propertyMetadata as $propertyMetadata) {
switch ($propertyMetadata->type) {
case 'odm':
$dm = $this->doctrine->getManager($propertyMetadata->targetManager);
// Copied following two lines from Doctrine\ORM\Mapping\ClassMetadataFactory
list($namespaceAlias, $simpleClassName) = explode(':', $propertyMetadata->targetObject);
$realClassName = $dm->getConfiguration()->getDocumentNamespace($namespaceAlias) . '\\' . $simpleClassName;
/**
* @var \Doctrine\Common\Persistence\Mapping\ClassMetadata $documentMetaData
*/
$documentMetaData = $dm->getClassMetadata($realClassName);
$document = $propertyMetadata->getValue($entity);
if (is_null($document)) {
continue;
}
$idValues = $documentMetaData->getIdentifierValues($document);
$propertyMetadata->setValue($entity, serialize($idValues));
$class = $args->getEntityManager()->getClassMetadata(get_class($entity));
$args->getEntityManager()->getUnitOfWork()->recomputeSingleEntityChangeSet($class, $entity);
break;
case 'mongodb':
throw new \Exception('MongoDB is not yet implemented');
break;
default:
break;
}
}
}
示例3: postPersist
public function postPersist(LifecycleEventArgs $args)
{
$obj = $args->getEntity();
// On veut envoyer un email que pour les entités Application
if ($obj instanceof Article) {
$article = $obj;
$em = $args->getEntityManager();
$news = new News();
$news->setType("article");
$news->setArticle($article);
$news->createAbstract($article->getContent());
$em->persist($news);
$em->flush();
//On flush pour créer l'id du content
}
if ($obj instanceof Playlist) {
$playlist = $obj;
$em = $args->getEntityManager();
$news = new News();
$news->setType("playlist");
$news->setPlaylist($playlist);
$news->createAbstract("");
$em->persist($news);
$em->flush();
//On flush pour créer l'id du content
}
return;
}
示例4: prePersist
/**
* @param LifecycleEventArgs $args
*/
public function prePersist(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if (!$this->isContactEntity($entity)) {
return;
}
/** @var Contact $entity */
$this->setCreatedProperties($entity, $args->getEntityManager());
$this->setUpdatedProperties($entity, $args->getEntityManager());
}
示例5: prePersist
public function prePersist(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof Vacancy) {
$encoder = new UrlEncoder($args->getEntityManager());
$entity->setUrlId($encoder->encode($entity, $entity->getTitle()));
} else {
if ($entity instanceof Organisation) {
$encoder = new UrlEncoder($args->getEntityManager());
$entity->setUrlId($encoder->encode($entity, $entity->getName()));
}
}
}
示例6: prePersist
/**
* @param LifecycleEventArgs $args
*/
public function prePersist(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if (!$this->isActivityListEntity($entity)) {
return;
}
/** @var ActivityList $entity */
if (!$entity->getCreatedAt()) {
$this->setCreatedProperties($entity, $args->getEntityManager());
}
if (!$entity->getUpdatedAt()) {
$this->setUpdatedProperties($entity, $args->getEntityManager());
}
}
示例7: postPersist
/**
* @param LifecycleEventArgs $event
*/
public function postPersist(LifecycleEventArgs $event)
{
if (!$this->enabled) {
return;
}
$this->loggableManager->handlePostPersist($event->getEntity(), $event->getEntityManager());
}
示例8: preRemove
public function preRemove(LifecycleEventArgs $eventArgs)
{
$entity = $eventArgs->getEntity();
if ($entity instanceof $this->objectClass) {
$this->scheduleForRemoval($entity, $eventArgs->getEntityManager());
}
}
示例9: postPersist
/**
* Este escucha permite esteblecer el consecutivo de las entidades
* al momento de ser almacenadas en base de datos
* @author Cesar Giraldo <cesargiraldo1108@gmail.com> 23/12/2015
* @param LifecycleEventArgs $args
*/
public function postPersist(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
$className = get_class($entity);
$entityManager = $args->getEntityManager();
$reflectedClass = new \ReflectionClass($className);
if ($reflectedClass->hasProperty('consecutive')) {
$consecutive = null;
$enabledEntity = false;
if ($entity instanceof Entity\Item) {
$enabledEntity = true;
//buscamos la cantidad de items que tiene creado un proyecto para asignar el consecutivo
$project = $entity->getProject();
$consecutive = $project->getLastItemConsecutive() + 1;
$project->setLastItemConsecutive($consecutive);
$entityManager->persist($project);
} elseif ($entity instanceof Entity\Sprint) {
$enabledEntity = true;
//buscamos la cantidad de items que tiene creado un proyecto para asignar el consecutivo
$project = $entity->getProject();
$consecutive = $project->getLastSprintConsecutive() + 1;
$project->setLastSprintConsecutive($consecutive);
$entityManager->persist($project);
}
if ($enabledEntity) {
if ($consecutive != null) {
$entity->setConsecutive($consecutive);
} else {
$entity->setConsecutive(1);
}
$entityManager->flush();
}
}
}
示例10: postPersist
public function postPersist(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
$entityManager = $args->getEntityManager();
if ($entity instanceof Attachment) {
//var_dump($entity); exit();
if (null === $entity->getFile()) {
return;
}
$id = sprintf('%010d', $entity->getId());
$path = $entity->getStoragePath() . substr($id, 6, 4) . '/' . substr($id, 2, 4) . '/' . $id;
$filename = $entity->getId() . '.' . $entity->getFile()->guessExtension();
if (!file_exists($path)) {
mkdir($path, 0777, true);
}
$entity->setFullpath($path . '/' . $filename);
$entity->getFile()->move($path, $filename);
$entity->setFile(null);
/*
$changelog = new Changelog();
$changelog->setTable($entityManager->getClassMetadata('ProductsBundle:Product')->getTableName());
$changelog->setAction('U');
$changelog->setRecordId($entity->getId());
$changelog->setUser($this->userCallable->getCurrentUser()->getId());
$changelog->setRecordData($entity->jsonSerialize());
*/
$entityManager->flush();
}
}
示例11: preUpdate
/**
* @param LifecycleEventArgs $args
*/
public function preUpdate(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if ($entity instanceof NodeTranslation) {
$this->setSlugWhenEmpty($entity, $args->getEntityManager());
}
}
示例12: checkBadWords
/**
* @param LifecycleEventArgs $args
* @return bool
* @throws \Exception
*/
public function checkBadWords(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
if (!$entity instanceof BadWordDetectorInterface) {
return true;
}
$badWords = $args->getEntityManager()->getRepository('RenowazeBundle:BadWord')->findAll();
/** @var BadWordDetector $annotationParams */
$annotationParams = $this->reader->getClassAnnotation(new \ReflectionClass($entity), 'RenowazeBundle\\Annotation\\BadWordDetector');
foreach ($annotationParams->fields as $field) {
$methodName = 'get' . ucfirst($field);
if (!method_exists($entity, $methodName)) {
throw new \Exception(sprintf('Field "%s" not found in entity "%s"', $methodName, get_class($entity)));
}
/** @var BadWord $badWord */
foreach ($badWords as $badWord) {
if (strpos($entity->{$methodName}(), $badWord->getWord()) !== false) {
$entity->setHasBadWords(true);
return true;
}
}
}
$entity->setHasBadWords(false);
return true;
}
示例13: process
/**
* @param LifecycleEventArgs $event
*/
protected function process(LifecycleEventArgs $event)
{
/** @var Page $page */
$page = $event->getEntity();
if (!$this->isApplicable($page)) {
return;
}
$expectedRoute = 'orob2b_cms_page_view';
$expectedParameters = ['id' => $page->getId()];
foreach ($page->getSlugs() as $slug) {
$actualRoute = $slug->getRouteName();
$actualParameters = $slug->getRouteParameters();
$changeSet = [];
if ($actualRoute !== $expectedRoute) {
$slug->setRouteName($expectedRoute);
$changeSet['routeName'] = [$actualRoute, $expectedRoute];
}
if ($actualParameters !== $expectedParameters) {
$slug->setRouteParameters($expectedParameters);
$changeSet['routeParameters'] = [$actualParameters, $expectedParameters];
}
if ($changeSet) {
$unitOfWork = $event->getEntityManager()->getUnitOfWork();
$unitOfWork->scheduleExtraUpdate($slug, $changeSet);
}
}
}
示例14: checkRelations
protected function checkRelations(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
$entityManager = $args->getEntityManager();
$entityName = (new \ReflectionClass($entity))->getShortName();
if (in_array($entityManager->getClassMetadata(get_class($entity))->name, $this->excludedEntities)) {
return;
}
$mappings = $entityManager->getClassMetadata(get_class($entity))->getAssociationMappings();
foreach ($mappings as $mapping) {
if ($mapping['type'] === ClassMetadataInfo::ONE_TO_MANY || $mapping['type'] === ClassMetadataInfo::MANY_TO_MANY) {
$targetEntityMeta = $entityManager->getClassMetadata($mapping['targetEntity']);
if ($targetEntityMeta->reflClass->getParentClass()) {
if (in_array($targetEntityMeta->reflClass->getParentClass()->name, $this->ignoredEntities)) {
continue;
}
}
$accessor = PropertyAccess::createPropertyAccessor();
$value = $accessor->getValue($entity, $mapping['fieldName']);
if (count($value) === 0) {
continue;
}
$exception = new HasRelationException();
$exception->setEntityName($entityName);
$exception->setEntity($entity);
$exception->setMapping($mapping);
throw $exception;
}
}
}
示例15: preRemove
/**
* Pre remove event handler
*
* @param LifecycleEventArgs $args
*/
public function preRemove(LifecycleEventArgs $args)
{
$entity = $args->getEntity();
$classMetadata = $args->getEntityManager()->getClassMetadata(get_class($entity));
$identifiers = $classMetadata->getIdentifierValues($entity);
$this->inventory->setIdentifiers($entity, $identifiers);
}