Esempio n. 1
0
 /**
  * Return the object repository locator
  *
  * @return RepositoryLocatorInterface Object repository locator
  */
 public function getRepositoryLocator()
 {
     // If the object has already been instantiated
     if ($this->object instanceof ObjectInterface) {
         return $this->object->getRepositoryLocator();
     }
     return $this->getUrl()->getLocator();
 }
Esempio n. 2
0
 /**
  * Create and return a FrontMark resource instance from an object
  *
  * @param ObjectInterface $object Object
  * @return ResourceInterface Object resource
  */
 public static function createFromObject(ObjectInterface $object)
 {
     /** @var ResourceInterface $resource */
     $resource = Kernel::create(Resource::class, [null]);
     $resource->setPropertyData($object->getPropertyData());
     $resource->setPayload($object->getPayload());
     return $resource;
 }
Esempio n. 3
0
 /**
  * Create and return an apparat object decorator
  *
  * @param ObjectInterface $object Object
  * @return ApparatObjectInterface Apparat object
  */
 public static function create(ObjectInterface $object)
 {
     $objectType = $object->getObjectType()->getType();
     // If the object type doesn't map to known apparat object class
     if (!array_key_exists($objectType, static::$typeClasses) || !static::$typeClasses[$objectType]) {
         throw new PortsInvalidArgumentException(sprintf('Unknown apparat object type "%s"', $objectType), PortsInvalidArgumentException::UNKNOWN_APPARAT_OBJECT_TYPE);
     }
     /** @var ApparatObjectInterface $apparatObject */
     $apparatObject = Kernel::create(self::$typeClasses[$objectType], [$object]);
     return $apparatObject;
 }
Esempio n. 4
0
 /**
  * Delete and object from the repository
  *
  * @param ObjectInterface $object Object
  * @return boolean Success
  */
 public function deleteObject(ObjectInterface $object)
 {
     $this->adapterStrategy->persistObject($object->delete());
     return true;
 }
Esempio n. 5
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);
         }
     }
 }