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
3 changed files
with
168 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,98 @@ | ||
<?php # -*- coding: utf-8 -*- | ||
|
||
namespace W2M\Import\Data; | ||
|
||
use | ||
W2M\Import\Filter; | ||
|
||
/** | ||
* Class MetaFilterList | ||
* | ||
* Manages a list of Filter\ValueFilterableInterface for each type:meta-key pair | ||
* | ||
* @package W2M\Import\Data | ||
*/ | ||
class MetaFilterList implements MetaFilterListInterface { | ||
|
||
/** | ||
* @var Filter\ValueFilterableInterface[][] | ||
*/ | ||
private $filters; | ||
|
||
public function __construct() { | ||
|
||
$this->filters = [ | ||
'comment' => [], | ||
'post' => [], | ||
'term' => [], | ||
'user' => [] | ||
]; | ||
} | ||
|
||
/** | ||
* @param string $type | ||
* @param string $key | ||
* @param Filter\ValueFilterableInterface $filter | ||
* | ||
* @return bool | ||
*/ | ||
public function push_filter( $type, $key, Filter\ValueFilterableInterface $filter ) { | ||
|
||
$this->setup_list( $type, $key ); | ||
$index = spl_object_hash( $filter ); | ||
if ( isset( $this->filters[ $type ][ $key ][ $index ] ) ) | ||
return FALSE; | ||
|
||
$this->filters[ $type ][ $key ][ $index ] = $filter; | ||
|
||
return TRUE; | ||
} | ||
|
||
/** | ||
* @param string $type | ||
* @param string $key | ||
* @param Filter\ValueFilterableInterface $filter | ||
* | ||
* @return bool | ||
*/ | ||
public function pop_filter( $type, $key, Filter\ValueFilterableInterface $filter ) { | ||
|
||
$this->setup_list( $type, $key ); | ||
$index = spl_object_hash( $filter ); | ||
if ( isset( $this->filters[ $type ][ $key ][ $index ] ) ) { | ||
unset( $this->filters[ $type ][ $key ][ $index ] ); | ||
|
||
return TRUE; | ||
} | ||
|
||
return FALSE; | ||
} | ||
|
||
/** | ||
* @param string $type | ||
* @param string $key | ||
* | ||
* @return Filter\ValueFilterableInterface[] | ||
*/ | ||
public function get_filters( $type, $key ) { | ||
|
||
$this->setup_list( $type, $key ); | ||
|
||
return isset( $this->filters[ $type ][ $key ] ) | ||
? $this->filters[ $type ][ $key ] | ||
: []; | ||
} | ||
|
||
/** | ||
* @param string $type | ||
* @param string $key | ||
*/ | ||
private function setup_list( $type, $key ) { | ||
|
||
if ( isset( $this->filters[ $type ][ $key ] ) ) | ||
return; | ||
|
||
$this->filters[ $type ][ $key ] = []; | ||
} | ||
|
||
} |
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,42 @@ | ||
<?php # -*- coding: utf-8 -*- | ||
|
||
namespace W2M\Import\Data; | ||
|
||
use | ||
W2M\Import\Filter; | ||
|
||
/** | ||
* Interface MetaFilterListInterface | ||
* | ||
* Manages a list of Filter\ValueFilterableInterface for each type:meta-key pair | ||
* | ||
* @package W2M\Import\Data | ||
*/ | ||
interface MetaFilterListInterface { | ||
|
||
/** | ||
* @param string $type | ||
* @param string $key | ||
* @param Filter\ValueFilterableInterface $filter | ||
* | ||
* @return bool | ||
*/ | ||
public function push_filter( $type, $key, Filter\ValueFilterableInterface $filter ); | ||
|
||
/** | ||
* @param string $type | ||
* @param string $key | ||
* @param Filter\ValueFilterableInterface $filter | ||
* | ||
* @return bool | ||
*/ | ||
public function pop_filter( $type, $key, Filter\ValueFilterableInterface $filter ); | ||
|
||
/** | ||
* @param string $type | ||
* @param string $key | ||
* | ||
* @return Filter\ValueFilterableInterface[] | ||
*/ | ||
public function get_filters( $type, $key ); | ||
} |
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,28 @@ | ||
<?php # -*- coding: utf-8 -*- | ||
|
||
namespace W2M\Test\Unit\Import\Data; | ||
|
||
use | ||
W2M\Import\Filter, | ||
W2M\Test\Helper; | ||
|
||
class MetaFilterListTest extends Helper\MonkeyTestCase { | ||
|
||
public function test_push_filter() { | ||
|
||
// Todo: Write tests | ||
$this->markTestIncomplete( 'Under construction' ); | ||
} | ||
|
||
public function test_pop_filter() { | ||
|
||
// Todo: Write tests | ||
$this->markTestIncomplete( 'Under construction' ); | ||
} | ||
|
||
public function test_get_filters() { | ||
|
||
// Todo: Write tests | ||
$this->markTestIncomplete( 'Under construction' ); | ||
} | ||
} |