-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMY_Loader.php
More file actions
151 lines (120 loc) · 3.18 KB
/
Copy pathMY_Loader.php
File metadata and controls
151 lines (120 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?php
/*
* Created by Martin Wernståhl on 2009-04-18.
* Copyright (c) 2009 Martin Wernståhl.
* All rights reserved.
*/
/**
* An alternative loader for CodeIgniter, loading RapidDataMapper instead of the native database abstraction.
*/
class MY_Loader extends CI_Loader
{
// ------------------------------------------------------------------------
/**
* Loads the RapidDataMapper database abstraction.
*
* @param string
* @param bool
* @param bool
* @return Db_Connection|void
*/
public function database($params = '', $return = false, $active_record = false)
{
self::initRDM();
// do we already have it instantiated?
$CI = get_instance();
if($return == false && isset($CI->db) && is_object($CI->db))
{
return false;
}
if($return)
{
return Db::getConnection($params);
}
$CI->db = '';
$CI->db = Db::getConnection($params);
$this->_ci_assign_to_models();
}
// ------------------------------------------------------------------------
/**
* A loader for the data objects and their descriptors.
*
* @param string
* @return void
*/
public static function load_data_object($class)
{
$class = strtolower($class);
if(file_exists(APPPATH . 'data_model/'.$class.EXT))
{
require APPPATH . 'data_model/'.$class.EXT;
return true;
}
}
// ------------------------------------------------------------------------
/**
* Not supported by RapidDataMapper.
*
* @return void
*/
public function dbutil()
{
show_error('CodeIgniter\' dbutil is not supported by RapidDataMapper, use the table abstraction RapidDataMapper provides instead');
}
// ------------------------------------------------------------------------
/**
* Not supported by RapidDataMapper.
*
* @return void
*/
public function dbforge()
{
show_error('CodeIgniter\' dbforge is not supported by RapidDataMapper, use the table abstraction RapidDataMapper provides instead');
}
// ------------------------------------------------------------------------
/**
* Returns the original Ci database instance.
*
* @return CI_DB
*/
public function database_original()
{
static $instance;
if($instance)
{
return $instance;
}
// Do we even need to load the database class?
if( ! class_exists('CI_DB'))
{
require_once(BASEPATH.'database/DB'.EXT);
}
return DB('', true);
}
// ------------------------------------------------------------------------
/**
* Initializes the RapidDataMapper class.
*
* @return void
*/
public static function initRDM()
{
static $defined;
if($defined !== true)
{
// load the RapidDataMapper base
require_once APPPATH.'libraries/Db.php';
include APPPATH.'config/database.php';
Db::setConnectionConfig($db);
Db::setDefaultConnectionName($active_group);
Db::setCompileMappers(isset($cache_mappers) ? $cache_mappers : false);
Db::setMapperCacheDir(APPPATH.'mappercache');
Db::initAutoload();
// register a loader for the data objects and their descriptors
spl_autoload_register(array('MY_Loader', 'load_data_object'));
$defined = true;
}
}
}
/* End of file MY_Loader.php */
/* Location: ./compat/CodeIgniter/libraries */