Permalink
Browse files

Remove addFilterClosure, addConverterClosure and addWriterClosure met…

…hods
  • Loading branch information...
1 parent 128ef08 commit 6d06981c2ff226c17e6532914d04bbd56d22ba95 @ddeboer ddeboer committed Jun 19, 2012
Showing with 66 additions and 60 deletions.
  1. +25 −15 README.md
  2. +41 −0 Tests/WorkflowTest.php
  3. +0 −45 Workflow.php
View
40 README.md
@@ -55,7 +55,7 @@ Usage
object to retrieve this `splFileObject`: construct a source and add `source
filters`, if you like.
2. Construct a `reader` object and pass an `splFileObject` to it.
-3. Construct a `workflow` object and pass the reader to it. Add at least one
+3. Construct a `workflow` object and pass the reader to it. Add at least one
`writer` object to this workflow. You can also add `filters` and `converters`
to the workflow.
4. Process the workflow: this will read the data from the reader, filter and
@@ -64,10 +64,10 @@ Usage
An example:
```
+use Ddeboer\DataImportBundle\Workflow;
use Ddeboer\DataImportBundle\Source\Http;
use Ddeboer\DataImportBundle\Source\Filter\Unzip;
use Ddeboer\DataImportBundle\Reader\CsvReader;
-use Ddeboer\DataImportBundle\Workflow;
use Ddeboer\DataImportBundle\Converter\DateTimeConverter;
(...)
@@ -90,22 +90,32 @@ $workflow = new Workflow($csvReader);
$dateTimeConverter = new DateTimeConverter();
// Add converters to the workflow
-$workflow->addConverter('twn_datumbeschikking', $dateTimeConverter)
- ->addConverter('twn_datumeind', $dateTimeConverter)
- ->addConverter('datummutatie', $dateTimeConverter)
+$workflow
+ ->addConverter('twn_datumbeschikking', $dateTimeConverter)
+ ->addConverter('twn_datumeind', $dateTimeConverter)
+ ->addConverter('datummutatie', $dateTimeConverter)
// You can also add closures as converters
- ->addConverterClosure('twn_nummertm', function($input) {
- return str_replace('-', '', $input);
- })
- ->addConverterClosure('twn_nummervan', function($input) {
- return str_replace('-', '', $input);
- })
-
-// For now, no writers are supplied yet, so implement your own or use a closure
- ->addWriterClosure(function($csvLine) {
+ ->addConverter('twn_nummertm',
+ new \Ddeboer\DataImportBundle\Converter\CallbackConverter(
+ function($input) {
+ return str_replace('-', '', $input);
+ }
+ )
+ ->addConverter('twn_nummervan',
+ new \Ddeboer\DataImportBundle\Converter\CallbackConverter(
+ function($input) {
+ return str_replace('-', '', $input);
+ }
+ )
+
+// Use one of the writers supplied with this bundle, implement your own, or use
+// a closure:
+ ->addWriter(new \Ddeboer\DataImportBundle\Writer\CallbackWriter(
+ function($csvLine) {
var_dump($csvLine);
- });
+ }
+ );
// Process the workflow
$workflow->process();
View
41 Tests/WorkflowTest.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace Ddeboer\DataImportBundle\Tests;
+
+use Ddeboer\DataImportBundle\Workflow;
+use Ddeboer\DataImportBundle\Filter\CallbackFilter;
+use Ddeboer\DataImportBundle\Converter\CallbackConverter;
+use Ddeboer\DataImportBundle\Writer\CallbackWriter;
+
+class WorkflowTest extends \PHPUnit_Framework_TestCase
+{
+ public function testAddCallbackFilter()
+ {
+ $this->getWorkflow()->addFilter(new CallbackFilter(function($input) {
+ return true;
+ }));
+ }
+
+ public function testAddCallbackConverter()
+ {
+ $this->getWorkflow()->addConverter('someField', new CallbackConverter(function($input) {
+ return str_replace('-', '', $input);
+ }));
+ }
+
+ public function testAddCallbackWriter()
+ {
+ $this->getWorkflow()->addWriter(new CallbackWriter(function($item) {
+ var_dump($item);
+ }));
+ }
+
+ protected function getWorkflow()
+ {
+ $reader = $this->getMockBuilder('\Ddeboer\DataImportBundle\Reader\CsvReader')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ return new Workflow($reader);
+ }
+}
View
45 Workflow.php
@@ -96,22 +96,6 @@ public function addFilterAfterConversion(Filter $filter)
}
/**
- * Add a filter closure to the workflow
- *
- * A filter decides whether an item is accepted into the import process.
- *
- * @param \Closure $closure
- *
- * @return $this
- */
- public function addFilterClosure(\Closure $closure)
- {
- $this->filters[] = new CallbackFilter($closure);
-
- return $this;
- }
-
- /**
* Add a writer to the workflow
*
* A writer takes a filtered and converted item, and writes that to, e.g.,
@@ -129,20 +113,6 @@ public function addWriter(Writer $writer)
}
/**
- * Add a writer closure to the workflow
- *
- * @param \Closure $closure
- *
- * @return Workflow
- */
- public function addWriterClosure(\Closure $closure)
- {
- $this->writers[] = new CallbackWriter($closure);
-
- return $this;
- }
-
- /**
* Add a converter to the workflow
*
* @param string $field Field
@@ -158,21 +128,6 @@ public function addConverter($field, Converter $converter)
}
/**
- * Add a converter closure to the workflow
- *
- * @param string $field Field
- * @param \Closure $closure Closure
- *
- * @return Workflow
- */
- public function addConverterClosure($field, \Closure $closure)
- {
- $this->converters[$field][] = new CallbackConverter($closure);
-
- return $this;
- }
-
- /**
* Add a mapping to the workflow
*
* If we can get the field names from the reader, they are just to check the

0 comments on commit 6d06981

Please sign in to comment.