コード例 #1
0
 /**
  * @param \Heystack\Core\DataObjectSchema\SchemaInterface $schema
  * @return void
  */
 public function mergeSchema(SchemaInterface $schema)
 {
     $flat = $schema->getFlatStorage();
     if (is_array($flat)) {
         foreach ($flat as $key => $value) {
             $this->config['flat'][$key] = $value;
         }
     }
     $children = $schema->getChildStorage();
     if (is_array($children)) {
         foreach ($children as $key => $value) {
             $this->config['children'][$key] = $value;
         }
     }
 }
コード例 #2
0
 /**
  * @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;
 }