/** * Load a particular object revision from a repository * * @param RepositoryLocatorInterface $locator Repository object locator * @param int $visibility Object visibility * @return ObjectInterface Object */ protected function loadObjectRevision(RepositoryLocatorInterface $locator, $visibility = SelectorInterface::ALL) { // Create the current revision locator /** @var RepositoryLocatorInterface $currentLocator */ $currentLocator = $locator->setRevision(Revision::current()); // Load the object resource respecting visibility constraints $objectResource = $this->loadObjectResource($currentLocator, $visibility); // Instantiate the object $object = ObjectFactory::createFromResource($currentLocator, $objectResource); // Use and return the requested object revision return $object->useRevision($locator->getRevision()); }
/** * 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); }