source: trunk/library/Zend/Ldap/Filter/Logical.php @ 5146

Revision 5146, 2.9 KB checked in by wmerlotto, 12 years ago (diff)

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus. Library: adicionando arquivos.

Line 
1<?php
2/**
3 * Zend Framework
4 *
5 * LICENSE
6 *
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
14 *
15 * @category   Zend
16 * @package    Zend_Ldap
17 * @subpackage Filter
18 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license    http://framework.zend.com/license/new-bsd     New BSD License
20 * @version    $Id: Logical.php 20096 2010-01-06 02:05:09Z bkarwin $
21 */
22
23/**
24 * @see Zend_Ldap_Filter_Abstract
25 */
26require_once 'Zend/Ldap/Filter/Abstract.php';
27/**
28 * @see Zend_Ldap_Filter_String
29 */
30require_once 'Zend/Ldap/Filter/String.php';
31
32/**
33 * Zend_Ldap_Filter_Logical provides a base implementation for a grouping filter.
34 *
35 * @category   Zend
36 * @package    Zend_Ldap
37 * @subpackage Filter
38 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
39 * @license    http://framework.zend.com/license/new-bsd     New BSD License
40 */
41abstract class Zend_Ldap_Filter_Logical extends Zend_Ldap_Filter_Abstract
42{
43    const TYPE_AND = '&';
44    const TYPE_OR  = '|';
45
46    /**
47     * All the sub-filters for this grouping filter.
48     *
49     * @var array
50     */
51    private $_subfilters;
52
53    /**
54     * The grouping symbol.
55     *
56     * @var string
57     */
58    private $_symbol;
59
60    /**
61     * Creates a new grouping filter.
62     *
63     * @param array  $subfilters
64     * @param string $symbol
65     */
66    protected function __construct(array $subfilters, $symbol)
67    {
68        foreach ($subfilters as $key => $s) {
69            if (is_string($s)) $subfilters[$key] = new Zend_Ldap_Filter_String($s);
70            else if (!($s instanceof Zend_Ldap_Filter_Abstract)) {
71                /**
72                 * @see Zend_Ldap_Filter_Exception
73                 */
74                require_once 'Zend/Ldap/Filter/Exception.php';
75                throw new Zend_Ldap_Filter_Exception('Only strings or Zend_Ldap_Filter_Abstract allowed.');
76            }
77        }
78        $this->_subfilters = $subfilters;
79        $this->_symbol = $symbol;
80    }
81
82    /**
83     * Adds a filter to this grouping filter.
84     *
85     * @param  Zend_Ldap_Filter_Abstract $filter
86     * @return Zend_Ldap_Filter_Logical
87     */
88    public function addFilter(Zend_Ldap_Filter_Abstract $filter)
89    {
90        $new = clone $this;
91        $new->_subfilters[] = $filter;
92        return $new;
93    }
94
95    /**
96     * Returns a string representation of the filter.
97     *
98     * @return string
99     */
100    public function toString()
101    {
102        $return = '(' . $this->_symbol;
103        foreach ($this->_subfilters as $sub) $return .= $sub->toString();
104        $return .= ')';
105        return $return;
106    }
107}
Note: See TracBrowser for help on using the repository browser.