-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilter.php
More file actions
47 lines (45 loc) · 1.05 KB
/
Filter.php
File metadata and controls
47 lines (45 loc) · 1.05 KB
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
44
45
46
47
<?php
/**
* Utility of Iterator
*
* @package Tsukiyo
* @author Satoshi Nishimura <nishim314@gmail.com>
* @copyright Copyright (c) 2012 Satoshi Nishimura
*/
/**
* Utility of Iterator
*
* usage:
* <code><pre>
* $iterator = $db->from('Item')->order('itemId')->iterator();
* $iterator2 = new Tsukiyo_Filter($iterator, array('myclass', 'filter'));
* </pre></code>
*
* callback function:
* <code><pre>
* class myclass {
* public static function filter($vo){
* $vo->status = myclass::codeToText($vo->statusCode);
* return $vo;
* }
* }
* </pre></code>
*
* @package Tsukiyo
* @author Satoshi Nishimura <nishim314@gmail.com>
* @copyright Copyright (c) 2012 Satoshi Nishimura
*/
class Tsukiyo_Filter extends IteratorIterator
{
private $callback;
public function __construct(Traversable $iterator, $callback)
{
parent::__construct($iterator);
$this->callback = $callback;
}
public function current()
{
$arg = parent::current();
return call_user_func($this->callback, $arg);
}
}