public function generateData(Type $type) { switch ($type->getName()) { case 'String': return $this->generateString(15); case 'Integer': return mt_rand(0, 99999) * (mt_rand(0, 1) === 0 ? -1 : 1); // negativ, positiv, 0-xxxx // negativ, positiv, 0-xxxx case 'Array': // wir füllen den array mit random strings, oder whatever, numerische schlüssel $array = array(); if ($type->isTyped()) { for ($i = 1; $i <= 15; $i++) { $array[] = $this->generateData($type->getType()); } } else { $randomTypes = array(new StringType(), new IntegerType(), new BooleanType()); for ($i = 1; $i <= 15; $i++) { $array[] = $this->generateDataRandomType($randomTypes); } } return $array; case 'Boolean': return mt_rand(0, 1) === 1; } throw new \Psc\Code\NotImplementedException('Kein switch für randomData für: ' . $type->getName()); }
public function walkListValue(array $list, Type $type) { $walkedList = array(); foreach ($list as $value) { $walkedList[] = $this->walkPHPValue($value, $type instanceof EnclosingType && $type->isTyped() ? $type->getType() : NULL, 'list'); } return $this->codeWriter->writeList($walkedList, $type); }
public function walkCollection($collection, Type $collectionType = NULL) { $walkedItems = array(); /* 1. Fall: wir kennen den Inhalt des Arrays (er hat einen Typ) */ if (isset($collectionType) && $collectionType->isTyped()) { $itemType = $collectionType->getType(); foreach ($collection->toArray() as $key => $item) { $walkedItems[$key] = $this->walkCollectionItem($item, $itemType, $key, $collection, $collectionType); } } else { /* 2. Fall wir kennen den Inhalt nicht */ if (!isset($collectionType)) { $collectionType = $this->inferType($collection); } foreach ($collection->toArray() as $key => $item) { $itemType = $this->inferCollectionItemType($item, $key, $collection, $collectionType); // damit walkArrayEntry hier volle power hat rufen wir direkt mit $entry auf nicht mit $this->walk($entry) $walkedItems[$key] = $this->walkCollectionItem($item, $itemType, $key, $collection, $collectionType); } } return $this->decorateCollection($walkedItems, $collectionType); }