Example #1
0
 /**
  * Compress a chain down to a single collection.
  *
  * @param bool $preserveKeys
  *
  * @return CollectionInterface
  */
 public function compress($preserveKeys = true)
 {
     $compressed = new Collection();
     foreach ($this->items as $item) {
         $compressed->merge($item, $preserveKeys);
     }
     return $compressed;
 }
Example #2
0
 public function pluck($offset, $count = 0)
 {
     $rows = new Collection();
     foreach ($this->rows as $row) {
         $counter = 0;
         $newRow = [];
         foreach ($row as $index => $cell) {
             if ($index >= $offset && $index < $count + $offset) {
                 $newRow[] = $cell;
             }
             $counter++;
         }
         $rows->push($newRow);
     }
     return $rows;
 }
Example #3
0
 public function read($offset = 0, $count = 0, $delimiter = null)
 {
     if (!$this->handle) {
         throw new FileNotOpenException();
     }
     if (!$delimiter) {
         $delimiter = $this->testDelimiters();
     }
     $rows = new Collection();
     $counter = 0;
     rewind($this->handle);
     while (($data = fgetcsv($this->handle, self::READ_LENGTH, $delimiter, Komma::CSV_ENCLOSURE, Komma::CSV_ESCAPE)) !== false && (!$count || $counter < $count + $offset)) {
         $counter++;
         if ($counter >= $offset) {
             $rows->push($data);
         }
     }
     $this->rows = new Rows($rows);
     return $this->rows;
 }