Example #1
0
 /**
  * Determine and validate the object class name from its type
  *
  * @param Type $type Object type
  * @return string Object class name
  * @throws InvalidArgumentException If the object type is invalid
  */
 protected static function objectClassFromType(Type $type)
 {
     // If the object type is invalid
     $objectType = $type->getType();
     $objectClass = 'Apparat\\Object\\Application\\Model\\Object\\' . ucfirst($objectType);
     if (!TypeService::isEnabled($objectType) || !class_exists($objectClass)) {
         throw new InvalidArgumentException(sprintf('Invalid object type "%s"', $objectType), InvalidArgumentException::INVALID_OBJECT_TYPE);
     }
     return $objectClass;
 }
Example #2
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 #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]);
 }