This repository has been archived by the owner on Nov 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); | ||
} | ||
} |