root/trunk/ar_wrapper_generator.php

49110
6
$file = file_get_contents('../../CodeIgniter/system/database/DB_active_rec.php');
6
$file = file_get_contents('../../CodeIgniter/system/database/DB_active_rec.php');
7
7
8
// these will be prefixed by db_ and return their real return value
8
// these will be prefixed by db_ and return their real return value
9
$private = array('set','get','get_where','insert','update','empty_table','delete','truncate','use_table');
9
$private = array('set','insert','update','empty_table','delete','truncate','use_table');
10
10
11
$num = preg_match_all(
11
$num = preg_match_all(
12
			'@function(?:\s*)(\S*)\(([^\)]*)\)@'
12
			'@function(?:\s*)(\S*)\(([^\)]*)\)@'
13
				,$file,$matches,PREG_SET_ORDER);
13
				,$file,$matches,PREG_SET_ORDER);
14
14
15
echo "<pre>\nclass IR_base{\n\t".
15
echo '<pre>/**
16
'function IR_base()
16
 * Define the global var to store the models.
17
 */
18
$GLOBALS[\'IR_MODELS\'] = array();
19
20
/**
21
 * PHP 4 base for IgnitedRecord with CI\'s ActiveRecord
22
 */
23
class IR_base{
24
	
25
	/**
26
	 * Returns the model which is mapped to the table $table.
27
	 * 
28
	 * Can be called statically.
29
	 * 
30
	 * @param $table A table name
31
	 * @return object or false
32
	 */
33
	function &get_model($table)
17
	{
34
	{
18
		$CI =& get_instance();
35
		if( ! isset($GLOBALS[\'IR_MODELS\'][$table]))
19
		$this->db =& $CI->db;
36
		{
37
			$false = false;
38
			return $false;
39
		}
40
		
41
		return $GLOBALS[\'IR_MODELS\'][$table];
20
	}
42
	}
21
	
43
	
22
	// --------------------------------------------------------------------
44
	// --------------------------------------------------------------------
23
		
45
		
24
	/**
46
	/**
47
	 * Adds a model which is mapped to the $table to the internal array.
48
	 * 
49
	 * Can be called statically.
50
	 * 
51
	 * @param $object The model object
52
	 * @param $table The tablename
53
	 */
54
	function add_model(&$object, $table)
55
	{
56
		$GLOBALS[\'IR_MODELS\'][$table] =& $object;
57
	}
58
	
59
	// --------------------------------------------------------------------
60
		
61
	/**
25
	 * Resets the current query, enabling you to restart the building process
62
	 * Resets the current query, enabling you to restart the building process
26
	 * @return void
63
	 * @return void
27
	 */
64
	 */
...
...
44
		$function[1] = 'db_'.$function[1];
81
		$function[1] = 'db_'.$function[1];
45
		$is_execute = true;
82
		$is_execute = true;
46
	}
83
	}
84
	elseif(in_array($function[1], array('get', 'get_where'))
85
	{
86
		$is_execute = true;
87
	}
47
	else
88
	else
48
		// add ampersand, to aviod copies
89
		// add ampersand, to aviod copies
49
		$function[1] = '&'.$function[1];
90
		$function[1] = '&'.$function[1];