Repository navigation
Expand file tree
/
Copy pathModel.php
More file actions
executable file
·66 lines (63 loc) · 1.71 KB
/
Copy pathModel.php
File metadata and controls
executable file
·66 lines (63 loc) · 1.71 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
<?php
namespace Framework\Orm;
use Framework\App;
use Framework\Orm\DB;
use Framework\Exceptions\CoreHttpException;
class Model extends DB
{
/**
* 构造函数
*
* __construct
*/
public function __construct()
{
parent::__construct();
$this->getTableName();
}
/**
* 获取表名
*
* get table name
*
* @return void
*/
public function getTableName()
{
$prefix = App::$container->getSingle('config')
->config['database']['dbprefix'];
$callClassName = get_called_class();
$callClassName = explode('\\', $callClassName);
$callClassName = array_pop($callClassName);
if (! empty($this->tableName)) {
if (empty($prefix)) {
return;
}
$this->tableName = $prefix . '_' . $this->tableName;
return;
}
preg_match_all('/([A-Z][a-z]*)/', $callClassName, $match);
if (! isset($match[1][0]) || empty($match[1][0])) {
throw new CoreHttpException('model name invalid', 401);
}
$match = $match[1];
$count = count($match);
if ($count === 1) {
$this->tableName = strtolower($match[0]);
if (empty($prefix)) {
return;
}
$this->tableName = $prefix . '_' . $this->tableName;
return;
}
$last = strtolower(array_pop($match));
foreach ($match as $v) {
$this->tableName .= strtolower($v) . '_';
}
$this->tableName .= $last;
if (empty($prefix)) {
return;
}
$this->tableName = $prefix . '_' . $this->tableName;
}
}