mirror of
https://github.com/parsecsv/parsecsv-for-php.git
synced 2026-02-19 08:36:39 +00:00
Merge branch 'feature-datacollections'
Conflicts: src/Csv.php
This commit is contained in:
@@ -26,5 +26,8 @@
|
|||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "4.1.*"
|
"phpunit/phpunit": "4.1.*"
|
||||||
|
},
|
||||||
|
"suggest": {
|
||||||
|
"illuminate/support": "Fluent array interface for map functions"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
32
src/Csv.php
32
src/Csv.php
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace ParseCsv;
|
namespace ParseCsv;
|
||||||
|
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
use ParseCsv\enums\FileProcessingModeEnum;
|
use ParseCsv\enums\FileProcessingModeEnum;
|
||||||
use ParseCsv\enums\SortEnum;
|
use ParseCsv\enums\SortEnum;
|
||||||
use ParseCsv\extensions\DatatypeTrait;
|
use ParseCsv\extensions\DatatypeTrait;
|
||||||
@@ -17,7 +18,6 @@ class Csv {
|
|||||||
Based on the concept of Ming Hong Ng's CsvFileParser class:
|
Based on the concept of Ming Hong Ng's CsvFileParser class:
|
||||||
- http://minghong.blogspot.com/2006/07/csv-parser-for-php.html
|
- http://minghong.blogspot.com/2006/07/csv-parser-for-php.html
|
||||||
|
|
||||||
|
|
||||||
(The MIT license)
|
(The MIT license)
|
||||||
|
|
||||||
Copyright (c) 2014 Jim Myhrberg.
|
Copyright (c) 2014 Jim Myhrberg.
|
||||||
@@ -564,7 +564,6 @@ class Csv {
|
|||||||
- substr_count($data, "\r\n")
|
- substr_count($data, "\r\n")
|
||||||
- $headingRow;
|
- $headingRow;
|
||||||
|
|
||||||
|
|
||||||
return $count;
|
return $count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1206,7 +1205,7 @@ class Csv {
|
|||||||
* first line containing only "sep=;", where the last character is the
|
* first line containing only "sep=;", where the last character is the
|
||||||
* separator. Microsoft Excel is able to open such files.
|
* separator. Microsoft Excel is able to open such files.
|
||||||
*
|
*
|
||||||
* @param string $data file data
|
* @param string $data file data
|
||||||
*
|
*
|
||||||
* @return string|false detected delimiter, or false if none found
|
* @return string|false detected delimiter, or false if none found
|
||||||
*/
|
*/
|
||||||
@@ -1224,7 +1223,7 @@ class Csv {
|
|||||||
/**
|
/**
|
||||||
* Support for Excel-compatible sep=? row.
|
* Support for Excel-compatible sep=? row.
|
||||||
*
|
*
|
||||||
* @param string $data_string file data to be updated
|
* @param string $data_string file data to be updated
|
||||||
*
|
*
|
||||||
* @return bool TRUE if sep= line was found at the very beginning of the file
|
* @return bool TRUE if sep= line was found at the very beginning of the file
|
||||||
*/
|
*/
|
||||||
@@ -1320,4 +1319,29 @@ class Csv {
|
|||||||
ksort($filtered);
|
ksort($filtered);
|
||||||
$this->delimiter = reset($filtered);
|
$this->delimiter = reset($filtered);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getCollection
|
||||||
|
* Returns a Illuminate/Collection object
|
||||||
|
* This may prove to be helpful to people who want to
|
||||||
|
* create macros, and or use map functions
|
||||||
|
*
|
||||||
|
* @access public
|
||||||
|
* @link https://laravel.com/docs/5.6/collections
|
||||||
|
*
|
||||||
|
* @throws \ErrorException - If the Illuminate\Support\Collection class is not found
|
||||||
|
*
|
||||||
|
* @return Collection
|
||||||
|
*/
|
||||||
|
public function getCollection() {
|
||||||
|
//does the Illuminate\Support\Collection class exists?
|
||||||
|
//this uses the autoloader to try to determine
|
||||||
|
//@see http://php.net/manual/en/function.class-exists.php
|
||||||
|
if (class_exists('Illuminate\Support\Collection', true) == false) {
|
||||||
|
throw new \ErrorException('It would appear you have not installed the illuminate/support package!');
|
||||||
|
}
|
||||||
|
|
||||||
|
//return the collection
|
||||||
|
return new Collection($this->data);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,8 +58,9 @@ class ConstructTest extends TestCase {
|
|||||||
ob_start();
|
ob_start();
|
||||||
/** @noinspection PhpIncludeInspection */
|
/** @noinspection PhpIncludeInspection */
|
||||||
require $script_file;
|
require $script_file;
|
||||||
|
$ob_get_clean = ob_get_clean();
|
||||||
if ($script_file != 'download.php') {
|
if ($script_file != 'download.php') {
|
||||||
$this->assertContains('<td>', ob_get_clean());
|
$this->assertContains('<td>', $ob_get_clean);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
chdir('..');
|
chdir('..');
|
||||||
|
|||||||
Reference in New Issue
Block a user