Example #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;
 }
Example #2
0
 /**
  * Test whether an object resource exists
  *
  * @param RepositoryLocatorInterface $locator
  * @return boolean Object resource exists
  */
 public function objectResourceExists(RepositoryLocatorInterface $locator)
 {
     return $locator->getRepository()->getAdapterStrategy()->hasResource($locator->withExtension(getenv('OBJECT_RESOURCE_EXTENSION')));
 }
Example #3
0
 /**
  * Create and return a new object
  *
  * @param RepositoryLocatorInterface $locator Repository object locator
  * @param string $payload Object payload
  * @param array $propertyData Object property data
  * @return ObjectInterface Object
  */
 public static function createFromParams(RepositoryLocatorInterface $locator, $payload = '', array $propertyData = [])
 {
     // Determine the object class
     $objectClass = self::objectClassFromType($locator->getObjectType());
     // Prepare the system properties collection
     $systemPropertyData = empty($propertyData[SystemProperties::COLLECTION]) || !is_array($propertyData[SystemProperties::COLLECTION]) ? [] : $propertyData[SystemProperties::COLLECTION];
     $systemPropertyData[SystemProperties::PROPERTY_ID] = $locator->getId()->getId();
     $systemPropertyData[SystemProperties::PROPERTY_TYPE] = $locator->getObjectType()->getType();
     $systemPropertyData[SystemProperties::PROPERTY_REVISION] = $locator->getRevision()->getRevision();
     $systemPropertyData[SystemProperties::PROPERTY_CREATED] = $systemPropertyData[SystemProperties::PROPERTY_MODIFIED] = $locator->getCreationDate();
     if (empty($systemPropertyData[SystemProperties::PROPERTY_LANGUAGE])) {
         $systemPropertyData[SystemProperties::PROPERTY_LANGUAGE] = getenv('OBJECT_DEFAULT_LANGUAGE');
     }
     $propertyData[SystemProperties::COLLECTION] = $systemPropertyData;
     // Prepare the meta properties collection
     $metaPropertyData = empty($propertyData[MetaProperties::COLLECTION]) || !is_array($propertyData[MetaProperties::COLLECTION]) ? [] : $propertyData[MetaProperties::COLLECTION];
     $metaPropertyData[MetaProperties::PROPERTY_PRIVACY] = getenv('OBJECT_DEFAULT_PRIVACY');
     $propertyData[MetaProperties::COLLECTION] = $metaPropertyData;
     // Instantiate the object
     /** @var ObjectInterface $object */
     $object = Kernel::create($objectClass, [$locator, '', $propertyData]);
     return $object->setPayload($payload);
 }
Example #4
0
 /**
  * Build an absolute repository resource locator
  *
  * @param RepositoryLocatorInterface $repositoryLocator Repository locator
  * @return string Absolute repository resource locator
  */
 public function getAbsoluteResourcePath(RepositoryLocatorInterface $repositoryLocator)
 {
     return $this->root . str_replace('/', DIRECTORY_SEPARATOR, $repositoryLocator->withExtension(getenv('OBJECT_RESOURCE_EXTENSION')));
 }