~patrix-sbs/oraculum/git

« back to all changes in this revision

Viewing changes to library/components/doctrine/lib/Doctrine/Record/Filter/Compound.php

  • Committer: Patrick Kaminski
  • Date: 2009-09-02 02:33:07 UTC
  • Revision ID: git-v1:943803254fca67bfb4c0374422b1b836b14dc518
Tags: v0.1a
Sending Oraculum Framework v0.1 alpha

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
 *  $Id: Record.php 1298 2007-05-01 19:26:03Z zYne $
 
4
 *
 
5
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
6
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
7
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 
8
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
9
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 
10
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 
11
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 
12
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 
13
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
14
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
15
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
16
 *
 
17
 * This software consists of voluntary contributions made by many individuals
 
18
 * and is licensed under the LGPL. For more information, see
 
19
 * <http://www.phpdoctrine.org>.
 
20
 */
 
21
 
 
22
/**
 
23
 * Doctrine_Record_Filter_Compound
 
24
 *
 
25
 * @package     Doctrine
 
26
 * @subpackage  Record
 
27
 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
 
28
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
 
29
 * @link        www.phpdoctrine.org
 
30
 * @since       1.0
 
31
 * @version     $Revision: 1298 $
 
32
 */
 
33
class Doctrine_Record_Filter_Compound extends Doctrine_Record_Filter
 
34
{
 
35
    protected $_aliases = array();
 
36
 
 
37
    public function __construct(array $aliases)
 
38
    {
 
39
        $this->_aliases = $aliases;
 
40
    }
 
41
    public function init()
 
42
    {
 
43
        // check that all aliases exist
 
44
        foreach ($this->_aliases as $alias) {
 
45
            $this->_table->getRelation($alias);
 
46
        }
 
47
    }
 
48
 
 
49
    /**
 
50
     * filterSet
 
51
     * defines an implementation for filtering the set() method of Doctrine_Record
 
52
     *
 
53
     * @param mixed $name                       name of the property or related component
 
54
     */
 
55
    public function filterSet(Doctrine_Record $record, $name, $value)
 
56
    {
 
57
        foreach ($this->_aliases as $alias) {
 
58
            if ( ! $record->exists()) {
 
59
                if (isset($record[$alias][$name])) {
 
60
                    $record[$alias][$name] = $value;
 
61
                    
 
62
                    return $record;
 
63
                }
 
64
            } else {
 
65
                if (isset($record[$alias][$name])) {
 
66
                    $record[$alias][$name] = $value;
 
67
                }
 
68
 
 
69
                return $record;
 
70
            }
 
71
        }
 
72
        throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $name, get_class($record)));
 
73
    }
 
74
 
 
75
    /**
 
76
     * filterGet
 
77
     * defines an implementation for filtering the get() method of Doctrine_Record
 
78
     *
 
79
     * @param mixed $name                       name of the property or related component
 
80
     */
 
81
    public function filterGet(Doctrine_Record $record, $name)
 
82
    {
 
83
        foreach ($this->_aliases as $alias) {
 
84
            if ( ! $record->exists()) {
 
85
                if (isset($record[$alias][$name])) {
 
86
                    return $record[$alias][$name];
 
87
                }
 
88
            } else {
 
89
                if (isset($record[$alias][$name])) {
 
90
                    return $record[$alias][$name];
 
91
                }
 
92
            }
 
93
        }
 
94
        throw new Doctrine_Record_UnknownPropertyException(sprintf('Unknown record property / related component "%s" on "%s"', $name, get_class($record)));
 
95
    }
 
96
}
 
 
b'\\ No newline at end of file'