Exemplo n.º 1
0
 /**
  * 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));
 }
 /**
  * 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)
 {
     // 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);
 }
 /**
  * If there is already a document for the node registered, use that.
  *
  * @param HydrateEvent $event
  */
 public function handleDocumentFromRegistry(HydrateEvent $event)
 {
     if ($event->hasDocument()) {
         return;
     }
     $node = $event->getNode();
     if (!$this->documentRegistry->hasNode($node)) {
         return;
     }
     $document = $this->documentRegistry->getDocumentForNode($node);
     $event->setDocument($document);
 }
 /**
  * @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));
 }
Exemplo n.º 6
0
 /**
  * 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();
     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);
 }