Пример #1
0
 /**
  * Use a specific object revision
  *
  * @param Revision $revision Revision to be used
  * @return ObjectInterface Object
  * @throws OutOfBoundsException If a revision beyond the latest one is requested
  */
 public function useRevision(Revision $revision)
 {
     // If a revision beyond the latest one is requested
     if (!$revision->isCurrent() && $revision->getRevision() > $this->latestRevision->getRevision()) {
         throw new OutOfBoundsException(sprintf('Invalid object revision "%s"', $revision->getRevision()), OutOfBoundsException::INVALID_OBJECT_REVISION);
     }
     // Determine whether the current revision was requested
     $currentRevision = $this->getCurrentRevision();
     $isCurrentRevision = $revision->isCurrent() || $currentRevision->equals($revision);
     if ($isCurrentRevision) {
         $revision = $currentRevision;
     }
     // If the requested revision is not already used
     if (!$this->getRevision()->equals($revision)) {
         /** @var ManagerInterface $objectManager */
         $objectManager = Kernel::create(Service::class)->getObjectManager();
         /** @var Revision $newRevision */
         $newRevision = $isCurrentRevision ? Revision::current() : $revision;
         /** @var RepositoryLocator $newRevisionLocator */
         $newRevisionLocator = $this->locator->setRevision($newRevision);
         // Instantiate the requested revision resource
         $revisionResource = $objectManager->loadObjectResource($newRevisionLocator, SelectorInterface::ALL);
         // Load the revision resource data
         $this->loadRevisionData($revisionResource->getPayload(), $revisionResource->getPropertyData());
         // Update the object locator
         $this->updateLocator();
     }
     return $this;
 }
Пример #2
0
 /**
  * Load a particular object revision from a repository
  *
  * @param RepositoryLocatorInterface $locator Repository object locator
  * @param int $visibility Object visibility
  * @return ObjectInterface Object
  */
 protected function loadObjectRevision(RepositoryLocatorInterface $locator, $visibility = SelectorInterface::ALL)
 {
     // Create the current revision locator
     /** @var RepositoryLocatorInterface $currentLocator */
     $currentLocator = $locator->setRevision(Revision::current());
     // Load the object resource respecting visibility constraints
     $objectResource = $this->loadObjectResource($currentLocator, $visibility);
     // Instantiate the object
     $object = ObjectFactory::createFromResource($currentLocator, $objectResource);
     // Use and return the requested object revision
     return $object->useRevision($locator->getRevision());
 }