/**
  * 
  * Achtung! nicht bool zurückgeben, stattdessen irgendeine Exception schmeissen
  * 
  * Wird EmptyDataException bei validate() geworfen und ist der Validator mit optional aufgerufen worden, wird keine ValidatorException geworfen
  * 
  * @return $data
  */
 public function validate($data)
 {
     if ($data === NULL) {
         throw EmptyDataException::factory(NULL);
     }
     $repository = $this->dc->getRepository($this->entityMeta->getClass());
     try {
         return $repository->hydrate($data);
     } catch (\Psc\Doctrine\EntityNotFoundException $e) {
         throw EmptyDataException::factory(NULL, $e);
     }
 }
Exemplo n.º 2
0
 public function validate($data)
 {
     if ($data === NULL) {
         throw EmptyDataException::factory(array());
     }
     $data = Code::castArray($data);
     if (count($data) == 0) {
         throw EmptyDataException::factory(array());
     }
     if (count($data) > 0) {
         return $data;
     }
     throw new \Psc\Exception('Konnte nicht validiert werden');
 }
Exemplo n.º 3
0
 /**
  * 
  * Wird EmptyDataException bei validate() geworfen und ist der Validator mit optional aufgerufen worden, wird keine ValidatorException geworfen
  * @return $data
  */
 public function validate($data = NULL)
 {
     if ($data === NULL || $data === array()) {
         throw EmptyDataException::factory(new \Psc\Data\ArrayCollection());
     }
     if (!is_array($data)) {
         throw new \InvalidArgumentException('Parameter ist als Array erwartet. ' . Code::varInfo($data) . ' wurde übergeben');
     }
     $identifierCaster = $this->getIdentifierCaster($this->entityMeta->getIdentifier());
     $repository = $this->dc->getRepository($this->entityMeta->getClass());
     $entities = new ArrayCollection();
     foreach ($data as $key => $identifierString) {
         $identifier = $identifierCaster($identifierString, $key);
         $entities->add($repository->hydrate($identifier));
     }
     return $entities;
 }
Exemplo n.º 4
0
 /**
  *
  * Empty Data ist NULL
  * 
  * @return DateTime
  */
 public function validate($data)
 {
     if (is_integer($data) && $data > 0) {
         return new DateTime($data);
     }
     if ($data === NULL || !is_array($data) || !array_key_exists('date', $data) || $data['date'] == NULL || !$this->timeIsOptional && (!array_key_exists('time', $data) || $data['time'] == NULL)) {
         throw EmptyDataException::factory(NULL);
     }
     $data['time'] = !isset($data['time']) ? NULL : trim($data['time']);
     $dateRule = new DateValidatorRule('d.m.Y');
     $date = $dateRule->validate($data['date']);
     // cooler: time validator rule
     if ($this->timeIsOptional && $data['time'] == NULL) {
         return new DateTime($date);
         // sets time to 00:00
     } else {
         return DateTime::parse('d.m.Y H:i', $date->format('d.m.Y') . ' ' . $data['time']);
     }
 }
Exemplo n.º 5
0
 public function validate($data)
 {
     if ($data === NULL) {
         throw EmptyDataException::factory(0.0);
     }
     if ($data === '') {
         throw EmptyDataException::factory(0.0);
     }
     if (is_string($data)) {
         $float = \Psc\Code\Numbers::parseFloat($data, '.', ',');
     } elseif (is_numeric($data)) {
         $float = (double) $data;
     } else {
         throw new Exception('Parsing von ' . $data . ' war nicht möglich. String|Integer erwartet');
     }
     if (!is_float($float)) {
         throw new Exception('Parsing von ' . $data . ' war nicht möglich');
     }
     if (!$this->zero && $float == 0) {
         throw new Exception('0 ist nicht erlaubt');
     }
     return $float;
 }