コード例 #1
0
ファイル: Chain.php プロジェクト: warrickbayman/charms
 /**
  * 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;
 }
コード例 #2
0
ファイル: Rows.php プロジェクト: warrickbayman/komma
 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;
 }
コード例 #3
0
ファイル: Reader.php プロジェクト: warrickbayman/komma
 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;
 }