Example #1
0
 /**
  * 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);
 }
Example #2
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]);
 }