-
Notifications
You must be signed in to change notification settings - Fork 16
/
filter-key.php
43 lines (40 loc) · 925 Bytes
/
filter-key.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
* Filter an array of string results based on a given regular expression.
*/
class KeyFilter extends FilterIterator
{
private $_regex;
/**
* The key filter takes in an iterator and a regular expression pattern
* to filter the iterator keys against.
*
* @access public
* @return void
*/
public function __construct(Iterator $it, $regex)
{
parent::__construct($it);
$this->_regex = $regex;
}
/**
* Provide the required accept() method for filtering keys by
* a regular expression.
*
* @access public
* @return int|bool
*/
public function accept()
{
return preg_match($this->_regex, $this->getInnerIterator()->key());
}
/**
* Override the cloning method.
*
* @access protected
* @return bool
*/
protected function __clone() {
return false;
}
}