Example #1
0
 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());
 }
Example #2
0
 /**
  * @return Psc\CMS\Component
  */
 public function inferComponent(Type $type)
 {
     if (array_key_exists($type->getName(), $this->explicitMappings)) {
         $component = $this->createComponent($this->explicitMappings[$type->getName()]);
     } elseif ($type instanceof MappedComponentType) {
         $component = $type->getMappedComponent($this);
     } else {
         throw NoComponentFoundException::build("Zum Type '%s' konnte keine Komponente ermittelt werden. Das einfachste ist im Type \\Webforge\\Types\\MappedComponentType zu implementieren.", $type->getName())->set('type', $type)->end();
     }
     $component->setType($type);
     $this->manager->dispatchEvent(self::EVENT_COMPONENT_MAPPED, compact('component', 'type'), $this);
     return $component;
 }
Example #3
0
 public function exportType(Type $type)
 {
     if (array_key_exists($tn = $type->getName(), $this->casts)) {
         return $this->casts[$tn];
     }
     // Explicit Interface in der Type-Klasse selbst
     if ($type instanceof DoctrineExportableType) {
         // keinen dynamischen cache einbauen für z.b. DCEnumType,
         // wir machen den ganz aus, denn der performance overhead sollte minimal sein
         return $type->getDoctrineExportType();
     }
     throw new TypeExportException(sprintf("Es konnte kein DoctrineExportType für: '%s' gefunden werden. Dieser Typ sollte \\Webfoge\\Types\\DoctrineExportableType implementieren.", $tn));
     // YAGNI?
 }
Example #4
0
 protected function assertDocType($docType, WebforgeType $type)
 {
     $msg = 'DokumentationsType des Type ' . $type . ' ist nicht korrekt';
     $this->assertEquals($docType, $type->getName(WebforgeType::CONTEXT_DOCBLOCK), $msg);
     $this->assertEquals($docType, $type->getDocType(), $msg);
 }
Example #5
0
 /**
  *
  * @param integer $num 1-basiserend
  * @param string $context Class::Method()|Method()|something parseable
  * @param mixed $actual
  * @param Psc\Data\Type\Type $expected
  * @return InvalidArgumentException
  */
 public static function invalidArgument($num, $context, $actual, Type $expected)
 {
     return new InvalidArgumentException(sprintf('Argument %d passed to %s must be a %s, %s given', $num, $context, $expected->getName(Type::CONTEXT_DEBUG), Code::varInfo($actual)));
 }