Skip to content
This repository has been archived by the owner on Nov 28, 2019. It is now read-only.

Commit

Permalink
Implement filters in element processors #49
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaber-de committed Feb 7, 2016
1 parent 4313789 commit f82dda7
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
15 changes: 13 additions & 2 deletions inc/Import/Service/CommentProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace W2M\Import\Service;

use
W2M\Import\Filter,
W2M\Import\Iterator;

class CommentProcessor implements ElementProcessorInterface {
Expand All @@ -17,17 +18,27 @@ class CommentProcessor implements ElementProcessorInterface {
*/
private $importer;

/**
* @var Filter\CommentImportFilterInterface
*/
private $filter;

/**
* @param Iterator\CommentIterator $iterator
* @param CommentImporterInterface $importer
* @param Filter\CommentImportFilterInterface $filter (Optional)
*/
public function __construct(
Iterator\CommentIterator $iterator,
CommentImporterInterface $importer
CommentImporterInterface $importer,
Filter\CommentImportFilterInterface $filter = NULL
) {

$this->iterator = $iterator;
$this->importer = $importer;
$this->filter = $filter
? $filter
: new Filter\CommentPassThroughFilter;
}

/**
Expand All @@ -41,7 +52,7 @@ public function process_elements() {

while ( $this->iterator->valid() ) {
$import_comment = $this->iterator->current();
if ( $import_comment ) {
if ( $import_comment && $this->filter->comment_to_import( $import_comment ) ) {
$this->importer->import_comment( $import_comment );
}
$this->iterator->next();
Expand Down
15 changes: 13 additions & 2 deletions inc/Import/Service/PostProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace W2M\Import\Service;

use
W2M\Import\Filter,
W2M\Import\Iterator;

class PostProcessor implements ElementProcessorInterface {
Expand All @@ -17,16 +18,26 @@ class PostProcessor implements ElementProcessorInterface {
*/
private $importer;

/**
* @var Filter\PostImportFilterInterface
*/
private $filter;

/**
* @param Iterator\PostIterator $iterator
* @param PostImporterInterface $importer
* @param Filter\PostImportFilterInterface $filter (Optional)
*/
public function __construct(
Iterator\PostIterator $iterator,
PostImporterInterface $importer
PostImporterInterface $importer,
Filter\PostImportFilterInterface $filter = NULL
) {
$this->iterator = $iterator;
$this->importer = $importer;
$this->filter = $filter
? $filter
: new Filter\PostPassThroughFilter;
}

/**
Expand All @@ -40,7 +51,7 @@ public function process_elements() {

while ( $this->iterator->valid() ) {
$import_post = $this->iterator->current();
if ( $import_post ) {
if ( $import_post && $this->filter->post_to_import( $import_post ) ) {
$this->importer->import_post( $import_post );
}
$this->iterator->next();
Expand Down
15 changes: 13 additions & 2 deletions inc/Import/Service/TermProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace W2M\Import\Service;

use
W2M\Import\Filter,
W2M\Import\Iterator;

class TermProcessor implements ElementProcessorInterface {
Expand All @@ -17,17 +18,27 @@ class TermProcessor implements ElementProcessorInterface {
*/
private $importer;

/**
* @var Filter\TermImportFilterInterface
*/
private $filter;

/**
* @param Iterator\TermIterator $iterator
* @param TermImporterInterface $importer
* @param Filter\TermImportFilterInterface $filter (Optional)
*/
public function __construct(
Iterator\TermIterator $iterator,
TermImporterInterface $importer
TermImporterInterface $importer,
Filter\TermImportFilterInterface $filter = NULL
) {

$this->iterator = $iterator;
$this->importer = $importer;
$this->filter = $filter
? $filter
: new Filter\TermPassThroughFilter;
}

/**
Expand All @@ -41,7 +52,7 @@ public function process_elements() {

while ( $this->iterator->valid() ) {
$import_term = $this->iterator->current();
if ( $import_term ) {
if ( $import_term && $this->filter->term_to_import( $import_term ) ) {
$this->importer->import_term( $import_term );
}
$this->iterator->next();
Expand Down
15 changes: 13 additions & 2 deletions inc/Import/Service/UserProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace W2M\Import\Service;

use
W2M\Import\Filter,
W2M\Import\Iterator;

class UserProcessor implements ElementProcessorInterface {
Expand All @@ -17,17 +18,27 @@ class UserProcessor implements ElementProcessorInterface {
*/
private $importer;

/**
* @var Filter\UserImportFilterInterface
*/
private $filter;

/**
* @param Iterator\UserIterator $iterator
* @param UserImporterInterface $importer
* @param Filter\UserImportFilterInterface $filter (Optional)
*/
public function __construct(
Iterator\UserIterator $iterator,
UserImporterInterface $importer
UserImporterInterface $importer,
Filter\UserImportFilterInterface $filter = NULL
) {

$this->iterator = $iterator;
$this->importer = $importer;
$this->filter = $filter
? $filter
: new Filter\UserPassThroughFilter;
}

/**
Expand All @@ -41,7 +52,7 @@ public function process_elements() {

while ( $this->iterator->valid() ) {
$import_user = $this->iterator->current();
if ( $import_user ) {
if ( $import_user && $this->filter->user_to_import( $import_user ) ) {
$this->importer->import_user( $import_user );
}
$this->iterator->next();
Expand Down

0 comments on commit f82dda7

Please sign in to comment.