From be631fb3f642b8c15741044f6a19701e985d29b3 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Mon, 26 Feb 2018 14:56:08 +0100 Subject: [PATCH] Adds callback an dateformat sep --- src/Step/Callback.php | 44 +++++++++++++++++++++++++++++++++++++++++ src/Step/DateFormat.php | 44 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 src/Step/Callback.php create mode 100644 src/Step/DateFormat.php diff --git a/src/Step/Callback.php b/src/Step/Callback.php new file mode 100644 index 0000000..5ec88e3 --- /dev/null +++ b/src/Step/Callback.php @@ -0,0 +1,44 @@ +key = $key; + $this->callback = $callback; + } + + /** + * @return \Generator + */ + public function fetch() + { + foreach ($this->step->fetch() as $item) { + $value = $item[$this->key]; + + $item[$this->key] = call_user_func($this->callback, $value, $item); + yield $item; + } + } + + public function attach(Reader $step) + { + $this->step = $step; + } +} diff --git a/src/Step/DateFormat.php b/src/Step/DateFormat.php new file mode 100644 index 0000000..3b95e31 --- /dev/null +++ b/src/Step/DateFormat.php @@ -0,0 +1,44 @@ +key = $key; + $this->format = $format; + } + + /** + * @return \Generator + */ + public function fetch() + { + foreach ($this->step->fetch() as $item) { + $value = $item[$this->key]; + + $item[$this->key] = \DateTime::createFromFormat($this->format, $value)->format('Y-m-d'); + yield $item; + } + } + + public function attach(Reader $step) + { + $this->step = $step; + } +}