Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加DB验证器 #146

Merged
merged 6 commits into from
Jul 31, 2018
Merged

Conversation

limingxinleo
Copy link
Contributor

FIx

2018-07-19 16:46:48 [warning] [SwoftDemoTieba] [logid:5b504ff83cf05] [spanid:0] trace[Executor.php:516,Swoft\Db\Executor::validate] 验证器不存在,beanName=DbTinyintValidator

*/
public function validate(string $column, $value, ...$params): bool
{
return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里怎么直接return?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里提了pr,就忘了说了,bitint长度比php的int最大值大,所以使用传统的is_int似乎不太合理,就想问一下,bitint的处理这里,因为平常使用bigint,都没有到过php处理的最大值。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我是想先用is_int 处理,如果是字符串,再用正则匹配,这里想问问你们的意见

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议用BCmatch 来处理bigint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wujunze 好的,谢谢,我试一下

Copy link
Contributor

@wujunze wujunze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

请补充一下单元测试

*/
public function validate(string $column, $value, ...$params): bool
{
return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接return true 是不是不太合理

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,这里我会再改一下,后面会抽空把单侧补上。

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK 单测很有必要👍

@limingxinleo
Copy link
Contributor Author

单测已经完善了。。另外bigint也处理了 😄

@huangzhhui @wujunze

@huangzhhui
Copy link
Contributor

验证抛出的文案没法自定义?

@limingxinleo
Copy link
Contributor Author

limingxinleo commented Jul 27, 2018

@huangzhhui 这里的逻辑是沿用之前DB验证器的逻辑,所以文案也是直接写死在程序里了

        // 循环验证,一个验证不通过,验证失败
        foreach ($validates as $validate) {
            $name     = $validate['name'];
            $params   = $validate['value'];
            $beanName = 'Db' . $name . 'Validator';

            // 验证器未定义
            if (!BeanFactory::hasBean($beanName)) {
                App::warning('验证器不存在,beanName=' . $beanName);
                continue;
            }

            /* @var ValidatorInterface $objValidator */
            $objValidator = App::getBean($beanName);
            $objValidator->validate($column, $propertyValue, $params);
        }

后面可以把上述的逻辑改一下,可以让用户注入自己的DB类型验证器。

另外就是,现在bean的逻辑似乎只能注入一个bean,使用者没有办法覆写官方使用的bean,比如
\Swoft\Cache\Cache

我们要不要把bean的功能再强化一下,比如设置一个level,高级别的Bean可以覆盖低级别的Bean,这样我们实例化bean的时候,就能拿到高级别的bean

@huangzhhui
Copy link
Contributor

不用设定等级,直接用户定义的配置覆盖框架定义的就好了

@huangzhhui huangzhhui merged commit bb8697f into swoft-cloud:master Jul 31, 2018
huangzhhui pushed a commit to swoft-cloud/swoft-db that referenced this pull request Jul 31, 2018
* 增加DB验证器

* bigint validate

* 增加bigint、tinyint、smallint Validator的单测

* 完善bigint Validator 以及对应单测

* 完善单测
@limingxinleo limingxinleo deleted the features/db-validator branch July 31, 2018 14:34
huangzhhui added a commit that referenced this pull request Aug 30, 2018
c51130a3 Upstream travis ci config (#160)
166a16af 修复TravisCi Build失败的BUG (#154)
b3ec7609 增加DB验证器 (#146)
a10b8629 修复Json Validator会失效的BUG (#153)
d9218a31 Fix 查询值为null时,写入模型失败的BUG (#133)

git-subtree-dir: src/db
git-subtree-split: c51130a33ab42620d652a6ccb81cb3cd0999028e
swoft-bot pushed a commit to swoft-cloud/swoft-view that referenced this pull request Jan 25, 2019
* 增加DB验证器

* bigint validate

* 增加bigint、tinyint、smallint Validator的单测

* 完善bigint Validator 以及对应单测

* 完善单测
stelin pushed a commit to swoft-cloud/swoft-db that referenced this pull request May 28, 2019
* 增加DB验证器

* bigint validate

* 增加bigint、tinyint、smallint Validator的单测

* 完善bigint Validator 以及对应单测

* 完善单测
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants