示例#1
0
 /**
  * Returns an array of duplicate keys.
  *
  * @param Collection $data
  * @param string $table
  * @param string $key
  * @return array
  */
 protected function intersect(Collection $data, $table, $key)
 {
     $ids = $data->fetch($key)->toArray();
     return $this->table($table)->whereIn($key, $ids)->lists($key);
 }
示例#2
0
 /**
  * {@inheritDoc}
  *
  * @todo Attaching keys to values requires more work to be robust, including determining what is actually required for expects
  */
 public function transform(Collection $data, ValidatorInterface $validator = null)
 {
     $output = new Collection();
     // Extract keys
     $keys = array_keys($this->expects());
     // Check to see if we should validate each record
     $shouldValidate = $this->shouldValidate($validator);
     foreach ($data as $record) {
         // Attach the keys to the values
         $record = array_combine($keys, $record);
         // For now: throw exception if we are validating but the record doesn't validate
         if ($shouldValidate && !$this->validate($record, $validator)) {
             throw new TransformerException('A record failed validation');
         }
         $output->push($this->process($record));
     }
     return $output;
 }