Skip to content

Commit

Permalink
Update Workflow.php
Browse files Browse the repository at this point in the history
  • Loading branch information
MelBookeen committed Jun 9, 2016
1 parent 50969f5 commit c74e269
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions Workflow/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,33 @@
namespace Bookeen\ETLWorkflow\Workflow;

use Bookeen\ETLWorkflow\Context\ContextInterface;
use Bookeen\ETLWorkflow\Event\WorkflowEvent;
use Bookeen\ETLWorkflow\Extractor\ExtractorAbstract;
use Bookeen\ETLWorkflow\Loader\LoaderInterface;
use Bookeen\ETLWorkflow\Transformer\TransformerInterface;
use Bookeen\ETLWorkflow\Event\WorkflowEvent;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;

class Workflow
{
/** @var ExtractorAbstract */
private $extractor;

/** @var TransformerInterface */
private $transformer;

/** @var LoaderInterface */
private $loader;

/** @var ContextInterface */
private $context;

/** @var EventDispatcherInterface */
private $dispatcher;

/**
* @param EventDispatcherInterface $dispatcher
*/
public function setDispatcher(EventDispatcherInterface $dispatcher)
{
$this->dispatcher = $dispatcher;
Expand Down Expand Up @@ -86,26 +99,29 @@ public function setTransformer(TransformerInterface $transformer)
$this->transformer = $transformer;
}

/**
*
*/
public function process()
{
if ($this->dispatcher !== null) {
$this->dispatcher->dispatch(WorkflowEvent::WORKFLOW_START);
$this->dispatcher->dispatch(WorkflowEvent::WORKFLOW_START, new GenericEvent($this->context));
}

while (null !== $extracted = $this->extractor->extract($this->context)) {
$transformed = $this->transformer->transform($extracted, $this->context);
$this->loader->load($transformed, $this->context);

if ($this->dispatcher !== null) {
$this->dispatcher->dispatch(WorkflowEvent::WORKFLOW_ADVANCE);
$this->dispatcher->dispatch(WorkflowEvent::WORKFLOW_ADVANCE, new GenericEvent($this->context));
}
}

$this->loader->flush($this->context);
$this->extractor->purge($this->context);

if ($this->dispatcher !== null) {
$this->dispatcher->dispatch(WorkflowEvent::WORKFLOW_FINISH);
$this->dispatcher->dispatch(WorkflowEvent::WORKFLOW_FINISH, new GenericEvent($this->context));
}
}
}

0 comments on commit c74e269

Please sign in to comment.