예제 #1
0
 /**
  * Publish the current object revision
  *
  * @return ObjectInterface Object
  */
 public function publish()
 {
     // If this is an unpublished draft
     if ($this->isDraft() & !$this->hasBeenPublished()) {
         $this->setPublishedState();
         $this->latestRevision = $this->latestRevision->setDraft(false);
         $this->updateLocator();
     }
     return $this;
 }
예제 #2
0
파일: Locator.php 프로젝트: apparat/object
 /**
  * Serialize as relative URL
  *
  * @param bool $canonical Canonical URL
  * @return string Relative URL
  */
 public function toUrl($canonical = false)
 {
     $locator = [];
     $datePrecision = intval(getenv('OBJECT_DATE_PRECISION'));
     // Add the creation date
     foreach (array_slice(array_keys(self::$datePattern), 0, $datePrecision) as $dateFormat) {
         $locator[] = $this->creationDate->format($dateFormat);
     }
     // Add the object ID and type
     $uid = $this->uid->getId();
     $locator[] = ($this->hidden ? '.' : '') . $uid;
     // If not only the canonical URL should be returned
     if (!$canonical) {
         $locator[count($locator) - 1] .= '-' . $this->type->getType();
         // Add the ID, draft mode and revision
         $locator[] = rtrim(($this->revision->isDraft() ? '.' : '') . $uid . '-' . $this->revision->getRevision(), '-');
     }
     return '/' . implode('/', $locator);
 }
예제 #3
0
 /**
  * Return the property values as array
  *
  * @param bool $serialize Serialize property objects
  * @return array Property values
  */
 public function toArray($serialize = true)
 {
     return $this->toSerializedArray($serialize, [self::PROPERTY_ID => $this->uid->getId(), self::PROPERTY_TYPE => $this->type->getType(), self::PROPERTY_REVISION => $this->revision->getRevision(), self::PROPERTY_CREATED => $this->created, self::PROPERTY_MODIFIED => $this->modified, self::PROPERTY_PUBLISHED => $this->published, self::PROPERTY_DELETED => $this->deleted, self::PROPERTY_LOCATION => $this->location->toArray($serialize), self::PROPERTY_LANGUAGE => $this->language]);
 }
예제 #4
0
파일: Manager.php 프로젝트: apparat/object
 /**
  * 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());
 }
예제 #5
0
 /**
  * Return whether the current revision is valid
  *
  * @return bool Current revision is valid
  */
 public function valid()
 {
     /** @var AbstractObject $that */
     $that =& $this;
     return $this->nextRevision->getRevision() <= count($that);
 }
예제 #6
0
파일: Selector.php 프로젝트: apparat/object
 /**
  * Validate the revision component
  *
  * @param int|NULL $revision Revision
  * @throws InvalidArgumentException If the revision component isn't valid
  */
 protected function validateRevisionComponent($revision)
 {
     // If the revision component isn't valid
     if (!Revision::isValidRevision($revision) && $revision !== self::WILDCARD) {
         throw new InvalidArgumentException(sprintf('Invalid repository selector revision component "%s"', $revision), InvalidArgumentException::INVALID_REPOSITORY_SELECTOR_COMPONENT, null, 'revision');
     }
     $this->revision = $revision;
 }
예제 #7
0
 /**
  * Publish an object in the repository
  *
  * @param ObjectInterface $object
  */
 protected function publishObject(ObjectInterface $object)
 {
     $objectRepoLocator = $object->getRepositoryLocator();
     // If the object had been persisted as a draft: Remove the draft resource
     $objectDraftLocator = $objectRepoLocator->setRevision($object->getRevision()->setDraft(true));
     $absObjectDraftPath = $this->getAbsoluteResourcePath($objectDraftLocator);
     if (@file_exists($absObjectDraftPath)) {
         unlink($absObjectDraftPath);
     }
     // If it's not the first object revision: Rotate the previous revision resource
     $objectRevisionNumber = $object->getRevision()->getRevision();
     if ($objectRevisionNumber > 1) {
         // Build the "current" object repository locator
         $currentRevision = Revision::current();
         $curObjectResPath = $this->getAbsoluteResourcePath($objectRepoLocator->setRevision($currentRevision));
         // Build the previous object repository locator
         /** @var Revision $previousRevision */
         $previousRevision = Kernel::create(Revision::class, [$objectRevisionNumber - 1]);
         $prevObjectResPath = $this->getAbsoluteResourcePath($objectRepoLocator->setRevision($previousRevision));
         // Rotate the previous revision's resource path
         if (file_exists($curObjectResPath)) {
             rename($curObjectResPath, $prevObjectResPath);
         }
     }
 }
예제 #8
0
파일: Revision.php 프로젝트: apparat/object
 /**
  * Compare this revision to a given one
  *
  * @param Revision $revision Comparison revision
  * @return bool This revision equals the given one
  */
 public function equals(Revision $revision)
 {
     return $this->revision == $revision->getRevision() && $this->draft == $revision->isDraft();
 }