/usr/share/php/Horde/Kolab/Format/Factory.php is in php-horde-kolab-format 2.0.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | <?php
/**
* Copyright 2010-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
*
* @category Kolab
* @package Kolab_Format
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://www.horde.org/libraries/Horde_Kolab_Format
*/
/**
* A factory for generating Kolab format handlers.
*
* @category Kolab
* @package Kolab_Format
* @author Gunnar Wrobel <wrobel@pardus.de>
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @link http://www.horde.org/libraries/Horde_Kolab_Format
*/
class Horde_Kolab_Format_Factory
{
/**
* Parameters for the parser construction.
*
* @var array
*/
private $_params;
/**
* Constructor.
*
* @param array $params Additional parameters for the creation of parsers.
*/
public function __construct(array $params = array())
{
$this->_params = $params;
}
/**
* Generates a handler for a specific Kolab object type.
*
* @param string $format The format that the handler should work with.
* @param string $type The object type that should be handled.
* @param array $params Additional parameters.
* <pre>
* 'version' - The format version.
* </pre>
*
* @return Horde_Kolab_Format The handler.
*
* @throws Horde_Kolab_Format_Exception If the specified handler does not
* exist.
*/
public function create($format = 'Xml', $type = '', array $params = array())
{
switch ($type) {
case 'h-ledger':
$type_class = 'Envelope';
break;
default:
$type_class = Horde_String::ucfirst(Horde_String::lower(str_replace('-', '', $type)));
break;
}
$parser = Horde_String::ucfirst(Horde_String::lower($format));
$class = basename('Horde_Kolab_Format_' . $parser . '_' . $type_class);
$params = array_merge($this->_params, $params);
if (class_exists($class)) {
switch ($parser) {
case 'Xml':
$instance = new $class($this->createXmlParser(), $this, $params);
break;
default:
throw new Horde_Kolab_Format_Exception(
sprintf(
'Failed to initialize the specified parser (Parser type %s does not exist)!',
$parser
)
);
}
} else {
throw new Horde_Kolab_Format_Exception(
sprintf(
'Failed to load the specified Kolab Format handler (Class %s does not exist)!',
$class
)
);
}
if (!empty($params['memlog'])) {
if (!class_exists('Horde_Support_Memory')) {
throw new Horde_Kolab_Format_Exception('The Horde_Support package seems to be missing (Class Horde_Support_Memory is missing)!');
}
$instance = new Horde_Kolab_Format_Decorator_Memory(
$instance,
new Horde_Support_Memory(),
$params['memlog']
);
}
if (!empty($params['timelog'])) {
if (!class_exists('Horde_Support_Timer')) {
throw new Horde_Kolab_Format_Exception('The Horde_Support package seems to be missing (Class Horde_Support_Timer is missing)!');
}
$instance = new Horde_Kolab_Format_Decorator_Timed(
$instance,
new Horde_Support_Timer(),
$params['timelog']
);
}
return $instance;
}
/**
* Generates a XML parser.
*
* @return Horde_Kolab_Format_Xml_Parser The parser.
*/
public function createXmlParser()
{
return new Horde_Kolab_Format_Xml_Parser(
new DOMDocument('1.0', 'UTF-8')
);
}
/**
* Generates a XML helper instance.
*
* @param DOMDocument $xmldoc The XML document the helper works with.
*
* @return Horde_Kolab_Format_Xml_Helper The helper utility.
*/
public function createXmlHelper(DOMDocument $xmldoc)
{
return new Horde_Kolab_Format_Xml_Helper($xmldoc);
}
/**
* Generates a XML type that deals with XML data modifications.
*
* @param string $type The value type.
* @param array $params Additional parameters.
*
* @return Horde_Kolab_Format_Xml_Type The type.
*
* @throws Horde_Kolab_Format_Exception If the specified type does not
* exist.
*/
public function createXmlType($type, $params = array())
{
if (isset($params['api-version'])) {
$class = $type . '_V' . $params['api-version'];
} else {
$class = $type;
}
if (class_exists($class)) {
return new $class($this);
} else if (class_exists($type)) {
return new $type($this);
} else {
throw new Horde_Kolab_Format_Exception(
sprintf('XML type %s not supported!', $type)
);
}
}
}
|