Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
imi
imi
提交
723ed991
imi
项目概览
imi
/
imi
9 个月 前同步成功
通知
53
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
imi
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
723ed991
编写于
6月 15, 2021
作者:
weixin_47267244
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
新增模型字段赋值,判断字符串长度
上级
f63b049f
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
130 addition
and
52 deletion
+130
-52
src/Tool/Tools/Generate/Model/base-template.tpl
src/Tool/Tools/Generate/Model/base-template.tpl
+55
-33
tests/unit/Component/Model/Base/ArticleBase.php
tests/unit/Component/Model/Base/ArticleBase.php
+9
-1
tests/unit/Component/Model/Base/MemberBase.php
tests/unit/Component/Model/Base/MemberBase.php
+9
-1
tests/unit/Component/Model/Base/PerformanceBase.php
tests/unit/Component/Model/Base/PerformanceBase.php
+5
-1
tests/unit/Component/Model/Base/TestJsonBase.php
tests/unit/Component/Model/Base/TestJsonBase.php
+8
-8
tests/unit/Component/Model/Base/TestListBase.php
tests/unit/Component/Model/Base/TestListBase.php
+5
-1
tests/unit/Component/Model/Base/TestSoftDeleteBase.php
tests/unit/Component/Model/Base/TestSoftDeleteBase.php
+4
-0
tests/unit/Component/Model/Base/TreeBase.php
tests/unit/Component/Model/Base/TreeBase.php
+5
-1
tests/unit/Component/Model/Base/UpdateTimeBase.php
tests/unit/Component/Model/Base/UpdateTimeBase.php
+1
-1
tests/unit/Component/Model/TestList.php
tests/unit/Component/Model/TestList.php
+29
-1
tests/unit/Component/Tests/ModelTest.php
tests/unit/Component/Tests/ModelTest.php
+0
-4
未找到文件。
src/Tool/Tools/Generate/Model/base-template.tpl
浏览文件 @
723ed991
<?
= '<?php'
?>
<?
php echo '<?php';
?>
namespace
<?
= $namespace
?>
\Base;
namespace
<?
php echo $namespace;
?>
\Base;
use
<?
= $baseClassName
?>
as Model;
use
<?
php echo $baseClassName;
?>
as Model;
use Imi\Model\Annotation\DDL;
use Imi\Model\Annotation\Table;
use Imi\Model\Annotation\Column;
use Imi\Model\Annotation\Entity;
/**
*
<?= $tableComment ?>
基类
*
<?php if($entity === true):?>
@Entity
<?php else:?>
@Entity(false)
<?php endif;?>
*
<?php echo $tableComment; ?>
基类
*
<?php if (true === $entity) { ?>
@Entity
<?php }
else
{ ?>
@Entity(false)
<?php }?>
* @Table(name="
<?
= $table['name'] ?>
"
<?php if(isset($table['id'][0])):?>
, id={
<?= '"', implode('", "', $table['id']), '"' ?>
}
<?php endif;?><?php if($poolName):?>
, dbPoolName="
<?=$poolName?>
"
<?php endif;
?>
)
* @DDL("
<?
= str_replace('"', '""', $ddl)
?>
")
<?php foreach
($fields as $field):
?>
* @property
<?
= $field['phpType'] ?>
$
<?= $field['varName'] ?>
<?= '' === $field['comment'] ? '' : $field['comment']
?>
* @Table(name="
<?
php echo $table['name']; ?>
"
<?php if (isset($table['id'][0])) { ?>
, id={
<?php echo '"', implode('", "', $table['id']), '"'; ?>
}
<?php }?><?php if ($poolName) { ?>
, dbPoolName="
<?php echo $poolName; ?>
"
<?php }
?>
)
* @DDL("
<?
php echo str_replace('"', '""', $ddl);
?>
")
<?php foreach
($fields as $field) {
?>
* @property
<?
php echo $field['phpType']; ?>
$
<?php echo $field['varName']; ?>
<?php echo '' === $field['comment'] ? '' : $field['comment'];
?>
<?php
endforeach;
?>
<?php
}
?>
*/
abstract class
<?
= $className
?>
Base extends Model
abstract class
<?
php echo $className;
?>
Base extends Model
{
<?php
foreach($fields as $field):
?>
foreach ($fields as $field)
{
?>
/**
<?php if('' === $field['comment']):?>
*
<?= $field['name'] ?>
<?php else: ?>
*
<?= $field['comment'] ?>
<?php if ('' === $field['comment']) { ?>
*
<?php echo $field['name']; ?>
<?php }
else
{ ?>
*
<?php echo $field['comment']; ?>
*
<?
= $field['name']
?>
<?php
endif;
?>
*
<?
php echo $field['name'];
?>
<?php
}
?>
* @Column(name="
<?
= $field['name'] ?>
", type="
<?= $field['type'] ?>
", length=
<?= $field['length'] ?>
, accuracy=
<?= $field['accuracy'] ?>
, nullable=
<?= json_encode($field['nullable']) ?>
, default="
<?= $field['default'] ?>
", isPrimaryKey=
<?= json_encode($field['isPrimaryKey']) ?>
, primaryKeyIndex=
<?= $field['primaryKeyIndex'] ?>
, isAutoIncrement=
<?= json_encode($field['isAutoIncrement'])
?>
)
* @var
<?
= $field['phpType']
?>
* @Column(name="
<?
php echo $field['name']; ?>
", type="
<?php echo $field['type']; ?>
", length=
<?php echo $field['length']; ?>
, accuracy=
<?php echo $field['accuracy']; ?>
, nullable=
<?php echo json_encode($field['nullable']); ?>
, default="
<?php echo $field['default']; ?>
", isPrimaryKey=
<?php echo json_encode($field['isPrimaryKey']); ?>
, primaryKeyIndex=
<?php echo $field['primaryKeyIndex']; ?>
, isAutoIncrement=
<?php echo json_encode($field['isAutoIncrement']);
?>
)
* @var
<?
php echo $field['phpType'];
?>
*/
protected $
<?
= $field['varName']
?>
;
protected $
<?
php echo $field['varName'];
?>
;
/**
* 获取
<?
= $field['varName'] ?><?= '' === $field['comment'] ? '' : (' - ' . $field['comment'])
?>
* 获取
<?
php echo $field['varName']; ?><?php echo '' === $field['comment'] ? '' : (' - ' . $field['comment']);
?>
*
* @return
<?
= $field['phpType']
?>
* @return
<?
php echo $field['phpType'];
?>
*/
public function get
<?
= ucfirst($field['varName'])
?>
()
*/
public function get
<?
php echo ucfirst($field['varName']);
?>
()
{
return $this->
<?
= $field['varName']
?>
;
return $this->
<?
php echo $field['varName'];
?>
;
}
/**
* 赋值
<?
= $field['varName'] ?><?= '' === $field['comment'] ? '' : (' - ' . $field['comment'])
?>
* 赋值
<?
php echo $field['varName']; ?><?php echo '' === $field['comment'] ? '' : (' - ' . $field['comment']);
?>
* @param
<?
= $field['phpType'] ?>
$
<?= $field['varName'] ?>
<?= $field['name']
?>
* @param
<?
php echo $field['phpType']; ?>
$
<?php echo $field['varName']; ?>
<?php echo $field['name'];
?>
* @return static
*/
public function set
<?
= ucfirst($field['varName']) ?>
($
<?= $field['varName']
?>
)
*/
public function set
<?
php echo ucfirst($field['varName']); ?>
($
<?php echo $field['varName'];
?>
)
{
$this->
<?= $field['varName'] ?>
= $
<?= $field['varName'] ?>
;
<?php if ($length = [
'char' => $field['length'],
'varchar' => $field['length'],
'tinyblob' => 2 ^ 8 - 1,
'tinytext' => 2 ^ 8 - 1,
'blob' => 2 ^ 16 - 1,
'text' => 2 ^ 16 - 1,
'mediumblob' => 2 ^ 24 - 1,
'mediumtext' => 2 ^ 24 - 1,
'longblob' => 2 ^ 32 - 1,
'longtext' => 2 ^ 32 - 1,
][$field['type']] ?? null) { ?>
if (isset($
<?php echo $field['varName']; ?>
[
<?php echo $length - 1; ?>
]))
{
throw new \InvalidArgumentException('The maximum length of $
<?php echo $field['varName']; ?>
is
<?php echo $length; ?>
');
}
<?php } ?>
$this->
<?php echo $field['varName']; ?>
= $
<?php echo $field['varName']; ?>
;
return $this;
}
<?php
endforeach;
}
?>
}
tests/unit/Component/Model/Base/ArticleBase.php
浏览文件 @
723ed991
...
...
@@ -6,7 +6,7 @@ use Imi\Model\Annotation\Column;
use
Imi\Model\Annotation\DDL
;
use
Imi\Model\Annotation\Entity
;
use
Imi\Model\Annotation\Table
;
use
Imi\Model\Model
;
use
Imi\Model\Model
as
Model
;
/**
* tb_article 基类.
...
...
@@ -83,6 +83,10 @@ abstract class ArticleBase extends Model
*/
public
function
setTitle
(
$title
)
{
if
(
isset
(
$title
[
254
]))
{
throw
new
\
InvalidArgumentException
(
'The maximum length of $title is 255'
);
}
$this
->
title
=
$title
;
return
$this
;
...
...
@@ -116,6 +120,10 @@ abstract class ArticleBase extends Model
*/
public
function
setContent
(
$content
)
{
if
(
isset
(
$content
[
20
]))
{
throw
new
\
InvalidArgumentException
(
'The maximum length of $content is 21'
);
}
$this
->
content
=
$content
;
return
$this
;
...
...
tests/unit/Component/Model/Base/MemberBase.php
浏览文件 @
723ed991
...
...
@@ -6,7 +6,7 @@ use Imi\Model\Annotation\Column;
use
Imi\Model\Annotation\DDL
;
use
Imi\Model\Annotation\Entity
;
use
Imi\Model\Annotation\Table
;
use
Imi\Model\Model
;
use
Imi\Model\Model
as
Model
;
/**
* tb_member 基类.
...
...
@@ -83,6 +83,10 @@ abstract class MemberBase extends Model
*/
public
function
setUsername
(
$username
)
{
if
(
isset
(
$username
[
31
]))
{
throw
new
\
InvalidArgumentException
(
'The maximum length of $username is 32'
);
}
$this
->
username
=
$username
;
return
$this
;
...
...
@@ -117,6 +121,10 @@ abstract class MemberBase extends Model
*/
public
function
setPassword
(
$password
)
{
if
(
isset
(
$password
[
254
]))
{
throw
new
\
InvalidArgumentException
(
'The maximum length of $password is 255'
);
}
$this
->
password
=
$password
;
return
$this
;
...
...
tests/unit/Component/Model/Base/PerformanceBase.php
浏览文件 @
723ed991
...
...
@@ -6,7 +6,7 @@ use Imi\Model\Annotation\Column;
use
Imi\Model\Annotation\DDL
;
use
Imi\Model\Annotation\Entity
;
use
Imi\Model\Annotation\Table
;
use
Imi\Model\Model
;
use
Imi\Model\Model
as
Model
;
/**
* tb_performance 基类.
...
...
@@ -81,6 +81,10 @@ abstract class PerformanceBase extends Model
*/
public
function
setValue
(
$value
)
{
if
(
isset
(
$value
[
254
]))
{
throw
new
\
InvalidArgumentException
(
'The maximum length of $value is 255'
);
}
$this
->
value
=
$value
;
return
$this
;
...
...
tests/unit/Component/Model/Base/TestJsonBase.php
浏览文件 @
723ed991
...
...
@@ -6,17 +6,17 @@ use Imi\Model\Annotation\Column;
use
Imi\Model\Annotation\DDL
;
use
Imi\Model\Annotation\Entity
;
use
Imi\Model\Annotation\Table
;
use
Imi\Model\Model
;
use
Imi\Model\Model
as
Model
;
/**
* tb_test_json 基类.
*
* @Entity
* @Table(name="tb_test_json", id={"id"})
* @DDL("CREATE TABLE `tb_test_json` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `json_data`
text
NOT NULL COMMENT 'json数据', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8")
* @DDL("CREATE TABLE `tb_test_json` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `json_data`
json
NOT NULL COMMENT 'json数据', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8")
*
* @property int $id
* @property
string
$jsonData json数据
* @property int
$id
* @property
\Imi\Util\LazyArrayObject
$jsonData json数据
*/
abstract
class
TestJsonBase
extends
Model
{
...
...
@@ -57,16 +57,16 @@ abstract class TestJsonBase extends Model
* json数据
* json_data.
*
* @Column(name="json_data", type="
text
", length=0, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false)
* @Column(name="json_data", type="
json
", length=0, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false)
*
* @var
string
* @var
\Imi\Util\LazyArrayObject
*/
protected
$jsonData
;
/**
* 获取 jsonData - json数据.
*
* @return
string
* @return
\Imi\Util\LazyArrayObject
*/
public
function
getJsonData
()
{
...
...
@@ -76,7 +76,7 @@ abstract class TestJsonBase extends Model
/**
* 赋值 jsonData - json数据.
*
* @param
string
$jsonData json_data
* @param
\Imi\Util\LazyArrayObject
$jsonData json_data
*
* @return static
*/
...
...
tests/unit/Component/Model/Base/TestListBase.php
浏览文件 @
723ed991
...
...
@@ -6,7 +6,7 @@ use Imi\Model\Annotation\Column;
use
Imi\Model\Annotation\DDL
;
use
Imi\Model\Annotation\Entity
;
use
Imi\Model\Annotation\Table
;
use
Imi\Model\Model
;
use
Imi\Model\Model
as
Model
;
/**
* tb_test_list 基类.
...
...
@@ -81,6 +81,10 @@ abstract class TestListBase extends Model
*/
public
function
setList
(
$list
)
{
if
(
isset
(
$list
[
254
]))
{
throw
new
\
InvalidArgumentException
(
'The maximum length of $list is 255'
);
}
$this
->
list
=
$list
;
return
$this
;
...
...
tests/unit/Component/Model/Base/TestSoftDeleteBase.php
浏览文件 @
723ed991
...
...
@@ -82,6 +82,10 @@ abstract class TestSoftDeleteBase extends Model
*/
public
function
setTitle
(
$title
)
{
if
(
isset
(
$title
[
254
]))
{
throw
new
\
InvalidArgumentException
(
'The maximum length of $title is 255'
);
}
$this
->
title
=
$title
;
return
$this
;
...
...
tests/unit/Component/Model/Base/TreeBase.php
浏览文件 @
723ed991
...
...
@@ -6,7 +6,7 @@ use Imi\Model\Annotation\Column;
use
Imi\Model\Annotation\DDL
;
use
Imi\Model\Annotation\Entity
;
use
Imi\Model\Annotation\Table
;
use
Imi\Model\Model
;
use
Imi\Model\Model
as
Model
;
/**
* tb_tree 基类.
...
...
@@ -115,6 +115,10 @@ abstract class TreeBase extends Model
*/
public
function
setName
(
$name
)
{
if
(
isset
(
$name
[
31
]))
{
throw
new
\
InvalidArgumentException
(
'The maximum length of $name is 32'
);
}
$this
->
name
=
$name
;
return
$this
;
...
...
tests/unit/Component/Model/Base/UpdateTimeBase.php
浏览文件 @
723ed991
...
...
@@ -6,7 +6,7 @@ use Imi\Model\Annotation\Column;
use
Imi\Model\Annotation\DDL
;
use
Imi\Model\Annotation\Entity
;
use
Imi\Model\Annotation\Table
;
use
Imi\Model\Model
;
use
Imi\Model\Model
as
Model
;
/**
* tb_update_time 基类.
...
...
tests/unit/Component/Model/TestList.php
浏览文件 @
723ed991
...
...
@@ -20,7 +20,35 @@ class TestList extends TestListBase
*
* @Column(name="list", type="list", listSeparator=",", length=255, accuracy=0, nullable=false, default="", isPrimaryKey=false, primaryKeyIndex=-1, isAutoIncrement=false)
*
* @var
string
* @var
array
*/
protected
$list
;
/**
* 获取 list.
*
* @phpstan-ignore-next-line
*
* @return array
*/
public
function
getList
()
{
return
$this
->
list
;
}
/**
* 赋值 list.
*
* @phpstan-ignore-next-line
*
* @param array $list list
*
* @return static
*/
public
function
setList
(
$list
)
{
$this
->
list
=
$list
;
return
$this
;
}
}
tests/unit/Component/Tests/ModelTest.php
浏览文件 @
723ed991
...
...
@@ -447,7 +447,6 @@ class ModelTest extends BaseTest
'id'
=>
null
,
'jsonData'
=>
[
1
,
2
,
3
],
],
$record
->
convertToArray
());
// @phpstan-ignore-next-line
$this
->
assertEquals
([
1
,
2
,
3
],
$record
->
getJsonData
()
->
toArray
());
$id
=
$record
->
insert
()
->
getLastInsertId
();
$this
->
assertGreaterThan
(
0
,
$id
);
...
...
@@ -456,7 +455,6 @@ class ModelTest extends BaseTest
'id'
=>
$id
,
'jsonData'
=>
[
1
,
2
,
3
],
],
$record
->
convertToArray
());
// @phpstan-ignore-next-line
$this
->
assertEquals
([
1
,
2
,
3
],
$record
->
getJsonData
()
->
toArray
());
$list
=
TestJson
::
query
()
->
where
(
'id'
,
'='
,
$id
)
->
select
()
->
getArray
();
$this
->
assertEquals
([[
...
...
@@ -471,7 +469,6 @@ class ModelTest extends BaseTest
'id'
=>
null
,
'json_data'
=>
[
4
,
5
,
6
],
],
$record
->
convertToArray
());
// @phpstan-ignore-next-line
$this
->
assertEquals
([
4
,
5
,
6
],
$record
->
getJsonData
()
->
toArray
());
$id
=
$record
->
insert
()
->
getLastInsertId
();
$this
->
assertGreaterThan
(
0
,
$id
);
...
...
@@ -480,7 +477,6 @@ class ModelTest extends BaseTest
'id'
=>
$id
,
'json_data'
=>
[
4
,
5
,
6
],
],
$record
->
convertToArray
());
// @phpstan-ignore-next-line
$this
->
assertEquals
([
4
,
5
,
6
],
$record
->
getJsonData
()
->
toArray
());
$list
=
TestJsonNotCamel
::
query
()
->
where
(
'id'
,
'='
,
$id
)
->
select
()
->
getArray
();
$this
->
assertEquals
([[
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录