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_CDATA.
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: CDATA.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_Processor_CDATA extends the class XML_Query2XML_Data_Processor.
19
 */
20
require_once 'XML/Query2XML/Data/Processor.php';
21
 
22
/**
23
 * Data Processor Class that creates a CDATA section around the string
24
 * returned by a pre-processor.
25
 *
26
 * XML_Query2XML_Data_Processor_CDATA only works with a pre-processor
27
 * that returns a string.
28
 *
29
 * usage:
30
 * <code>
31
 * $commandObject = new XML_Query2XML_Data_Processor_CDATA(
32
 *   new XML_Query2XML_Data_Source_ColumnValue('name')  //pre-processor
33
 * );
34
 * </code>
35
 *
36
 * @category  XML
37
 * @package   XML_Query2XML
38
 * @author    Lukas Feiler <lukas.feiler@lukasfeiler.com>
39
 * @copyright 2009 Lukas Feiler
40
 * @license   http://www.gnu.org/copyleft/lesser.html  LGPL Version 2.1
41
 * @version   Release: 1.7.2
42
 * @link      http://pear.php.net/package/XML_Query2XML
43
 * @access    private
44
 * @since     Release 1.7.1RC1
45
 */
46
class XML_Query2XML_Data_Processor_CDATA extends XML_Query2XML_Data_Processor
47
{
48
    /**
49
     * Create a new instance of this class.
50
     *
51
     * @param mixed  $preProcessor The pre-processor to be used. An instance of
52
     *                             XML_Query2XML_Data or null.
53
     * @param string $configPath   The configuration path within the $options
54
     *                             array.
55
     *
56
     * @return XML_Query2XML_Data_Processor_CDATA
57
     */
58
    public function create($preProcessor, $configPath)
59
    {
60
        $processor = new XML_Query2XML_Data_Processor_CDATA($preProcessor);
61
        $processor->setConfigPath($configPath);
62
        return $processor;
63
    }
64
 
65
    /**
66
     * Called by XML_Query2XML for every record in the result set.
67
     * This method will return an instance of DOMCDATASection or null
68
     * if an empty string was returned by the pre-processor.
69
     *
70
     * @param array $record An associative array.
71
     *
72
     * @return DOMCDATASection
73
     * @throws XML_Query2XML_ConfigException If the pre-processor returns
74
     *                      something that cannot be converted to a string (i.e. an
75
     *                      array or an object) or if no pre-processor was set.
76
     */
77
    public function execute(array $record)
78
    {
79
        $doc  = new DOMDocument();
80
        $data = $this->runPreProcessor($record);
81
        if (is_array($data) || is_object($data)) {
82
            throw new XML_Query2XML_ConfigException(
83
                $this->getConfigPath()
84
                . 'XML_Query2XML_Data_Processor_CDATA: string expected '
85
                . 'from pre-processor, but ' . gettype($data) . ' returned.'
86
            );
87
        }
88
        if (strlen($data) > 0) {
89
            return $doc->createCDATASection($data);
90
        } else {
91
            return null;
92
        }
93
    }
94
}
95
?>