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_ColumnValue.
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: ColumnValue.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_ColumnValue 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 the column 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_ColumnValue('name');
31
 * </code>
32
 *
33
 * @category  XML
34
 * @package   XML_Query2XML
35
 * @author    Lukas Feiler <lukas.feiler@lukasfeiler.com>
36
 * @copyright 2009 Lukas Feiler
37
 * @license   http://www.gnu.org/copyleft/lesser.html  LGPL Version 2.1
38
 * @version   Release: 1.7.2
39
 * @link      http://pear.php.net/package/XML_Query2XML
40
 * @access    private
41
 * @since     Release 1.7.1RC1
42
 */
43
class XML_Query2XML_Data_Source_ColumnValue extends XML_Query2XML_Data_Source
44
{
45
    /**
46
     * The column name.
47
     * @var string
48
     */
49
    private $_column = '';
50
 
51
    /**
52
     * Constructor
53
     *
54
     * @param string $column The name of the column.
55
     */
56
    public function __construct($column)
57
    {
58
        $this->_column = $column;
59
    }
60
 
61
    /**
62
     * Creates a new instance of this class.
63
     * This method is called by XML_Query2XML.
64
     *
65
     * @param string $column     The name of the column.
66
     * @param string $configPath The configuration path within the $options array.
67
     *                           This argument is optional.
68
     *
69
     * @return XML_Query2XML_Data_Source_ColumnValue
70
     */
71
    public function create($column, $configPath)
72
    {
73
        $source = new XML_Query2XML_Data_Source_ColumnValue($column);
74
        $source->setConfigPath($configPath);
75
        return $source;
76
    }
77
 
78
    /**
79
     * Called by XML_Query2XML for every record in the result set.
80
     *
81
     * @param array $record An associative array.
82
     *
83
     * @return mixed The contents of $record[$column] where $column is the first
84
     *               argument passed to the constructor.
85
     * @throws XML_Query2XML_ConfigException If $column does not exist in the
86
     *               result set, i.e. $record[$column] does not exist.
87
     */
88
    public function execute(array $record)
89
    {
90
        if (array_key_exists($this->_column, $record)) {
91
            return $record[$this->_column];
92
        }
93
        throw new XML_Query2XML_ConfigException(
94
            $this->getConfigPath() . 'The column "' . $this->_column
95
            . '" was not found in the result set'
96
        );
97
    }
98
 
99
    /**
100
     * This method is called by XML_Query2XML in case the asterisk shortcut was used.
101
     *
102
     * The interface XML_Query2XML_Data_Source requires an implementation of
103
     * this method.
104
     *
105
     * @param string $columnName The column name that is to replace every occurance
106
     *                           of the asterisk character '*' in $column (the first
107
     *                           argument passed to the constructor).
108
     *
109
     * @return void
110
     */
111
    public function replaceAsterisks($columnName)
112
    {
113
        $this->_column = str_replace('*', $columnName, $this->_column);
114
    }
115
 
116
    /**
117
     * Returns a textual representation of this instance.
118
     * This might be useful for debugging.
119
     *
120
     * @return string
121
     */
122
    public function toString()
123
    {
124
        return get_class($this) . '(' . $this->_column . ')';
125
    }
126
}
127
?>