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

Commit

Permalink
Introcuce ImportMetaFilter #56
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaber-de committed Feb 14, 2016
1 parent 37568f0 commit 8bc01b3
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
69 changes: 69 additions & 0 deletions inc/Import/Filter/ImportMetaFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php # -*- coding: utf-8 -*-

namespace W2M\Import\Filter;

use
W2M\Import\Data,
W2M\Import\Filter,
W2M\Import\Type;

/**
* Class ImportMetaFilter
*
* @package W2M\Import\Filter
*/
class ImportMetaFilter implements ImportMetaFilterInterface {

/**
* @var Data\MetaFilterListInterface
*/
private $filter_list;

/**
* @var string
*/
private $type;

/**
* @param Data\MetaFilterListInterface $filter_list
* @param string $type
*/
public function __construct(
Data\MetaFilterListInterface $filter_list,
$type
) {

$this->filter_list = $filter_list;
$this->type = (string) $type;
}

/**
* @param Type\ImportMetaInterface $meta
* @param int $object_id
*
* @return mixed
*/
public function filter_value( Type\ImportMetaInterface $meta, $object_id ) {

$filters = $this->filter_list->get_filters( $this->type, $meta->key() );
$value = $meta->value();
foreach ( $filters as $filter ) {
if ( ! $filter->is_filterable( $meta->value(), $object_id ) ) {
/**
* Fires when a filter is invalid (due to missing data)
*
* @param string $type ('post', 'comment', 'user' or 'term')
* @param int $object_id
* @param Type\ImportMetaInterface $meta
* @param Filter\ValueFilterableInterface $filter
*/
do_action( 'w2m_import_meta_not_filterable', $this->type, $object_id, $meta, $filter );
continue;
}
$value = $filter->filter( $value, $object_id );
}

return $value;
}

}
24 changes: 24 additions & 0 deletions inc/Import/Filter/ImportMetaFilterInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php # -*- coding: utf-8 -*-

namespace W2M\Import\Filter;

use
W2M\Import\Type;

/**
* Interface ImportMetaFilterInterface
*
* Filters the value of ImportMetaInterface instance
*
* @package W2M\Import\Filter
*/
interface ImportMetaFilterInterface {

/**
* @param Type\ImportMetaInterface $meta
* @param int $object_id
*
* @return mixed (The filtered value)
*/
public function filter_value( Type\ImportMetaInterface $meta, $object_id );
}
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ Use the installer via back-end of your install or ...
* `w2m_import_post_ancestor_resolving_start` in `W2M\Import\Module\ResolvingPendingRelations::resolving_posts()`
* `w2m_import_term_ancestor_resolving_start` in `W2M\Import\Module\ResolvingPendingRelations::resolving_terms()`

* `w2m_import_meta_not_filterable` in `W2M\Import\Filter\ImportMetaFilter::filter_value()`


## Other Notes

Expand Down
16 changes: 16 additions & 0 deletions tests/phpunit/Unit/Import/Filter/ImportMetaFilterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php # -*- coding: utf-8 -*-

namespace W2M\Test\Unit\Import\Filter;

use
W2M\Import\Filter,
W2M\Test\Helper;

class ImportMetaFilterTest extends Helper\MonkeyTestCase {

public function test_filter_value() {

// Todo: Write tests for
$this->markTestIncomplete( 'Under construction' );
}
}

0 comments on commit 8bc01b3

Please sign in to comment.