mirror of
https://github.com/parsecsv/parsecsv-for-php.git
synced 2026-02-19 08:36:39 +00:00
change accessibility of parse_file and parse_string
This commit is contained in:
@@ -408,7 +408,7 @@ class Csv {
|
||||
|
||||
if (strlen($input) <= PHP_MAXPATHLEN && is_readable($input)) {
|
||||
$this->file = $input;
|
||||
$this->data = $this->parse_file($input);
|
||||
$this->data = $this->parse_file();
|
||||
}
|
||||
else {
|
||||
$this->file = null;
|
||||
@@ -569,7 +569,7 @@ class Csv {
|
||||
*
|
||||
* @return array|bool
|
||||
*/
|
||||
public function parse_file($file = null) {
|
||||
protected function parse_file($file = null) {
|
||||
if (is_null($file)) {
|
||||
$file = $this->file;
|
||||
}
|
||||
@@ -592,7 +592,7 @@ class Csv {
|
||||
*
|
||||
* @return array|false - 2D array with CSV data, or false on failure
|
||||
*/
|
||||
public function parse_string($data = null) {
|
||||
protected function parse_string($data = null) {
|
||||
if (empty($data)) {
|
||||
if ($this->_check_data()) {
|
||||
$data = &$this->file_data;
|
||||
|
||||
@@ -89,7 +89,8 @@ class ParseTest extends TestCase
|
||||
$this->csv->enclosure = '"';
|
||||
$sInput = "86545235689,a\r\n34365587654,b\r\n13469874576,\"c\r\nd\"";
|
||||
$expected_data = [86545235689, 34365587654, 13469874576];
|
||||
$actual_data = $this->csv->parse_string($sInput);
|
||||
|
||||
$actual_data = $this->invokeMethod($this->csv, 'parse_string', array($sInput));
|
||||
$actual_column = array_map('reset', $actual_data);
|
||||
$this->assertEquals($expected_data, $actual_column);
|
||||
$this->assertEquals([
|
||||
@@ -198,4 +199,22 @@ class ParseTest extends TestCase
|
||||
$this->assertArrayHasKey('column1', $csv->data[0], 'Data parsed incorrectly with enclosure ' . $enclosure);
|
||||
$this->assertEquals('value1', $csv->data[0]['column1'], 'Data parsed incorrectly with enclosure ' . $enclosure);
|
||||
}
|
||||
|
||||
/**
|
||||
* Call protected/private method of a class.
|
||||
*
|
||||
* @param object &$object Instantiated object that we will run method on.
|
||||
* @param string $methodName Method name to call
|
||||
* @param array $parameters Array of parameters to pass into method.
|
||||
*
|
||||
* @return mixed Method return.
|
||||
*/
|
||||
private function invokeMethod(&$object, $methodName, array $parameters = array())
|
||||
{
|
||||
$reflection = new \ReflectionClass(get_class($object));
|
||||
$method = $reflection->getMethod($methodName);
|
||||
$method->setAccessible(true);
|
||||
|
||||
return $method->invokeArgs($object, $parameters);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user