/** * 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; }
/** * Undelete all revisions of an object * * @param ObjectInterface $object Object * @return ObjectInterface Object */ protected function undeleteObject(ObjectInterface $object) { // Hide object directory $objContainerDir = dirname(dirname($this->getAbsoluteResourcePath($object->getRepositoryLocator()))); $objContainerName = $object->getId()->getId() . '-' . $object->getObjectType()->getType(); $objPublicContainer = $objContainerDir . DIRECTORY_SEPARATOR . $objContainerName; $objHiddenContainer = $objContainerDir . DIRECTORY_SEPARATOR . '.' . $objContainerName; if (file_exists($objHiddenContainer) && is_dir($objHiddenContainer) && !rename($objHiddenContainer, $objPublicContainer)) { throw new RuntimeException(sprintf('Cannot unhide object container "%s"', $objContainerName), RuntimeException::CANNOT_UNHIDE_OBJECT_CONTAINER); } // Undelete all object revisions /** @var ObjectInterface $objectRevision */ foreach ($object as $objectRevision) { $this->persistObjectResource($objectRevision->undelete()); } return $this; }