public function validate($data)
 {
     if (empty($data)) {
         $e = new EmptyDataException();
         $e->setDefaultValue(array());
         throw $e;
     }
     $data = json_decode($data, true);
     if (count($data) == 0) {
         $e = new EmptyDataException();
         $e->setDefaultValue(array());
         throw $e;
     }
     $rep = $this->em->getRepository($this->entityName);
     $collection = $rep->findAllByIds($data, $this->idName);
     // überspringt dies fehlende Ids?
     // sortieren nach der Data List (da findAllByIds das nicht tut, und das ist auch gut so)
     $getter = \Psc\Code\Code::castGetter($this->idName);
     $keys = array_flip($data);
     usort($collection, function ($entityA, $entityB) use($keys, $getter) {
         $keyA = $keys[$getter($entityA)];
         $keyB = $keys[$getter($entityB)];
         if ($keyA === $keyB) {
             return 0;
         }
         return $keyA > $keyB ? 1 : -1;
     });
     if (count($collection) == count($data)) {
         return $collection;
     } else {
         throw new \Psc\Exception('Unexpected: Es wurden: ' . count($collection) . ' IDs hydriert, aber ' . count($data) . ' IDs angegeben.');
     }
 }
Beispiel #2
0
 public function validate($data)
 {
     $e = new EmptyDataException();
     $e->setDefaultValue(array());
     if ($data === NULL) {
         throw $e;
     }
     if (trim($data) == ',') {
         throw $e;
     }
     $cb = new Callback($this->tagsClass, 'toCollection');
     return $cb->call(array($data));
 }