Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * This file contains the class XML_Query2XML_Data_Processor.
4
 *
5
 * PHP version 5
6
 *
7
 * @category  XML
8
 * @package   XML_Query2XML
9
 * @author    Lukas Feiler <lukas.feiler@lukasfeiler.com>
10
 * @copyright 2009 Lukas Feiler
11
 * @license   http://www.gnu.org/copyleft/lesser.html  LGPL Version 2.1
12
 * @version   CVS: $Id: Processor.php 309898 2011-04-02 17:38:08Z lukasfeiler $
13
 * @link      http://pear.php.net/package/XML_Query2XML
14
 */
15
 
16
/**
17
 * XML_Query2XML_Data_Processor extends XML_Query2XML_Data.
18
 */
19
require_once 'XML/Query2XML/Data.php';
20
 
21
/**
22
 * Abstract class extended by all Data Processor Classes.
23
 *
24
 * @category  XML
25
 * @package   XML_Query2XML
26
 * @author    Lukas Feiler <lukas.feiler@lukasfeiler.com>
27
 * @copyright 2009 Lukas Feiler
28
 * @license   http://www.gnu.org/copyleft/lesser.html  LGPL Version 2.1
29
 * @version   Release: 1.7.2
30
 * @link      http://pear.php.net/package/XML_Query2XML
31
 * @since     Release 1.7.1RC1
32
 */
33
abstract class XML_Query2XML_Data_Processor extends XML_Query2XML_Data
34
{
35
    /**
36
     * Another instance of XML_Query2XML_Data to process before this one.
37
     * @var XML_Query2XML_Data
38
     */
39
    private $_preProcessor = null;
40
 
41
    /**
42
     * Constructor.
43
     *
44
     * @param XML_Query2XML_Data $preProcessor The pre-processor to be used.
45
     *                                         This argument is optional.
46
     */
47
    public function __construct(XML_Query2XML_Data $preProcessor = null)
48
    {
49
        $this->setPreProcessor($preProcessor);
50
    }
51
 
52
    /**
53
     * Allows the pre-processor to be set (or changed) after an instance was
54
     * created.
55
     *
56
     * @param mixed $preProcessor The pre-processor to be used. An instance
57
     *                            of XML_Query2XML_Data or null.
58
     *
59
     * @return void
60
     */
61
    public function setPreProcessor($preProcessor)
62
    {
63
        $this->_preProcessor = $preProcessor;
64
    }
65
 
66
    /**
67
     * Returns the pre-processor.
68
     *
69
     * @return mixed XML_Query2XML_Data or null
70
     */
71
    public function getPreProcessor()
72
    {
73
        return $this->_preProcessor;
74
    }
75
 
76
    /**
77
     * Returns the first pre-processor in the chain.
78
     *
79
     * @return XML_Query2XML_Data
80
     */
81
    public function getFirstPreProcessor()
82
    {
83
        if (!is_null($this->getPreProcessor())) {
84
            return $this->getPreProcessor()->getFirstPreProcessor();
85
        }
86
        return $this;
87
    }
88
 
89
    /**
90
     * Runs the pre-processor if one was defined and returns it's return value.
91
     *
92
     * @param array $record The record to process - this is an associative array.
93
     *
94
     * @return mixed Whatever was returned by the pre-processor
95
     * @throws XML_Query2XML_ConfigException If no pre-processor was defined.
96
     */
97
    protected function runPreProcessor(array $record)
98
    {
99
        if (!is_null($this->getPreProcessor())) {
100
            return $this->getPreProcessor()->execute($record);
101
        } else {
102
            include_once 'XML/Query2XML.php';
103
            // UNIT TEST: MISSING
104
            throw new XML_Query2XML_ConfigException(
105
                $this->getConfigPath()
106
                . get_class($this) . ' requires a pre-processor.'
107
            );
108
        }
109
    }
110
 
111
    /**
112
     * Returns a textual representation of this instance.
113
     * This might be useful for debugging.
114
     *
115
     * @return string
116
     */
117
    public function toString()
118
    {
119
        $str = get_class($this) . '(';
120
        if (!is_null($this->getPreProcessor())) {
121
            $str .= $this->getPreProcessor()->toString();
122
        }
123
        return $str . ')';
124
    }
125
}
126
?>