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_Source_Static.
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: Static.php 276639 2009-03-01 13:17:08Z lukasfeiler $
13
 * @link      http://pear.php.net/package/XML_Query2XML
14
 * @access    private
15
 */
16
 
17
/**
18
 * XML_Query2XML_Data_Source_Static extends the class
19
 * XML_Query2XML_Data_Source.
20
 */
21
require_once 'XML/Query2XML/Data/Source.php';
22
 
23
/**
24
 * Data Source Class that allows a static value to be used as the data source.
25
 *
26
 * This command class does not accept a pre-processor.
27
 *
28
 * usage:
29
 * <code>
30
 * $commandObject = new XML_Query2XML_Data_Source_Static('my static value');
31
 * </code>
32
 *
33
 * The static value can also be an instance of DOMNode or an array of DOMNode
34
 * instances:
35
 * <code>
36
 * $commandObject = new XML_Query2XML_Data_Source_Static(new DOMElement('test'));
37
 * </code>
38
 *
39
 * @category  XML
40
 * @package   XML_Query2XML
41
 * @author    Lukas Feiler <lukas.feiler@lukasfeiler.com>
42
 * @copyright 2009 Lukas Feiler
43
 * @license   http://www.gnu.org/copyleft/lesser.html  LGPL Version 2.1
44
 * @version   Release: 1.7.2
45
 * @link      http://pear.php.net/package/XML_Query2XML
46
 * @access    private
47
 * @since     Release 1.7.1RC1
48
 */
49
class XML_Query2XML_Data_Source_Static extends XML_Query2XML_Data_Source
50
{
51
    /**
52
     * The static data.
53
     * @var mixed
54
     */
55
    private $_data = null;
56
 
57
    /**
58
     * Constructor
59
     *
60
     * @param mixed $data The static data.
61
     */
62
    public function __construct($data)
63
    {
64
        if ($data === false) {
65
            $data = '';
66
        }
67
        $this->_data = $data;
68
    }
69
 
70
    /**
71
     * Creates a new instance of this class.
72
     * This method is called by XML_Query2XML.
73
     *
74
     * @param string $data       The static data.
75
     * @param string $configPath The configuration path within the $options array.
76
     *
77
     * @return XML_Query2XML_Data_Source_Static
78
     */
79
    public function create($data, $configPath)
80
    {
81
        $source = new XML_Query2XML_Data_Source_Static($data);
82
        $source->setConfigPath($configPath);
83
        return $source;
84
    }
85
 
86
    /**
87
     * Called by XML_Query2XML for every record in the result set.
88
     *
89
     * @param array $record An associative array.
90
     *
91
     * @return mixed Whatever was passed as $data to the constructor.
92
     */
93
    public function execute(array $record)
94
    {
95
        return $this->_data;
96
    }
97
 
98
    /**
99
     * This method is called by XML_Query2XML in case the asterisk shortcut was used.
100
     *
101
     * The interface XML_Query2XML_Data_Source requires an implementation of
102
     * this method.
103
     *
104
     * @param string $columnName The column name that is to replace every occurance
105
     *                           of the asterisk character '*' in the static value,
106
     *                           in case it is a string.
107
     *
108
     * @return void
109
     */
110
    public function replaceAsterisks($columnName)
111
    {
112
        if (is_string($this->_data)) {
113
            $this->_data = str_replace('*', $columnName, $this->_data);
114
        }
115
    }
116
 
117
    /**
118
     * Returns a textual representation of this instance.
119
     * This might be useful for debugging.
120
     *
121
     * @return string
122
     */
123
    public function toString()
124
    {
125
        if (is_string($this->_data)) {
126
            $data = $this->_data;
127
        } else {
128
            $data = gettype($this->_data);
129
        }
130
        return get_class($this) . '(' . $data . ')';
131
    }
132
}
133
?>