Subversion Repositories Applications.papyrus

Rev

Rev 1463 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1463 alexandre_ 1
<?php
2
// +----------------------------------------------------------------------+
3
// | PEAR :: I18Nv2 :: DecoratedList :: Filter                            |
4
// +----------------------------------------------------------------------+
5
// | This source file is subject to version 3.0 of the PHP license,       |
6
// | that is available at http://www.php.net/license/3_0.txt              |
7
// | If you did not receive a copy of the PHP license and are unable      |
8
// | to obtain it through the world-wide-web, please send a note to       |
9
// | license@php.net so we can mail you a copy immediately.               |
10
// +----------------------------------------------------------------------+
11
// | Copyright (c) 2004 Michael Wallner <mike@iworks.at>                  |
12
// +----------------------------------------------------------------------+
13
//
14
// $Id: Filter.php,v 1.1 2007-06-25 09:55:28 alexandre_tb Exp $
15
 
16
/**
17
 * I18Nv2::DecoratedList::Filter
18
 *
19
 * @package     I18Nv2
20
 * @category    Internationalization
21
 */
22
 
23
require_once 'I18Nv2/DecoratedList.php';
24
 
25
/**
26
 * I18Nv2_DecoratedList_Filter
27
 *
28
 * The Filter Decorator only operates on getAllCodes().
29
 *
30
 * @author      Michael Wallner <mike@php.net>
31
 * @version     $Revision: 1.1 $
32
 * @package     I18Nv2
33
 * @access      public
34
 */
35
class I18Nv2_DecoratedList_Filter extends I18Nv2_DecoratedList
36
{
37
    /**
38
     * Filter
39
     *
40
     * exclude|include resp. false|true
41
     *
42
     * @access  public
43
     * @var     mixed
44
     */
45
    var $filter = 'include';
46
 
47
    /**
48
     * Elements
49
     *
50
     * Keys that should be filtered
51
     *
52
     * @access  public
53
     * @var     array
54
     */
55
    var $elements = array();
56
 
57
    /**
58
     * decorate
59
     *
60
     * @access  protected
61
     * @return  mixed
62
     * @param   mixed   $value
63
     */
64
    function decorate($value)
65
    {
66
        if (is_array($value)) {
67
            $result = array();
68
            $filter = array_map(
69
                array(&$this->list, 'changeKeyCase'),
70
                $this->elements
71
            );
72
            switch ($this->filter)
73
            {
74
                case false:
75
                case 'exclude':
76
                    foreach ($value as $key => $val) {
77
                        if (!in_array($key, $filter)) {
78
                            $result[$key] = $val;
79
                        }
80
                    }
81
                break;
82
 
83
                case 'include':
84
                case true:
85
                    foreach ($value as $key => $val) {
86
                        if (in_array($key, $filter)) {
87
                            $result[$key] = $val;
88
                        }
89
                    }
90
                break;
91
            }
92
            return $result;
93
        }
94
        return $value;
95
    }
96
}
97
?>