3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
20 * @subpackage backup-convert
21 * @copyright 2011 Mark Nielsen <mark@moodlerooms.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
28 * Factory class to create new instances of backup converters
30 abstract class convert_factory {
33 * Instantinates the given converter operating on a given directory
35 * @throws coding_exception
36 * @param $name The converter name
37 * @param $tempdir The temp directory to operate on
38 * @return base_converter
40 public static function converter($name, $tempdir) {
43 $name = clean_param($name, PARAM_SAFEDIR);
45 $classfile = "$CFG->dirroot/backup/converter/$name/lib.php";
46 $classname = "{$name}_converter";
48 if (!file_exists($classfile)) {
49 throw new coding_exception("Converter factory error: class file not found $classfile");
51 require_once($classfile);
53 if (!class_exists($classname)) {
54 throw new coding_exception("Converter factory error: class not found $classname");
56 return new $classname($tempdir);