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
94d36efa
Commit
94d36efa
authored
Jan 19, 2019
by
王召彬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
重新toArray()
parent
e1c8d3dc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
src/Common/Entity/CommonEntity.php
+30
-0
No files found.
src/Common/Entity/CommonEntity.php
View file @
94d36efa
...
...
@@ -14,6 +14,7 @@ use Swoft\Db\Bean\Collector\EntityCollector;
use
Swoft\Db\Model
;
use
Swoft\Exception\Exception
;
use
Swoole\Http\Request
;
use
Swoft\Helper\StringHelper
;
class
CommonEntity
extends
Model
{
...
...
@@ -183,4 +184,32 @@ class CommonEntity extends Model
preg_match
(
'/(?<=Table\(name=").*(?="\))/'
,
$commentString
,
$matches
);
return
$tableName
=
isset
(
$matches
[
0
])
?
$matches
[
0
]
:
''
;
}
/**
* @return array
*/
public
function
toArray
()
:
array
{
$entities
=
EntityCollector
::
getCollector
();
$columns
=
$entities
[
static
::
class
][
'field'
];
$data
=
[];
foreach
(
$columns
as
$propertyName
=>
$column
)
{
if
(
!
isset
(
$column
[
'column'
]))
{
continue
;
}
$methodName
=
StringHelper
::
camel
(
'get'
.
$propertyName
);
if
(
!
\method_exists
(
$this
,
$methodName
))
{
continue
;
}
$value
=
$this
->
$methodName
();
if
(
$value
===
null
){
continue
;
}
$data
[
$propertyName
]
=
$value
;
}
return
$data
;
}
}
\ 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