예제 #1
0
 /**
  * Persist the current object revision
  *
  * @return ObjectInterface Object
  */
 public function persist()
 {
     // If this is not the latest revision
     if ($this->getRevision()->getRevision() !== $this->latestRevision->getRevision()) {
         throw new RuntimeException(sprintf('Cannot persist revision %s/%s', $this->getRevision()->getRevision(), $this->latestRevision->getRevision()), RuntimeException::CANNOT_PERSIST_EARLIER_REVISION);
     }
     // Update the object repository
     $this->locator->getRepository()->updateObject($this);
     // Reset to a clean state
     $this->resetState();
     $this->latestRevision = $this->getRevision();
     $this->updateLocator();
     // Post persistence hook
     $this->postPersist();
     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
 /**
  * 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);
 }
예제 #5
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();
 }