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