From 4f3ce9d72ec96789ee047ac9d45f05e96d9f7f4d Mon Sep 17 00:00:00 2001 From: Amor Batayola Date: Fri, 22 May 2015 14:46:09 +0800 Subject: [PATCH 1/4] added variable $url so it can be access inside addObserver() --- .../CSV/Import/Protocol/InterpreterInterface.php | 2 +- src/Goodby/CSV/Import/Standard/Interpreter.php | 12 ++++++------ src/Goodby/CSV/Import/Standard/Lexer.php | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Goodby/CSV/Import/Protocol/InterpreterInterface.php b/src/Goodby/CSV/Import/Protocol/InterpreterInterface.php index 85b246e..7b26b6f 100644 --- a/src/Goodby/CSV/Import/Protocol/InterpreterInterface.php +++ b/src/Goodby/CSV/Import/Protocol/InterpreterInterface.php @@ -11,5 +11,5 @@ interface InterpreterInterface * @param $line * @return void */ - public function interpret($line); + public function interpret($line, $url); } diff --git a/src/Goodby/CSV/Import/Standard/Interpreter.php b/src/Goodby/CSV/Import/Standard/Interpreter.php index 0a49e30..ed1639a 100644 --- a/src/Goodby/CSV/Import/Standard/Interpreter.php +++ b/src/Goodby/CSV/Import/Standard/Interpreter.php @@ -33,7 +33,7 @@ class Interpreter implements InterpreterInterface * @return void * @throws \Goodby\CSV\Import\Protocol\Exception\InvalidLexicalException */ - public function interpret($line) + public function interpret($line, $url) { $this->checkRowConsistency($line); @@ -41,7 +41,7 @@ public function interpret($line) throw new InvalidLexicalException('line is must be array'); } - $this->notify($line); + $this->notify($line, $url); } public function unstrict() @@ -66,12 +66,12 @@ public function addObserver($observer) * * @param $line */ - private function notify($line) + private function notify($line, $url) { $observers = $this->observers; foreach ($observers as $observer) { - $this->delegate($observer, $line); + $this->delegate($observer, $line, $url); } } @@ -81,9 +81,9 @@ private function notify($line) * @param $observer * @param $line */ - private function delegate($observer, $line) + private function delegate($observer, $line, $url) { - call_user_func($observer, $line); + call_user_func($observer, $line, $url); } /** diff --git a/src/Goodby/CSV/Import/Standard/Lexer.php b/src/Goodby/CSV/Import/Standard/Lexer.php index 7631791..548360e 100644 --- a/src/Goodby/CSV/Import/Standard/Lexer.php +++ b/src/Goodby/CSV/Import/Standard/Lexer.php @@ -60,7 +60,7 @@ public function parse($filename, InterpreterInterface $interpreter) if ($ignoreHeader && $lineNumber == 0 || (count($line) === 1 && empty($line[0]))) { continue; } - $interpreter->interpret($line); + $interpreter->interpret($line, $url); } parse_str(str_replace(';', '&', $originalLocale), $locale_array); From 51b579e0b7f6360f6bc764396b5cfbf21f8c51a5 Mon Sep 17 00:00:00 2001 From: Amor Batayola Date: Fri, 22 May 2015 15:18:33 +0800 Subject: [PATCH 2/4] modified test unit --- src/Goodby/CSV/Import/Tests/Protocol/InterpreterTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Goodby/CSV/Import/Tests/Protocol/InterpreterTest.php b/src/Goodby/CSV/Import/Tests/Protocol/InterpreterTest.php index a570375..5af3b66 100644 --- a/src/Goodby/CSV/Import/Tests/Protocol/InterpreterTest.php +++ b/src/Goodby/CSV/Import/Tests/Protocol/InterpreterTest.php @@ -12,6 +12,7 @@ class InterpreterTest extends \PHPUnit_Framework_TestCase public function testInterpreterInterface() { $line = array(); + $url = 'filepath'; $interpreter = $this->getMock('\Goodby\CSV\Import\Protocol\InterpreterInterface'); @@ -20,7 +21,7 @@ public function testInterpreterInterface() ->with($this->identicalTo($line)) ; - $interpreter->interpret($line); + $interpreter->interpret($line, $url); } /** @@ -36,7 +37,8 @@ public function testInterpreterInterfaceWillThrownInvalidLexicalException() ; $line = "INVALID LEXICAL"; + $url = 'filepath'; - $interpreter->interpret($line); + $interpreter->interpret($line), $url; } } From d249cc47585d5c60d9c7f9d1c5344f4483886d2f Mon Sep 17 00:00:00 2001 From: Amor Batayola Date: Fri, 22 May 2015 15:24:05 +0800 Subject: [PATCH 3/4] modified README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0045524..7e08072 100644 --- a/README.md +++ b/README.md @@ -149,7 +149,7 @@ $lexer = new Lexer($config); $interpreter = new Interpreter(); -$interpreter->addObserver(function(array $columns) use ($pdo) { +$interpreter->addObserver(function(array $columns, $url) use ($pdo) { $stmt = $pdo->prepare('INSERT INTO user (id, name, email) VALUES (?, ?, ?)'); $stmt->execute($columns); }); @@ -180,7 +180,7 @@ $config->setDelimiter("\t"); $lexer = new Lexer($config); $interpreter = new Interpreter(); -$interpreter->addObserver(function(array $row) use (&$temperature) { +$interpreter->addObserver(function(array $row, $url) use (&$temperature) { $temperature[] = array( 'temperature' => $row[0], 'city' => $row[1], From 5fe047b92908d001553cb6026f52305bc62c8763 Mon Sep 17 00:00:00 2001 From: Amor Batayola Date: Fri, 22 May 2015 15:26:28 +0800 Subject: [PATCH 4/4] test unit fixes --- src/Goodby/CSV/Import/Tests/Protocol/InterpreterTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Goodby/CSV/Import/Tests/Protocol/InterpreterTest.php b/src/Goodby/CSV/Import/Tests/Protocol/InterpreterTest.php index 5af3b66..a3b907a 100644 --- a/src/Goodby/CSV/Import/Tests/Protocol/InterpreterTest.php +++ b/src/Goodby/CSV/Import/Tests/Protocol/InterpreterTest.php @@ -39,6 +39,6 @@ public function testInterpreterInterfaceWillThrownInvalidLexicalException() $line = "INVALID LEXICAL"; $url = 'filepath'; - $interpreter->interpret($line), $url; + $interpreter->interpret($line, $url); } }