本文整理汇总了PHP中Doctrine\ODM\MongoDB\Event\LifecycleEventArgs::getDocumentManager方法的典型用法代码示例。如果您正苦于以下问题:PHP LifecycleEventArgs::getDocumentManager方法的具体用法?PHP LifecycleEventArgs::getDocumentManager怎么用?PHP LifecycleEventArgs::getDocumentManager使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\Event\LifecycleEventArgs
的用法示例。
在下文中一共展示了LifecycleEventArgs::getDocumentManager方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prePersist
public function prePersist(LifecycleEventArgs $eventArgs)
{
$document = $eventArgs->getDocument();
if (!method_exists($document, 'addHistoryEvent')) {
return;
}
$historyRecord = $this->createEvent();
$historyRecord->setType(HistoryEventType::RECORD_CREATED);
$historyRecord->setTitle('Record created');
$originalValues = $eventArgs->getDocumentManager()->getUnitOfWork()->getDocumentActualData($document);
$historyRecord->setInfo(substr($this->getDetailedCreateInfo($originalValues), 0, 100000));
$document->addHistoryEvent($historyRecord);
$eventArgs->getDocumentManager()->persist($historyRecord);
}
示例2: preRemove
public function preRemove(LifecycleEventArgs $args)
{
$dm = $args->getDocumentManager();
$currentDocument = $args->getDocument();
$currentDocumentClass = get_class($currentDocument);
$isRefExists = FALSE;
$documentClassNames = $dm->getConfiguration()->getMetadataDriverImpl()->getAllClassNames();
foreach ($documentClassNames as $documentClassName) {
try {
$cm = $dm->getClassMetadata($documentClassName);
foreach ($cm->getAssociationNames() as $associationName) {
if ($currentDocumentClass == $cm->getAssociationTargetClass($associationName) || is_subclass_of($currentDocumentClass, $cm->getAssociationTargetClass($associationName))) {
$searchObj = $dm->getRepository($documentClassName)->findOneBy(array($associationName . '.$id' => new \MongoId($currentDocument->getId())));
if ($searchObj) {
$isRefExists = TRUE;
}
}
}
} catch (\Exception $e) {
}
}
if ($isRefExists) {
throw new \Exception('ref_erro');
}
}
示例3: preUpdate
public function preUpdate(LifecycleEventArgs $args)
{
$document = $args->getDocument();
// perhaps you only want to act on some "Product" document
if ($document instanceof Project) {
$dm = $args->getDocumentManager();
$document->setDateUpdated(new \DateTime("now"));
$class = $dm->getClassMetadata("Zeega\\DataBundle\\Document\\Project");
if ($args->hasChangedField("tags")) {
$update = true;
$oldTags = $args->getOldValue('tags');
foreach ($oldTags as $tag) {
$name = $tag->getName();
$id = $tag->getId();
if ($name == 'homepage' && $id !== null) {
$update = false;
break;
}
}
if ($update === true) {
$document->setDateTagsUpdated(new \DateTime("now"));
}
}
$dm->getUnitOfWork()->recomputeSingleDocumentChangeSet($class, $document);
}
}
示例4: postLoad
/**
* Hydrates the given node
* @param LifecycleEventArgs $eventArgs
*/
public function postLoad(LifecycleEventArgs $eventArgs)
{
if ($eventArgs->getDocument() instanceof Node) {
/*
* Loading users and group inside the current Node
* Using an event suscriber to allow these objects to come from many places
*/
$node = $eventArgs->getDocument();
$groupId = $node->getGroupId();
/*
* If netBS
*
if(!is_null($groupId))
$node->setGroup($this->em->getRepository('AppBundle:Groupe')->find($groupId));
foreach($node->getUsersId() as $id)
$node->addUser($this->em->getRepository('InterneSecurityBundle:User')->find($id));
*/
/*
* If colibri
*/
foreach ($node->getUsersId() as $id) {
$user = $eventArgs->getDocumentManager()->getRepository('ColibriUserBundle:User')->find($id);
$node->addUser($user);
}
}
}
示例5: preRemove
public function preRemove(LifecycleEventArgs $eventArgs)
{
$document = $eventArgs->getDocument();
if ($document instanceof $this->objectClass) {
$this->scheduleForRemoval($document, $eventArgs->getDocumentManager());
}
}
示例6: preUpdate
/**
* @param LifecycleEventArgs $event
*/
public function preUpdate(LifecycleEventArgs $event)
{
if (!($object = $event->getDocument()) instanceof ContentInterface || in_array($object->getContentId(), $this->contentManaged)) {
return;
}
$this->contentManaged[] = $object->getContentId();
$contents = $this->getContentRepository()->findByContentId($object->getContentId());
$contentType = $this->getContentTypeRepository()->findOneByContentTypeIdInLastVersion($object->getContentType());
/** @var ContentInterface $content */
foreach ($contents as $content) {
if ($content != $object) {
foreach ($this->immutableData as $immutableData) {
$getter = $this->generateGetter($immutableData, $object);
$setter = 'set' . ucfirst($immutableData);
$content->{$setter}($object->{$getter}());
}
/** @var FieldTypeInterface $field */
foreach ($contentType->getFields() as $field) {
if (!$field->isTranslatable()) {
$contentAttribute = $this->getContentAttribute($content, $field->getFieldId());
$contentAttribute->setValue($object->getAttributeByName($field->getFieldId())->getValue());
}
}
}
$event->getDocumentManager()->flush($content);
}
}
开发者ID:open-orchestra,项目名称:open-orchestra-model-bundle,代码行数:30,代码来源:UpdateNonTranslatableContentFieldsListener.php
示例7: preThaw
/**
*
* @param \Doctrine\ODM\MongoDB\Event\OnFlushEventArgs $eventArgs
*/
public function preThaw(LifecycleEventArgs $eventArgs)
{
if (!($accessController = $this->getAccessController())) {
//Access control is not enabled
return;
}
$document = $eventArgs->getDocument();
if (!$accessController->isAllowed(Actions::thaw, null, $document)->getIsAllowed()) {
//stop thaw
$this->getFreezer()->freeze($document);
$eventManager = $eventArgs->getDocumentManager()->getEventManager();
if ($eventManager->hasListeners(Events::thawDenied)) {
$eventManager->dispatchEvent(Events::thawDenied, new AccessControlEventArgs($document, $eventArgs->getDocumentManager(), Actions::thaw));
}
}
}
示例8: preUpdate
public function preUpdate(LifecycleEventArgs $eventArgs)
{
$document = $eventArgs->getDocument();
if (!$document instanceof SearchableEntityInterface) {
return;
}
$dm = $eventArgs->getDocumentManager();
$uow = $dm->getUnitOfWork();
$changeset = $uow->getDocumentChangeset($document);
$filter = $this->getKeywordsFilter();
$keywords = array();
$mustUpdate = false;
foreach ($document->getSearchableProperties() as $name) {
if (isset($changeset[$name])) {
$mustUpdate = true;
break;
}
}
if (!$mustUpdate) {
return;
}
$keywords = $filter->filter($document);
$document->setKeywords($keywords);
$uow->recomputeSingleDocumentChangeSet($dm->getClassMetadata(get_class($document)), $document);
}
示例9: postLoad
public function postLoad(\Doctrine\ODM\MongoDB\Event\LifecycleEventArgs $eventArgs)
{
if (!$eventArgs->getDocument() instanceof \Bpi\ApiBundle\Domain\Entity\Author) {
return;
}
$author = $eventArgs->getDocument();
$author->loadAgency($eventArgs->getDocumentManager()->getRepository('BpiApiBundle:Aggregate\\Agency'));
}
示例10: recomputeChangeset
/**
*
* @param \Doctrine\ODM\MongoDB\Event\LifecycleEventArgs $eventArgs
*/
protected function recomputeChangeset(LifecycleEventArgs $eventArgs)
{
$documentManager = $eventArgs->getDocumentManager();
$document = $eventArgs->getDocument();
$unitOfWork = $documentManager->getUnitOfWork();
$metadata = $documentManager->getClassMetadata(get_class($document));
$unitOfWork->recomputeSingleDocumentChangeSet($metadata, $document);
}
示例11: postPersist
/**
* Populates identities for stored references
*
* @param LifecycleEventArgs $args
*/
public function postPersist(LifecycleEventArgs $args)
{
$object = $args->getDocument();
if (($name = $this->referenceRepository->getReferenceName($object)) !== false) {
$identity = $args->getDocumentManager()->getUnitOfWork()->getDocumentIdentifier($object);
$this->referenceRepository->setReferenceIdentity($name, $identity);
}
}
示例12: postPersist
public function postPersist(LifecycleEventArgs $eventArgs)
{
$document = $eventArgs->getDocument();
$uow = $eventArgs->getDocumentManager()->getUnitOfWork();
$idmap = $uow->getIdentityMap();
if ($document instanceof User\Document\User) {
var_dump($idmap);
}
}
示例13:
function it_throws_exception_when_entity_collection_field_has_no_target_entity(LifecycleEventArgs $args, ValueStub $document, DocumentManager $dm, ClassMetadata $documentMetadata)
{
$args->getDocument()->willReturn($document);
$args->getDocumentManager()->willReturn($dm);
$dm->getClassMetadata(Argument::any())->willReturn($documentMetadata);
$documentMetadata->fieldMappings = ['foo' => ['type' => 'text'], 'bar' => ['type' => 'entity']];
$documentMetadata->name = 'Acme/Document';
$this->shouldThrow(new \RuntimeException('Please provide the "targetEntity" of the Acme/Document::$bar field mapping'))->duringPostLoad($args);
}
示例14: postLoad
public function postLoad(LifecycleEventArgs $args)
{
$dm = $args->getDocumentManager();
$document = $args->getDocument();
if (!$document instanceof GH1152Child) {
return;
}
$document->parentAssociation = $dm->getUnitOfWork()->getParentAssociation($document);
}
示例15: postPersist
/**
* Dans le cas d'un document nouvellement enregistré, je vais renommer le nom du fichier uploadé si besoin
* @param LifecycleEventArgs $eventArgs [description]
* @return [type] [description]
*/
public function postPersist(LifecycleEventArgs $eventArgs)
{
$document = $eventArgs->getDocument();
$dm = $eventArgs->getDocumentManager();
$is_uploadable = $this->metadata_reader->isUploadable(ClassUtils::getClass($document));
if ($is_uploadable) {
// Récupération des champs uploadable
$fields = $this->metadata_reader->getUploadableFields(ClassUtils::getClass($document));
// Pour chacun de ces champs, je récupère le mapping associé pour vérifier le namer et le nom du champ
foreach ($fields as $field) {
$mapping = $this->mapping_factory->fromField($document, $field['propertyName']);
if ($mapping->getNamer() instanceof \Redking\Bundle\UploadBundle\Naming\ObjectNamer) {
$filename = $mapping->getFileName($document);
$file = $mapping->getFile($document);
// Si il y a bien un fichier, je vérifie son nom
if (!is_null($filename) && $file instanceof File) {
$filename_normalized = $mapping->getNamer()->getNormalizedName($document, $filename);
// Si les deux noms ne correspondent pas, je renomme et réassigne
if (strcmp($filename, $filename_normalized) !== 0) {
$base_directory = $mapping->hasDirectoryNamer() ? $mapping->getDirectoryNamer()->directoryName($document, $mapping) . '/' : '';
$adapter = $this->filesystem_map->get($mapping->getUploadDestination())->getAdapter();
$adapter->rename($base_directory . $filename, $base_directory . $filename_normalized);
if ($adapter->exists($base_directory . $filename)) {
$adapter->delete($base_directory . $filename);
}
// On vérifie si il y a des fichiers resized à renommer
foreach ($this->resizes as $suffix => $resize_conf) {
$resize_filename = $base_directory . ResizedNamer::getName($filename, $suffix);
$resize_filename_normalized = $base_directory . ResizedNamer::getName($filename_normalized, $suffix);
if ($adapter->exists($resize_filename)) {
$adapter->rename($resize_filename, $resize_filename_normalized);
if ($adapter->exists($resize_filename)) {
$adapter->delete($resize_filename);
}
}
}
$mapping->setFileName($document, $filename_normalized);
// Ré-enregistrement
$class = $dm->getClassMetadata(get_class($document));
$dm->getUnitOfWork()->recomputeSingleDocumentChangeSet($class, $document);
}
}
}
// Traitement du répertoire basé sur l'id pour voir si le fichier est bien dedans
$directory_namer = $mapping->getDirectoryNamer();
if (!is_null($directory_namer) && $directory_namer instanceof BaseDirectoryIdNamer) {
$adapter = $this->filesystem_map->get($mapping->getUploadDestination())->getAdapter();
$filename = $mapping->getFileName($document);
$good_path = ltrim($directory_namer->directoryName($document, $mapping) . '/' . $filename, '/');
$bad_path = ltrim($directory_namer->directoryNameError($document, $mapping) . '/' . $filename, '/');
if (!$adapter->exists($good_path) && $adapter->exists($bad_path)) {
$success = $adapter->rename($bad_path, $good_path);
}
}
}
}
}