1: <?php
2: /**
3: * Generates instances required for package.xml manipulations.
4: *
5: * PHP version 5
6: *
7: * @category Horde
8: * @package Pear
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://pear.horde.org/index.php?package=Pear
12: */
13:
14: /**
15: * Generates instances required for package.xml manipulations.
16: *
17: * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
21: *
22: * @category Horde
23: * @package Pear
24: * @author Gunnar Wrobel <wrobel@pardus.de>
25: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26: * @link http://pear.horde.org/index.php?package=Pear
27: */
28: class Horde_Pear_Package_Xml_Factory
29: {
30: /**
31: * Create an instance.
32: *
33: * @param string $type The instance type.
34: * @param array $arguments The constructor arguments.
35: *
36: * @return mixed The instance.
37: */
38: public function create($type, $arguments)
39: {
40: switch ($type) {
41: case 'Contents':
42: $class = 'Horde_Pear_Package_Xml_Contents';
43: break;
44: case 'Directory':
45: $class = 'Horde_Pear_Package_Xml_Directory';
46: break;
47: case 'ElementDirectory':
48: $class = 'Horde_Pear_Package_Xml_Element_Directory';
49: break;
50: case 'ElementFile':
51: $class = 'Horde_Pear_Package_Xml_Element_File';
52: break;
53: default:
54: throw new InvalidArgumentException(
55: sprintf('Cannot create instance for %s!', $type)
56: );
57: }
58: $reflectionObj = new ReflectionClass($class);
59: return $reflectionObj->newInstanceArgs($arguments);
60: }
61:
62: /**
63: * Create a task handler.
64: *
65: * @param string $type The task type.
66: * @param array $arguments The constructor arguments.
67: *
68: * @return Horde_Pear_Package_Task The task instance.
69: */
70: public function createTask($type, $arguments)
71: {
72: $class = 'Horde_Pear_Package_Task_' . ucfirst($type);
73: if (class_exists($class)) {
74: $reflectionObj = new ReflectionClass($class);
75: return $reflectionObj->newInstanceArgs($arguments);
76: } else {
77: throw new InvalidArgumentException(sprintf('No task %s!', $type));
78: }
79: }
80: }