1 |
efrain |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
// This file is part of Moodle - http://moodle.org/
|
|
|
4 |
//
|
|
|
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.
|
|
|
9 |
//
|
|
|
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.
|
|
|
14 |
//
|
|
|
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/>.
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* @package core
|
|
|
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
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
defined('MOODLE_INTERNAL') || die();
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Factory class to create new instances of backup converters
|
|
|
29 |
*/
|
|
|
30 |
abstract class convert_factory {
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Instantinates the given converter operating on a given directory
|
|
|
34 |
*
|
|
|
35 |
* @throws coding_exception
|
|
|
36 |
* @param $name The converter name
|
|
|
37 |
* @param $tempdir The temp directory to operate on
|
|
|
38 |
* @param base_logger|null if the conversion should be logged, use this logger
|
|
|
39 |
* @return base_converter
|
|
|
40 |
*/
|
|
|
41 |
public static function get_converter($name, $tempdir, $logger = null) {
|
|
|
42 |
global $CFG;
|
|
|
43 |
|
|
|
44 |
$name = clean_param($name, PARAM_SAFEDIR);
|
|
|
45 |
|
|
|
46 |
$classfile = "$CFG->dirroot/backup/converter/$name/lib.php";
|
|
|
47 |
$classname = "{$name}_converter";
|
|
|
48 |
|
|
|
49 |
if (!file_exists($classfile)) {
|
|
|
50 |
throw new coding_exception("Converter factory error: class file not found $classfile");
|
|
|
51 |
}
|
|
|
52 |
require_once($classfile);
|
|
|
53 |
|
|
|
54 |
if (!class_exists($classname)) {
|
|
|
55 |
throw new coding_exception("Converter factory error: class not found $classname");
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
return new $classname($tempdir, $logger);
|
|
|
59 |
}
|
|
|
60 |
}
|