/** * Runs through each storage backend and processes the Storable object * @param StorableInterface $object * @return array * @throws \Exception */ public function process(StorableInterface $object) { if (is_array($this->backends) && count($this->backends) > 0) { $results = []; $identifiers = $object->getStorableBackendIdentifiers(); foreach ($this->backends as $identifier => $backend) { if (in_array($identifier, $identifiers)) { $results[$identifier] = $backend->write($object); } } return $results; } else { throw new StorageProcessingException(sprintf("Tried to process an storable object '%s' with no backends", $object->getStorableIdentifier())); } }
/** * @param \Heystack\Core\DataObjectSchema\SchemaInterface $schema * @param \Heystack\Core\Storage\StorableInterface $object * @return mixed * @throws \Heystack\Core\Exception\ConfigurationException */ protected function writeStoredDataObject(SchemaInterface $schema, StorableInterface $object) { $identifier = $schema->getIdentifier()->getFull(); $saveable = sprintf('Stored%s', $identifier); $storedObject = \Injector::inst()->create($saveable); $writeableData = $object->getStorableData(); foreach ($schema->getFlatStorage() as $key => $value) { $reference = $this->generatorService->isReference($value); if ($reference) { $referenceSchema = $this->schemaService->getSchema($reference); $referenceSchemaIdentifier = $referenceSchema->getIdentifier(); if ($this->hasReferenceDataProvider($referenceSchemaIdentifier)) { $referenceData = $this->getReferenceDataProvider($referenceSchemaIdentifier)->getStorableData(); foreach (array_keys($referenceSchema->getFlatStorage()) as $referenceKey) { if (isset($referenceData['flat'][$referenceKey])) { $storedObject->{$key . $referenceKey} = $referenceData['flat'][$referenceKey]; } else { throw new ConfigurationException("No data found for key: {$key} on identifier: {$reference}"); } } } else { throw new ConfigurationException(sprintf('Reference in flat schema didn\'t have an associated data provider for identifier `%s`' . ' available identifiers are `%s`', $referenceSchema->getIdentifier()->getFull(), implode(', ', array_keys($this->referenceDataProviders)))); } } else { if (array_key_exists($key, $writeableData['flat'])) { $value = $writeableData['flat'][$key]; $storedObject->{$key} = $value; if (!is_null($value) && !is_scalar($value)) { throw new ConfigurationException("Non-scalar value found for key: {$key} on identifier: " . $object->getStorableIdentifier()); } } else { throw new ConfigurationException("No data found for key: {$key} on identifier: " . $object->getStorableIdentifier()); } } } if (isset($writeableData['parent']) && isset($writeableData['flat']['ParentID'])) { $storedObject->ParentID = $writeableData['flat']['ParentID']; } $storedObject->write(); return $storedObject; }