Skip to content

Commit

Permalink
Adds callback an dateformat sep
Browse files Browse the repository at this point in the history
  • Loading branch information
jaapio committed Feb 26, 2018
1 parent c307550 commit be631fb
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/Step/Callback.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php


namespace PolderKnowledge\Importer\Step;


use PolderKnowledge\Importer\Reader\Reader;
use Zend\Db\Sql\Ddl\Column\Datetime;

final class Callback implements Step
{
/**
* @var Step
*/
private $step;

private $key;

private $callback;

public function __construct($key, callable $callback)
{
$this->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;
}
}
44 changes: 44 additions & 0 deletions src/Step/DateFormat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php


namespace PolderKnowledge\Importer\Step;


use PolderKnowledge\Importer\Reader\Reader;
use Zend\Db\Sql\Ddl\Column\Datetime;

final class DateFormat implements Step
{
/**
* @var Step
*/
private $step;

private $key;

private $format;

public function __construct($key, $format)
{
$this->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;
}
}

0 comments on commit be631fb

Please sign in to comment.