forked from nazieb/elegant-orm
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathRabbitorm.php
More file actions
73 lines (51 loc) · 1.32 KB
/
Rabbitorm.php
File metadata and controls
73 lines (51 loc) · 1.32 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
<?php
use Doctrine\Common\Annotations\AnnotationReader;
use RabbitRobot\AnnotationParser\AnnotationParser;
// In CI 3 the EXT constant doesn't exist!
if(!defined('EXT'))
{
define('EXT', '.php');
}
class RabbitORM {
function __construct() {
$entity_path = APPPATH . 'entities' . DIRECTORY_SEPARATOR;
if(file_exists($entity_path)) { $this->_read_entity_dir($entity_path); }
}
/**
* @param $dirpath
*/
private function _read_entity_dir($dirpath)
{
$ci =& get_instance();
$handle = opendir($dirpath);
if(!$handle) return;
while (false !== ($filename = readdir($handle)))
{
if($filename == "." or $filename == "..") {
continue;
}
$filepath = $dirpath.$filename;
if(is_dir($filepath)) {
$this->_read_entity_dir($filepath);
} elseif(strpos(strtolower($filename), '.php') !== false)
{
require_once $filepath;
}
else { continue; }
}
closedir($handle);
}
}
spl_autoload_register(function($class){
if(strpos($class, "RabbitORM\\") === 0)
{
$classname = str_replace("RabbitORM\\", "", $class);
$path = 'RabbitORM/' . ucfirst(strtolower(str_replace("\\", DIRECTORY_SEPARATOR, $classname)) ) . EXT;
require_once $path;
}
if(strpos($class, "RabbitRobot\\") === 0)
{
$path = str_replace("\\", DIRECTORY_SEPARATOR, $class) . EXT;
require_once $path;
}
});