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
fc72ff4c
Commit
fc72ff4c
authored
Jul 13, 2018
by
zhufx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
实体处理
parent
11c6b7ca
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
42 deletions
+57
-42
src/Common/Entity/CommonEntity.php
+2
-42
src/Common/Entity/CommonSplitEntity.php
+55
-0
No files found.
src/Common/Entity/CommonEntity.php
View file @
fc72ff4c
...
@@ -2,53 +2,14 @@
...
@@ -2,53 +2,14 @@
/**
/**
* Created by PhpStorm.
* Created by PhpStorm.
* User: Administrator
* User: Administrator
* Date: 2018/7/
2
* Date: 2018/7/
13
* Time: 1
3:49
* Time: 1
6:27
*/
*/
namespace
Hdll\Services\Common\Entity
;
namespace
Hdll\Services\Common\Entity
;
use
Swoft\Db\Bean\Collector\EntityCollector
;
use
Swoft\Db\Model
;
use
Swoft\Db\Model
;
class
CommonEntity
extends
Model
class
CommonEntity
extends
Model
{
{
public
function
__construct
(
array
$attributes
=
[])
{
parent
::
__construct
(
$attributes
);
$user
=
User
::
getIns
();
$dbNum
=
$user
->
getStoreId
()
%
100
;
//获取注解里的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
])
);
}
public
static
function
getDb
()
{
$user
=
User
::
getIns
();
$dbNum
=
$user
->
getStoreId
()
%
100
;
//获取注解里的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
])
);
return
new
static
();
}
}
}
\ No newline at end of file
src/Common/Entity/CommonSplitEntity.php
0 → 100644
View file @
fc72ff4c
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/7/2
* Time: 13:49
*/
namespace
Hdll\Services\Common\Entity
;
use
Swoft\Db\Bean\Collector\EntityCollector
;
class
CommonSplitEntity
extends
CommonEntity
{
public
function
__construct
(
array
$attributes
=
[])
{
parent
::
__construct
(
$attributes
);
$user
=
User
::
getIns
();
$dbNum
=
$user
->
getStoreId
()
%
100
;
//获取注解里的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
])
);
}
public
static
function
getDb
()
{
$user
=
User
::
getIns
();
$dbNum
=
$user
->
getStoreId
()
%
100
;
//获取注解里的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
])
);
return
new
static
();
}
}
\ 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