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], 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); diff --git a/src/Goodby/CSV/Import/Tests/Protocol/InterpreterTest.php b/src/Goodby/CSV/Import/Tests/Protocol/InterpreterTest.php index a570375..a3b907a 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); } }