/** * Create a new proxy object from the given document for * the given target node. * * TODO: We only pass the document here in order to correctly evaluate its locale * later. I wonder if it necessary. * * @param object $fromDocument * @param NodeInterface $targetNode * * @return \ProxyManager\Proxy\GhostObjectInterface */ public function createProxyForNode($fromDocument, NodeInterface $targetNode) { $eventDispatcher = $this->dispatcher; $registry = $this->registry; $targetMetadata = $this->metadataFactory->getMetadataForPhpcrNode($targetNode); // if node is already registered then just return the registered document if ($this->registry->hasNode($targetNode)) { $document = $this->registry->getDocumentForNode($targetNode); $locale = $registry->getOriginalLocaleForDocument($fromDocument); // If the parent is not loaded in the correct locale, reload it in the correct locale. if ($registry->getOriginalLocaleForDocument($document) !== $locale) { $hydrateEvent = new HydrateEvent($targetNode, $locale); $hydrateEvent->setDocument($document); $this->dispatcher->dispatch(Events::HYDRATE, $hydrateEvent); } return $document; } $initializer = function (LazyLoadingInterface $document, $method, array $parameters, &$initializer) use($fromDocument, $targetNode, $eventDispatcher, $registry) { $locale = $registry->getOriginalLocaleForDocument($fromDocument); $hydrateEvent = new HydrateEvent($targetNode, $locale); $hydrateEvent->setDocument($document); $eventDispatcher->dispatch(Events::HYDRATE, $hydrateEvent); $initializer = null; }; $proxy = $this->proxyFactory->createProxy($targetMetadata->getClass(), $initializer); $locale = $registry->getOriginalLocaleForDocument($fromDocument); $this->registry->registerDocument($proxy, $targetNode, $locale); return $proxy; }
/** * Writes the history status of the node to the document. * * @param HydrateEvent $event */ public function handleHydrate(HydrateEvent $event) { $document = $event->getDocument(); if (!$document instanceof RouteBehavior) { return; } $document->setHistory($event->getNode()->getPropertyValue(self::NODE_HISTORY_FIELD)); }
/** * @param HydrateEvent $event */ public function handleHydrate(HydrateEvent $event) { $document = $event->getDocument(); if (!$document instanceof PathBehavior) { return; } $event->getAccessor()->set('path', $this->documentInspector->getPath($document)); }
/** * @param HydrateEvent $event */ public function handleHydrate(HydrateEvent $event) { $document = $event->getDocument(); if (!$document instanceof ChildrenBehavior) { return; } $accessor = $event->getAccessor(); $accessor->set('children', $this->proxyFactory->createChildrenCollection($document, $event->getOptions())); }
/** * @param HydrateEvent $event */ public function handleHydrate(HydrateEvent $event) { // don't need to instantiate the document if it is already existing. if ($event->hasDocument()) { return; } $node = $event->getNode(); $document = $this->getDocumentFromNode($node); $event->setDocument($document); }
public function setUp() { $this->persistEvent = $this->prophesize(PersistEvent::class); $this->hydrateEvent = $this->prophesize(HydrateEvent::class); $this->notImplementing = new \stdClass(); $this->encoder = $this->prophesize(PropertyEncoder::class); $this->node = $this->prophesize(NodeInterface::class); $this->accessor = $this->prophesize(DocumentAccessor::class); $this->persistEvent->getNode()->willReturn($this->node); $this->persistEvent->getAccessor()->willReturn($this->accessor); $this->hydrateEvent->getAccessor()->willReturn($this->accessor); }
/** * @param HydrateEvent $event */ public function handleHydrate(HydrateEvent $event) { $document = $event->getDocument(); if (!$document instanceof TimestampBehavior) { return; } $node = $event->getNode(); $locale = $event->getLocale(); $accessor = $event->getAccessor(); $accessor->set(self::CREATED, $node->getPropertyValueWithDefault($v = $this->encoder->localizedSystemName(self::CREATED, $locale), null)); $accessor->set(self::CHANGED, $node->getPropertyValueWithDefault($this->encoder->localizedSystemName(self::CHANGED, $locale), null)); }
/** * Adds the security information to the hydrated object. * * @param HydrateEvent $event */ public function handleHydrate(HydrateEvent $event) { $document = $event->getDocument(); $node = $event->getNode(); if (!$this->supports($document)) { return; } $permissions = []; foreach ($node->getProperties('sec:*') as $property) { /** @var PropertyInterface $property */ $roleId = substr($property->getName(), 9); // remove the "sec:role-" prefix $permissions[$roleId] = $property->getValue(); } $document->setPermissions($permissions); }
/** * @param HydrateEvent $event */ public function handleHydrate(HydrateEvent $event) { $document = $event->getDocument(); // we currently only support fallback on StructureBehavior implementors // because we use the template key to determine localization status if (!$document instanceof StructureBehavior) { return; } $locale = $event->getLocale(); if (!$locale || false === $event->getOption('load_ghost_content', true)) { return; } // change locale of document of ghost content should be loaded $newLocale = $this->getAvailableLocalization($document, $locale); $event->setLocale($newLocale); $document->setLocale($newLocale); }
/** * It should not register documents on the HYDRATE event when there is already a document. */ public function testHandleRegisterHydrateAlreadyExisting() { $this->hydrateEvent->getDocument()->willReturn($this->document); $this->hydrateEvent->getNode()->willReturn($this->node->reveal()); $this->hydrateEvent->getLocale()->willReturn('fr'); $this->registry->hasDocument($this->document)->willReturn(true); $this->registry->registerDocument($this->document, $this->node->reveal(), 'fr')->shouldNotBeCalled(); $this->registry->updateLocale($this->document, 'fr')->shouldBeCalled(); $this->subscriber->handleHydrate($this->hydrateEvent->reveal()); }
/** * @param HydrateEvent $event */ public function handleHydrate(HydrateEvent $event) { $document = $event->getDocument(); // we currently only support fallback on StructureBehavior implementors // because we use the template key to determine localization status if (!$document instanceof StructureBehavior) { return; } $locale = $event->getLocale(); if (!$locale) { return; } $newLocale = $this->getAvailableLocalization($document, $locale); $event->setLocale($newLocale); if ($newLocale === $locale) { return; } if ($event->getOption('load_ghost_content', true) === true) { $this->documentRegistry->updateLocale($document, $newLocale, $locale); return; } $this->documentRegistry->updateLocale($document, $locale, $locale); }
/** * When the hydrate request has finished, mark the document has hydrated. * This should be the last event listener called. * * @param HydrateEvent $event */ public function handleEndHydrate(HydrateEvent $event) { $this->documentRegistry->markDocumentAsHydrated($event->getDocument()); }
/** * Determines if the given document is supported by this subscriber. * * @param HydrateEvent|PublishEvent|PersistEvent $event * * @return bool */ private function supports($event) { return $event->getLocale() && $event->getDocument() instanceof WorkflowStageBehavior; }
/** * @param RefreshEvent $event */ public function handleRefresh(RefreshEvent $event) { $document = $event->getDocument(); $node = $this->documentRegistry->getNodeForDocument($document); $locale = $this->documentRegistry->getLocaleForDocument($document); // revert/reload the node to the persisted state $node->revert(); // rehydrate the document $hydrateEvent = new HydrateEvent($node, $locale); $hydrateEvent->setDocument($document); $this->eventDispatcher->dispatch(Events::HYDRATE, $hydrateEvent); }
/** * Set routes to custom-url. * * @param HydrateEvent $event */ public function handleHydrate(HydrateEvent $event) { $document = $event->getDocument(); if (!$document instanceof CustomUrlBehavior) { return; } $webspaceKey = $this->inspector->getWebspace($document); $document->setRoutes($this->findReferrer($document, $webspaceKey)); }
/** * @param HydrateEvent $event */ public function handleHydrate(HydrateEvent $event) { $document = $event->getDocument(); if (!$document instanceof ParentBehavior) { return; } $node = $event->getNode(); if ($node->getDepth() == 0) { throw new \RuntimeException(sprintf('Cannot apply parent behavior to root node "%s" with type "%s" for document of class "%s"', $node->getPath(), $node->getPrimaryNodeType()->getName(), get_class($document))); } $this->mapParent($document, $node); }