protected function createEntity() { $fields = $this->fields->toArray(); // @TODO hier könne es sein dass unset sehr lahm ist. man könnte auch array_intersect oder sowas nehmen oder im constructor foreach was anders machen etc // zuerst die ausm constructor $constructParams = array(); foreach ($this->getConstructorFields() as $field) { $constructParams[] = $this->fields->get($field); unset($fields[$field]); } // construct try { $entity = $this->getGClass()->newInstance($constructParams); } catch (\ErrorException $e) { throw new \Psc\Exception(sprintf("Fehler beim Erstellen des Entities: '%s'. Es wurden %d (%s) Parameter an den Constructor übergeben. Fehler: %s", $this->entityMeta->getEntityName(), count($constructParams), Code::varInfo($constructParams), $e->getMessage()), 0, $e); } // restliche Felder (oben haben wir alle aus dem constructor unsetted) foreach ($fields as $field => $value) { if (!$this->entityMeta->getPropertyMeta($field)->isAutogeneratedValue()) { $entity->callSetter($field, $value); } } return $entity; }
public function processSet(Set $set) { // weil der setter auch enabled sein soll, geht dies hier nicht im konstruktor zu überprüfen if (!$this->entity instanceof \Psc\Doctrine\Entity && !$this->entity instanceof \Psc\Doctrine\Object) { throw new \Psc\Exception('Entity ist kein bekanntes Interface'); } foreach ($set->getMeta()->getTypes() as $field => $type) { $value = $set->get($field); if (isset($this->onFieldTodos[$field])) { call_user_func($this->onFieldTodos[$field], $this->entity, $field, $value, $type); } elseif ($type instanceof PersistentCollectionType) { $this->processCollectionField($this->entity, $field, $value, $type); } else { $this->logf("Setze '%s' auf %s", $field, Code::varInfo($value)); $this->entity->callSetter($field, $value); } } return $this; }
/** * @depends testConstruct */ public function testGetWithMetaButEmptyReturnsNULL(Set $set) { $set->getMeta()->setFieldType('withMetaButEmptyLabel', new StringType()); $this->assertSame(NULL, $set->get('withMetaButEmptyLabel')); }