1<?php
2/**
3 * An example of defining a new Kolab format type
4 *
5 * PHP version 5
6 *
7 * @category Kolab
8 * @package  Kolab_Format
9 * @author   Gunnar Wrobel <wrobel@pardus.de>
10 * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
11 * @link     http://www.horde.org/libraries/Horde_Kolab_Format
12 */
13
14/**
15 * The Autoloader allows us to omit "require/include" statements.
16 */
17require_once 'Horde/Autoloader/Default.php';
18
19/**
20 * Kolab XML handler for a string value
21 *
22 * Copyright 2008-2016 Horde LLC (http://www.horde.org/)
23 *
24 * See the enclosed file COPYING for license information (LGPL). If you
25 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
26 *
27 * @category Kolab
28 * @package  Kolab_Format
29 * @author   Gunnar Wrobel <wrobel@pardus.de>
30 * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
31 * @link     http://www.horde.org/libraries/Horde_Kolab_Format
32 */
33class Horde_Kolab_Format_Xml_String extends Horde_Kolab_Format_Xml
34{
35
36    /**
37     * Specific data fields for the prefs object
38     *
39     * @var Kolab
40     */
41    protected $_fields_specific;
42
43    /**
44     * Constructor
45     */
46    public function __construct($parser, $params = array())
47    {
48        $this->_root_name = 'string';
49
50        /** Specific preferences fields, in kolab format specification order
51         */
52        $this->_fields_specific = array(
53            'string' => array(
54                'type' => self::TYPE_STRING,
55                'value' => self::VALUE_MAYBE_MISSING,
56            ),
57        );
58
59        parent::__construct($parser, $params);
60    }
61}
62
63/** Create the factory */
64$factory = new Horde_Kolab_Format_Factory();
65
66/** Generate the format handler */
67$format = $factory->create('Xml', 'String');
68
69/** Prepare a test object */
70$object = array(
71    'uid' => 1,
72    'string' => 'test string',
73);
74
75/** Save this test data array in Kolab XML format */
76$xml = $format->save($object);
77var_dump($xml);
78
79/** Reload the object from the XML format */
80$read_object = $format->load($xml);
81var_dump($read_object);
82
83