Ejemplo n.º 1
0
 /**
  * Generate a string
  *
  * @param $schema
  * @param $required
  * @param null $property
  * @return null|string
  * @throws InvalidArgumentException
  */
 private function handleString($schema, $required, $property = null)
 {
     if (!$this->shouldHandle($required)) {
         return null;
     }
     $enum = $this->getEnum($schema);
     if (null !== $enum) {
         return $enum;
     }
     if ($this->provider->hasProperty($schema, 'pattern')) {
         $pattern = $this->provider->getProperty($schema, 'pattern');
         return $this->generator->regexify($pattern);
     }
     if ($this->hasFormatter($schema, $property)) {
         $formatter = $this->getFormatter($schema, $property);
         return $formatter();
     }
     $maxLength = $this->provider->getProperty($schema, 'maxLength', $this->config->getMaxLength());
     $minLength = $this->provider->getProperty($schema, 'minLength', $this->config->getMinLength());
     $text = $this->generator->text($maxLength);
     while (strlen($text) < $minLength) {
         $text .= $this->generator->randomLetter;
     }
     return $text;
 }