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_Base64.
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: Base64.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_Base64 extends the class
19
 * XML_Query2XML_Data_Processor.
20
 */
21
require_once 'XML/Query2XML/Data/Processor.php';
22
 
23
/**
24
 * Data Processor Class that base64-encodes the string returned by a
25
 * pre-processor.
26
 *
27
 * XML_Query2XML_Data_Processor_Base64 only works with a pre-processor
28
 * that returns a string.
29
 *
30
 * usage:
31
 * <code>
32
 * $commandObject = new XML_Query2XML_Data_Processor_Base64(
33
 *   new XML_Query2XML_Data_Source_ColumnValue('name')  //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_Base64 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_Base64
58
     */
59
    public function create($preProcessor, $configPath)
60
    {
61
        $processor = new XML_Query2XML_Data_Processor_Base64($preProcessor);
62
        $processor->setConfigPath($configPath);
63
        return $processor;
64
    }
65
 
66
    /**
67
     * Called by XML_Query2XML for every record in the result set.
68
     *
69
     * @param array $record An associative array.
70
     *
71
     * @return string The base64-encoded version the string returned
72
     *                by the pre-processor.
73
     * @throws XML_Query2XML_ConfigException If the pre-processor returns
74
     *                something that cannot be converted to a string
75
     *                (i.e. an object or an array).
76
     */
77
    public function execute(array $record)
78
    {
79
        $data = $this->runPreProcessor($record);
80
        if (is_array($data) || is_object($data)) {
81
            throw new XML_Query2XML_ConfigException(
82
                $this->getConfigPath()
83
                . ': XML_Query2XML_Data_Processor_Base64: string '
84
                . 'expected from pre-processor, but ' . gettype($data) . ' returned.'
85
            );
86
        }
87
        return base64_encode($data);
88
    }
89
}
90
?>