From aaf5ca234cecc45f4068bc98a29c8905affafd01 Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Sat, 24 Nov 2012 09:42:09 +0100 Subject: [PATCH 1/2] Get str_getcsv working on PHP 5.2 --- unitTests/testDataFileIterator.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/unitTests/testDataFileIterator.php b/unitTests/testDataFileIterator.php index 0e6aad8..9eabe09 100644 --- a/unitTests/testDataFileIterator.php +++ b/unitTests/testDataFileIterator.php @@ -57,7 +57,7 @@ class testDataFileIterator implements Iterator list($testData) = explode('//',$testDataRow); // Split data into an array of individual values and a result - $dataSet = str_getcsv($testData,',',"'"); + $dataSet = $this->_getcsv($testData, ',', "'"); foreach($dataSet as &$dataValue) { $dataValue = $this->_parseDataValue($dataValue); } @@ -66,6 +66,25 @@ class testDataFileIterator implements Iterator return $dataSet; } + private function _getcsv($input, $delimiter, $enclosure) + { + if (function_exists('str_getcsv')) { + return str_getcsv($input, $delimiter, $enclosure); + } + + $temp = fopen('php://memory', 'rw'); + fwrite($temp, $input); + rewind($temp); + $data = fgetcsv($temp, strlen($input), $delimiter, $enclosure); + fclose($temp); + + if ($data === false) { + $data = array(null); + } + + return $data; + } + private function _parseDataValue($dataValue) { // discard any white space $dataValue = trim($dataValue); From 06293c784ab81f461e5c68c771deff67507bb7cc Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Sat, 24 Nov 2012 09:44:56 +0100 Subject: [PATCH 2/2] __DIR__ -> dirname(__FILE__) --- Build/build-phar.php | 2 +- Examples/32chartreadwrite.php | 2 +- Examples/35chartrender.php | 2 +- Examples/36chartreadwriteHTML.php | 2 +- Examples/36chartreadwritePDF.php | 2 +- unitTests/custom/complexAssert.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Build/build-phar.php b/Build/build-phar.php index 5e505aa..d2e5063 100644 --- a/Build/build-phar.php +++ b/Build/build-phar.php @@ -36,7 +36,7 @@ if (ini_get('phar.readonly')) { $pharName = 'PHPExcel.phar'; // target folder -$sourceDir = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Classes' . DIRECTORY_SEPARATOR; +$sourceDir = dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'Classes' . DIRECTORY_SEPARATOR; // default meta information $metaData = array( diff --git a/Examples/32chartreadwrite.php b/Examples/32chartreadwrite.php index 614dc6e..797612e 100644 --- a/Examples/32chartreadwrite.php +++ b/Examples/32chartreadwrite.php @@ -48,7 +48,7 @@ $inputFileNames = 'templates/32readwrite*[0-9].xlsx'; if ((isset($argc)) && ($argc > 1)) { $inputFileNames = array(); for($i = 1; $i < $argc; ++$i) { - $inputFileNames[] = __DIR__ . '/templates/' . $argv[$i]; + $inputFileNames[] = dirname(__FILE__) . '/templates/' . $argv[$i]; } } else { $inputFileNames = glob($inputFileNames); diff --git a/Examples/35chartrender.php b/Examples/35chartrender.php index bb3ec5f..601fb4c 100644 --- a/Examples/35chartrender.php +++ b/Examples/35chartrender.php @@ -68,7 +68,7 @@ $inputFileNames = 'templates/32readwrite*[0-9].xlsx'; if ((isset($argc)) && ($argc > 1)) { $inputFileNames = array(); for($i = 1; $i < $argc; ++$i) { - $inputFileNames[] = __DIR__ . '/templates/' . $argv[$i]; + $inputFileNames[] = dirname(__FILE__) . '/templates/' . $argv[$i]; } } else { $inputFileNames = glob($inputFileNames); diff --git a/Examples/36chartreadwriteHTML.php b/Examples/36chartreadwriteHTML.php index d2c0a70..3998378 100644 --- a/Examples/36chartreadwriteHTML.php +++ b/Examples/36chartreadwriteHTML.php @@ -68,7 +68,7 @@ $inputFileNames = 'templates/36write*.xlsx'; if ((isset($argc)) && ($argc > 1)) { $inputFileNames = array(); for($i = 1; $i < $argc; ++$i) { - $inputFileNames[] = __DIR__ . '/templates/' . $argv[$i]; + $inputFileNames[] = dirname(__FILE__) . '/templates/' . $argv[$i]; } } else { $inputFileNames = glob($inputFileNames); diff --git a/Examples/36chartreadwritePDF.php b/Examples/36chartreadwritePDF.php index f1b4130..bdac471 100644 --- a/Examples/36chartreadwritePDF.php +++ b/Examples/36chartreadwritePDF.php @@ -91,7 +91,7 @@ $inputFileNames = 'templates/36write*.xlsx'; if ((isset($argc)) && ($argc > 1)) { $inputFileNames = array(); for($i = 1; $i < $argc; ++$i) { - $inputFileNames[] = __DIR__ . '/templates/' . $argv[$i]; + $inputFileNames[] = dirname(__FILE__) . '/templates/' . $argv[$i]; } } else { $inputFileNames = glob($inputFileNames); diff --git a/unitTests/custom/complexAssert.php b/unitTests/custom/complexAssert.php index 486e092..5b813d2 100644 --- a/unitTests/custom/complexAssert.php +++ b/unitTests/custom/complexAssert.php @@ -1,6 +1,6 @@