ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilImportExportFactory.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3
11{
12 const PLUGINS_DIR = "Plugins";
13
14 public static function getExporterClass($a_type)
15 {
19 global $DIC;
20
21 $objDefinition = $DIC['objDefinition'];
22
23 if ($objDefinition->isPlugin($a_type)) {
24 $classname = 'il' . $objDefinition->getClassName($a_type) . 'Exporter';
25 $location = $objDefinition->getLocation($a_type);
26 if (include_once $location . '/class.' . $classname . '.php') {
27 return $classname;
28 }
29 } else {
30 $comp = $objDefinition->getComponentForType($a_type);
31 $class = array_pop(explode("/", $comp));
32 $class = "il" . $class . "Exporter";
33
34 // page component plugin exporter classes are already included
35 // the component is not registered by ilObjDefinition
36 if (class_exists($class)) {
37 return $class;
38 }
39
40 // the next line had a "@" in front of the include_once
41 // I removed this because it tages ages to track down errors
42 // if the include class contains parse errors.
43 // Alex, 20 Jul 2012
44 if (include_once "./" . $comp . "/classes/class." . $class . ".php") {
45 return $class;
46 }
47 }
48
49 throw new InvalidArgumentException('Invalid exporter type given');
50 }
51
52 public static function getComponentForExport($a_type)
53 {
57 global $DIC;
58
59 $objDefinition = $DIC['objDefinition'];
60
61 if ($objDefinition->isPlugin($a_type)) {
62 return self::PLUGINS_DIR . "/" . $a_type;
63 } else {
64 return $objDefinition->getComponentForType($a_type);
65 }
66 }
67
75 public static function getImporterClass($a_component)
76 {
80 global $DIC;
81 $objDefinition = $DIC['objDefinition'];
82
83 $parts = explode('/', $a_component);
84 $component_type = $parts[0];
85 $component = $parts[1];
86
87 if ($component_type == self::PLUGINS_DIR &&
88 $objDefinition->isPlugin($component)) {
89 $classname = 'il' . $objDefinition->getClassName($component) . 'Importer';
90 $location = $objDefinition->getLocation($component);
91 if (include_once $location . '/class.' . $classname . '.php') {
92 return $classname;
93 }
94 } else {
95 $class = "il" . $component . "Importer";
96 // treat special case of page component plugins
97 // they are imported with component type PLUGINS_DIR
98 // but are not yet recognized by ilObjDefinition::isPlugin()
99 //
100 // if they are active, then their importer class is already included by ilCOPageImporter::init()
101 if (class_exists($class)) {
102 return $class;
103 }
104 // the page component plugin is not installed or not active
105 // return an empty class name instead of throwing an exception
106 // in this case the import should be continued without treating the page component
107 elseif ($component_type == self::PLUGINS_DIR) {
108 return "";
109 }
110
111 if (is_file("./" . $a_component . "/classes/class." . $class . ".php")) {
112 return $class;
113 }
114 }
115
116 throw new InvalidArgumentException('Invalid importer type given: ' . "./" . $a_component . "/classes/class." . $class . ".php");
117 }
118}
$location
Definition: buildRTE.php:44
An exception for terminatinating execution or to throw for unit testing.
Factory for importer/exporter implementers.
global $DIC
Definition: saml.php:7
$a_type
Definition: workflow.php:92