Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
imi
imi
提交
3ec72a08
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 搜索 >>
提交
3ec72a08
编写于
6月 18, 2021
作者:
weixin_47267244
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
模型检查字符串字段长度改为可选项
上级
682a336f
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
15 addition
and
11 deletion
+15
-11
doc/dev/generate/model.md
doc/dev/generate/model.md
+1
-0
src/Tool/Tools/Generate/Model/ModelGenerate.php
src/Tool/Tools/Generate/Model/ModelGenerate.php
+4
-1
src/Tool/Tools/Generate/Model/base-template.tpl
src/Tool/Tools/Generate/Model/base-template.tpl
+2
-2
tests/unit/Component/Model/Base/ArticleBase.php
tests/unit/Component/Model/Base/ArticleBase.php
+2
-2
tests/unit/Component/Model/Base/MemberBase.php
tests/unit/Component/Model/Base/MemberBase.php
+2
-2
tests/unit/Component/Model/Base/PerformanceBase.php
tests/unit/Component/Model/Base/PerformanceBase.php
+1
-1
tests/unit/Component/Model/Base/TestListBase.php
tests/unit/Component/Model/Base/TestListBase.php
+1
-1
tests/unit/Component/Model/Base/TestSoftDeleteBase.php
tests/unit/Component/Model/Base/TestSoftDeleteBase.php
+1
-1
tests/unit/Component/Model/Base/TreeBase.php
tests/unit/Component/Model/Base/TreeBase.php
+1
-1
未找到文件。
doc/dev/generate/model.md
浏览文件 @
3ec72a08
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
`-basePath`
指定命名空间对应的基准路径,可选
`-basePath`
指定命名空间对应的基准路径,可选
`-entity`
序列化时是否使用驼峰命名(
`true`
or
`false`
),默认
`true`
,可选
`-entity`
序列化时是否使用驼峰命名(
`true`
or
`false`
),默认
`true`
,可选
`-sqlSingleLine`
生成的SQL为单行,默认
`false`
,可选
`-sqlSingleLine`
生成的SQL为单行,默认
`false`
,可选
`-lengthCheck`
是否检查字符串字段长度,可选
示例:
示例:
...
...
src/Tool/Tools/Generate/Model/ModelGenerate.php
浏览文件 @
3ec72a08
...
@@ -37,6 +37,7 @@ class ModelGenerate
...
@@ -37,6 +37,7 @@ class ModelGenerate
* @Arg(name="basePath", type=ArgType::STRING, default=null, comments="指定命名空间对应的基准路径,可选")
* @Arg(name="basePath", type=ArgType::STRING, default=null, comments="指定命名空间对应的基准路径,可选")
* @Arg(name="entity", type=ArgType::BOOLEAN, default=true, comments="序列化时是否使用驼峰命名(true or false),默认true,可选")
* @Arg(name="entity", type=ArgType::BOOLEAN, default=true, comments="序列化时是否使用驼峰命名(true or false),默认true,可选")
* @Arg(name="sqlSingleLine", type=ArgType::BOOLEAN, default=false, comments="生成的SQL为单行,默认false,可选")
* @Arg(name="sqlSingleLine", type=ArgType::BOOLEAN, default=false, comments="生成的SQL为单行,默认false,可选")
* @Arg(name="lengthCheck", type=ArgType::BOOLEAN, default=false, comments="是否检查字符串字段长度,可选")
*
*
* @param string $namespace
* @param string $namespace
* @param string $baseClass
* @param string $baseClass
...
@@ -50,10 +51,11 @@ class ModelGenerate
...
@@ -50,10 +51,11 @@ class ModelGenerate
* @param string|null $basePath
* @param string|null $basePath
* @param bool $entity
* @param bool $entity
* @param bool $sqlSingleLine
* @param bool $sqlSingleLine
* @param bool $lengthCheck
*
*
* @return void
* @return void
*/
*/
public
function
generate
(
$namespace
,
$baseClass
,
$database
,
$poolName
,
$prefix
,
$include
,
$exclude
,
$override
,
$config
,
$basePath
,
$entity
,
$sqlSingleLine
)
public
function
generate
(
$namespace
,
$baseClass
,
$database
,
$poolName
,
$prefix
,
$include
,
$exclude
,
$override
,
$config
,
$basePath
,
$entity
,
$sqlSingleLine
,
$lengthCheck
)
{
{
$override
=
(
string
)
$override
;
$override
=
(
string
)
$override
;
switch
(
$override
)
switch
(
$override
)
...
@@ -220,6 +222,7 @@ class ModelGenerate
...
@@ -220,6 +222,7 @@ class ModelGenerate
'poolName'
=>
$poolName
,
'poolName'
=>
$poolName
,
'ddl'
=>
$ddl
,
'ddl'
=>
$ddl
,
'tableComment'
=>
''
===
$item
[
'TABLE_COMMENT'
]
?
$table
:
$item
[
'TABLE_COMMENT'
],
'tableComment'
=>
''
===
$item
[
'TABLE_COMMENT'
]
?
$table
:
$item
[
'TABLE_COMMENT'
],
'lengthCheck'
=>
$lengthCheck
,
];
];
$fields
=
$query
->
execute
(
sprintf
(
'show full columns from `%s`.`%s`'
,
$database
,
$table
))
->
getArray
();
$fields
=
$query
->
execute
(
sprintf
(
'show full columns from `%s`.`%s`'
,
$database
,
$table
))
->
getArray
();
$this
->
parseFields
(
$fields
,
$data
,
'VIEW'
===
$item
[
'TABLE_TYPE'
]);
$this
->
parseFields
(
$fields
,
$data
,
'VIEW'
===
$item
[
'TABLE_TYPE'
]);
...
...
src/Tool/Tools/Generate/Model/base-template.tpl
浏览文件 @
3ec72a08
...
@@ -65,7 +65,7 @@ abstract class <?php echo $className; ?>Base extends Model
...
@@ -65,7 +65,7 @@ abstract class <?php echo $className; ?>Base extends Model
*/
*/
public function set
<?php echo ucfirst($field['varName']); ?>
($
<?php echo $field['varName']; ?>
)
public function set
<?php echo ucfirst($field['varName']); ?>
($
<?php echo $field['varName']; ?>
)
{
{
<?php if ($length = [
<?php if ($length
Check && $length
= [
'char' => $field['length'],
'char' => $field['length'],
'varchar' => $field['length'],
'varchar' => $field['length'],
'tinyblob' => 2 ** 8 - 1,
'tinyblob' => 2 ** 8 - 1,
...
@@ -77,7 +77,7 @@ abstract class <?php echo $className; ?>Base extends Model
...
@@ -77,7 +77,7 @@ abstract class <?php echo $className; ?>Base extends Model
'longblob' => 2 ** 32 - 1,
'longblob' => 2 ** 32 - 1,
'longtext' => 2 ** 32 - 1,
'longtext' => 2 ** 32 - 1,
][$field['type']] ?? null) { ?>
][$field['type']] ?? null) { ?>
if (
isset($
<?php echo $field['varName']; ?>
[
<?php echo $length; ?>
])
)
if (
mb_strlen($
<?php echo $field['varName']; ?>
) >
<?php echo $length; ?>
)
{
{
throw new \InvalidArgumentException('The maximum length of $
<?php echo $field['varName']; ?>
is
<?php echo $length; ?>
');
throw new \InvalidArgumentException('The maximum length of $
<?php echo $field['varName']; ?>
is
<?php echo $length; ?>
');
}
}
...
...
tests/unit/Component/Model/Base/ArticleBase.php
浏览文件 @
3ec72a08
...
@@ -83,7 +83,7 @@ abstract class ArticleBase extends Model
...
@@ -83,7 +83,7 @@ abstract class ArticleBase extends Model
*/
*/
public
function
setTitle
(
$title
)
public
function
setTitle
(
$title
)
{
{
if
(
isset
(
$title
[
255
])
)
if
(
mb_strlen
(
$title
)
>
255
)
{
{
throw
new
\
InvalidArgumentException
(
'The maximum length of $title is 255'
);
throw
new
\
InvalidArgumentException
(
'The maximum length of $title is 255'
);
}
}
...
@@ -120,7 +120,7 @@ abstract class ArticleBase extends Model
...
@@ -120,7 +120,7 @@ abstract class ArticleBase extends Model
*/
*/
public
function
setContent
(
$content
)
public
function
setContent
(
$content
)
{
{
if
(
isset
(
$content
[
16777215
])
)
if
(
mb_strlen
(
$content
)
>
16777215
)
{
{
throw
new
\
InvalidArgumentException
(
'The maximum length of $content is 16777215'
);
throw
new
\
InvalidArgumentException
(
'The maximum length of $content is 16777215'
);
}
}
...
...
tests/unit/Component/Model/Base/MemberBase.php
浏览文件 @
3ec72a08
...
@@ -83,7 +83,7 @@ abstract class MemberBase extends Model
...
@@ -83,7 +83,7 @@ abstract class MemberBase extends Model
*/
*/
public
function
setUsername
(
$username
)
public
function
setUsername
(
$username
)
{
{
if
(
isset
(
$username
[
32
])
)
if
(
mb_strlen
(
$username
)
>
32
)
{
{
throw
new
\
InvalidArgumentException
(
'The maximum length of $username is 32'
);
throw
new
\
InvalidArgumentException
(
'The maximum length of $username is 32'
);
}
}
...
@@ -121,7 +121,7 @@ abstract class MemberBase extends Model
...
@@ -121,7 +121,7 @@ abstract class MemberBase extends Model
*/
*/
public
function
setPassword
(
$password
)
public
function
setPassword
(
$password
)
{
{
if
(
isset
(
$password
[
255
])
)
if
(
mb_strlen
(
$password
)
>
255
)
{
{
throw
new
\
InvalidArgumentException
(
'The maximum length of $password is 255'
);
throw
new
\
InvalidArgumentException
(
'The maximum length of $password is 255'
);
}
}
...
...
tests/unit/Component/Model/Base/PerformanceBase.php
浏览文件 @
3ec72a08
...
@@ -81,7 +81,7 @@ abstract class PerformanceBase extends Model
...
@@ -81,7 +81,7 @@ abstract class PerformanceBase extends Model
*/
*/
public
function
setValue
(
$value
)
public
function
setValue
(
$value
)
{
{
if
(
isset
(
$value
[
255
])
)
if
(
mb_strlen
(
$value
)
>
255
)
{
{
throw
new
\
InvalidArgumentException
(
'The maximum length of $value is 255'
);
throw
new
\
InvalidArgumentException
(
'The maximum length of $value is 255'
);
}
}
...
...
tests/unit/Component/Model/Base/TestListBase.php
浏览文件 @
3ec72a08
...
@@ -81,7 +81,7 @@ abstract class TestListBase extends Model
...
@@ -81,7 +81,7 @@ abstract class TestListBase extends Model
*/
*/
public
function
setList
(
$list
)
public
function
setList
(
$list
)
{
{
if
(
isset
(
$list
[
255
])
)
if
(
mb_strlen
(
$list
)
>
255
)
{
{
throw
new
\
InvalidArgumentException
(
'The maximum length of $list is 255'
);
throw
new
\
InvalidArgumentException
(
'The maximum length of $list is 255'
);
}
}
...
...
tests/unit/Component/Model/Base/TestSoftDeleteBase.php
浏览文件 @
3ec72a08
...
@@ -82,7 +82,7 @@ abstract class TestSoftDeleteBase extends Model
...
@@ -82,7 +82,7 @@ abstract class TestSoftDeleteBase extends Model
*/
*/
public
function
setTitle
(
$title
)
public
function
setTitle
(
$title
)
{
{
if
(
isset
(
$title
[
255
])
)
if
(
mb_strlen
(
$title
)
>
255
)
{
{
throw
new
\
InvalidArgumentException
(
'The maximum length of $title is 255'
);
throw
new
\
InvalidArgumentException
(
'The maximum length of $title is 255'
);
}
}
...
...
tests/unit/Component/Model/Base/TreeBase.php
浏览文件 @
3ec72a08
...
@@ -115,7 +115,7 @@ abstract class TreeBase extends Model
...
@@ -115,7 +115,7 @@ abstract class TreeBase extends Model
*/
*/
public
function
setName
(
$name
)
public
function
setName
(
$name
)
{
{
if
(
isset
(
$name
[
32
])
)
if
(
mb_strlen
(
$name
)
>
32
)
{
{
throw
new
\
InvalidArgumentException
(
'The maximum length of $name is 32'
);
throw
new
\
InvalidArgumentException
(
'The maximum length of $name is 32'
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录