예제 #1
0
 public function testConstruct()
 {
     $objectExporter = new ObjectExporter();
     $t = function ($type) {
         return Type::create($type);
     };
     $set = new Set();
     // set implements Walkable
     $set->set('name', 'oids_pages', $t('String'));
     $j1 = new Set();
     $j1->set('name', 'oid', $t('String'));
     $j1->set('referencedColumnName', 'oid', $t('String'));
     $j1->set('onDelete', 'cascade', $t('String'));
     $j2 = new Set();
     $j2->set('name', 'page_id', $t('String'));
     $j2->set('referencedColumnName', 'id', $t('String'));
     $j2->set('onDelete', 'cascade', $t('String'));
     $set->set('joinColumns', array($j1, $j2), new ArrayType(new ObjectType(new GClass('Psc\\Data\\Walkable'))));
     $set->set('inverseJoinColumns', array($j2, $j1), new ArrayType(new ObjectType(new GClass('Psc\\Data\\Walkable'))));
     $this->assertInstanceOf('stdClass', $object = $objectExporter->walkWalkable($set));
     $this->assertInternalType('array', $object->joinColumns);
     $this->assertInternalType('array', $object->inverseJoinColumns);
     $this->assertInstanceOf('stdClass', $object->joinColumns[0]);
     $this->assertInstanceOf('stdClass', $object->inverseJoinColumns[0]);
 }
예제 #2
0
 public function export()
 {
     $meta = new SetMeta();
     foreach ($this->getSetMeta()->getTypes() as $property => $type) {
         // @TODO schön wäre eigentlich auf ebene 2 immer nur "entity:id" zu exportieren
         // das müsste dann alle relevanten daten für die response haben
         if ($type instanceof EntityType || $type instanceof PersistentCollectionType) {
             continue;
         }
         $meta->setFieldType($property, $type);
     }
     $set = new Set(array(), $meta);
     foreach ($set->getKeys() as $property) {
         $set->set($property, $this->callGetter($property));
     }
     $exporter = new ObjectExporter();
     return $exporter->walkWalkable($set);
 }
예제 #3
0
 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;
 }
예제 #4
0
 public function createWalkable()
 {
     $t = function ($type) {
         return Type::create($type);
     };
     $set = new Set();
     // set implements Walkable
     $set->set('name', 'oids_pages', $t('String'));
     $j1 = new Set();
     $j1->set('name', 'oid', $t('String'));
     $j1->set('referencedColumnName', 'oid', $t('String'));
     $j1->set('onDelete', 'cascade', $t('String'));
     $j2 = new Set();
     $j2->set('name', 'page_id', $t('String'));
     $j2->set('referencedColumnName', 'id', $t('String'));
     $j2->set('onDelete', 'cascade', $t('String'));
     $set->set('joinColumns', array($j1, $j2), new ArrayType(new ObjectType(new GClass('Psc\\Data\\Walkable'))));
     $set->set('inverseJoinColumns', array($j2, $j1), new ArrayType(new ObjectType(new GClass('Psc\\Data\\Walkable'))));
     return $set;
 }
예제 #5
0
 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;
 }
예제 #6
0
파일: SetTest.php 프로젝트: pscheit/psc-cms
 /**
  * @depends testConstruct
  */
 public function testGetWithMetaButEmptyReturnsNULL(Set $set)
 {
     $set->getMeta()->setFieldType('withMetaButEmptyLabel', new StringType());
     $this->assertSame(NULL, $set->get('withMetaButEmptyLabel'));
 }