Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
services
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tencent
services
Commits
0c9656ed
Commit
0c9656ed
authored
Jul 18, 2018
by
王召彬
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://git.0x00day.com:10080/hdll/hdll-services
parents
61a3c151
a813110b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
69 deletions
+77
-69
src/Common/Entity/CommonEntity.php
+77
-2
src/Common/Entity/CommonSplitEntity.php
+0
-67
No files found.
src/Common/Entity/CommonEntity.php
View file @
0c9656ed
...
...
@@ -2,14 +2,88 @@
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/7/
13
* Time: 1
6:27
* Date: 2018/7/
2
* Time: 1
3:49
*/
namespace
Hdll\Services\Common\Entity
;
use
Swoft\App
;
use
Swoft\Db\Bean\Collector\EntityCollector
;
use
Swoft\Db\Model
;
use
Swoft\Exception\Exception
;
class
CommonEntity
extends
Model
{
private
static
$commentString
;
public
function
__construct
(
array
$attributes
=
[])
{
parent
::
__construct
(
$attributes
);
//获取注解里的table
$res
=
new
\ReflectionClass
(
static
::
class
);
self
::
$commentString
=
$res
->
getDocComment
();
if
(
false
!==
strpos
(
self
::
$commentString
,
"
{
split
}
"
)
)
{
$dbNum
=
self
::
getDbNum
();
self
::
setTableName
(
$dbNum
);
}
$this
->
init
();
}
public
function
init
()
{
}
public
static
function
getDb
()
{
//获取注解里的table
$res
=
new
\ReflectionClass
(
static
::
class
);
self
::
$commentString
=
$res
->
getDocComment
();
if
(
false
!==
strpos
(
self
::
$commentString
,
"
{
split
}
"
)
)
{
$dbNum
=
self
::
getDbNum
();
self
::
setTableName
(
$dbNum
);
}
return
new
static
();
}
/**
* 获取数据库id
* @return int
* @throws Exception
*/
private
static
function
getDbNum
()
{
$user
=
App
::
getBean
(
User
::
class
);
$store
=
$user
->
getStoreId
();
if
(
empty
(
$store
)
)
{
throw
new
Exception
(
"店铺id获取失败"
);
}
return
$store
%
100
;
}
private
static
function
setTableName
(
$dbNum
)
{
preg_match
(
'/(?<=Table\(name=").*(?="\))/'
,
self
::
$commentString
,
$matches
);
$tableName
=
isset
(
$matches
[
0
])
?
$matches
[
0
]
:
''
;
EntityCollector
::
collect
(
static
::
class
,
new
\Swoft\Db\Bean\Annotation\Table
([
'name'
=>
$tableName
.
'_'
.
$dbNum
])
);
}
}
\ No newline at end of file
src/Common/Entity/CommonSplitEntity.php
deleted
100644 → 0
View file @
61a3c151
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/7/2
* Time: 13:49
*/
namespace
Hdll\Services\Common\Entity
;
use
Swoft\App
;
use
Swoft\Db\Bean\Collector\EntityCollector
;
use
Swoft\Exception\Exception
;
class
CommonSplitEntity
extends
CommonEntity
{
public
function
__construct
(
array
$attributes
=
[])
{
parent
::
__construct
(
$attributes
);
$dbNum
=
self
::
getDbNum
();
self
::
setTableName
(
$dbNum
);
}
public
static
function
getDb
()
{
$dbNum
=
self
::
getDbNum
();
self
::
setTableName
(
$dbNum
);
return
new
static
();
}
/**
* 获取数据库id
* @return int
* @throws Exception
*/
private
static
function
getDbNum
()
{
$user
=
App
::
getBean
(
User
::
class
);
$store
=
$user
->
getStoreId
();
if
(
empty
(
$store
)
)
{
throw
new
Exception
(
"店铺id获取失败"
);
}
return
$store
%
100
;
}
private
static
function
setTableName
(
$dbNum
)
{
//获取注解里的table
$res
=
new
\ReflectionClass
(
static
::
class
);
$commentString
=
$res
->
getDocComment
();
preg_match
(
'/(?<=Table\(name=").*(?="\))/'
,
$commentString
,
$matches
);
$tableName
=
isset
(
$matches
[
0
])
?
$matches
[
0
]
:
''
;
EntityCollector
::
collect
(
static
::
class
,
new
\Swoft\Db\Bean\Annotation\Table
([
'name'
=>
$tableName
.
'_'
.
$dbNum
])
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment