root/trunk/midcom/midcom.helper.filesync/importer.php

Revision 17354, 2.1 kB (checked in by flack, 4 days ago)

switch to PHP5-style constructors, part 5

Line 
1 <?php
2 /**
3 * @package midcom.helper.filesync
4 * @author The Midgard Project, http://www.midgard-project.org
5 * @version $Id: viewer.php 3975 2006-09-06 17:36:03Z bergie $
6 * @copyright The Midgard Project, http://www.midgard-project.org
7 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
8 */
9
10 /**
11  * @package midcom.helper.filesync
12  */
13 class midcom_helper_filesync_importer extends midcom_baseclasses_components_purecode
14 {
15     /**
16      * Initializes the class. The real startup is done by the initialize() call.
17      *
18      * @param midcom_helper_replication_type_dba $type type
19      */
20     function midcom_helper_filesync_importer()
21     {
22          $this->_component = 'midcom.helper.filesync';
23          $this->config =& $this->_config;
24          parent::__construct();
25     }
26
27     /**
28      * This is a static factory method which lets you dynamically create importer instances.
29      * It takes care of loading the required class files. The returned instances will be created
30      * but not initialized.
31      *
32      * On any error (class not found etc.) the factory method will call generate_error.
33      *
34      * <b>This function must be called statically.</b>
35      *
36      * @param string $type type
37      * @return midcom_helper_filesync_importer A reference to the newly created importer instance.
38      * @static
39      */
40     function & create($type)
41     {
42         $filename = MIDCOM_ROOT . "/midcom/helper/filesync/importer/{$type}.php";
43
44         if (!file_exists($filename))
45         {
46             $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "Requested importer file {$type} is not installed.");
47             // This will exit.
48         }
49         require_once($filename);
50
51         $classname = "midcom_helper_filesync_importer_{$type}";
52         if (!class_exists($classname))
53         {
54             $_MIDCOM->generate_error(MIDCOM_ERRCRIT, "Requested importer class {$type} is not installed.");
55             // This will exit.
56         }
57
58         /**
59          * Php 4.4.1 does not allow you to return a reference to an expression.
60          * http://www.php.net/release_4_4_0.php
61          */
62         $class = new $classname();
63         return $class;
64     }
65 }
66 ?>
Note: See TracBrowser for help on using the browser.