digicomp/settingvalidator
Composer 安装命令:
composer require digicomp/settingvalidator
包简介
Just a Neos\Flow Validator resolving other Validators with Configuration/Validation.yaml
关键字:
README 文档
README
This package allows configuring validators with a new configuration type.
Introduction
This package provides the SettingsValidator which uses the configuration type Validation to resolve the validators
that should be applied to the value. It distinguishes between validators that are applied to the value itself and its
properties.
Resolving the validation configuration
The SettingsValidator has an option name. If it is set, the name is used to resolve the validation configuration,
otherwise the type of the value is used, which is mainly useful for objects where the FQCN is used.
Resolving by option name
To resolve the validation configuration by name just use the option name.
/** * @Flow\Validate(type="DigiComp.SettingValidator:Settings", options={"name"="MyNamedValidator"}) * @var MyObject */ protected MyObject $myObject;
The SettingsValidator will search for an entry inside the Validation.yaml with that name.
MyNamedValidator: ...
Resolving by type
To resolve the validation configuration by type just do not set the option name.
/** * @Flow\Validate(type="DigiComp.SettingValidator:Settings") * @var MyObject */ protected MyObject $myObject;
The SettingsValidator will search for an entry inside the Validation.yaml with the FQCN of MyObject.
My\Package\Domain\Model\MyObject: ...
The validation configuration
Difference between self and properties
self contains a map of validators that are applied to the value itself. properties contains a map with property
names of the value you would like to validate and each entry contains a map of validators that are applied to that
property.
MyNamedValidator: self: ... properties: myProperty1: ... myProperty2: ...
Configuring a validator
To configure a validator you use the type of the validator as key and the options as entries of that key. If the validator has no options or all the default values are used, set an empty map as options.
MyNamedValidator: self: 'My.Package:SomeValidator': myOption: "myOptionValue" properties: myProperty1: 'My.Package:SomeOtherValidator': {} myProperty2: 'My.Package:SomeOtherValidator': {}
Disable a validator
To disable a validator you need to set the options to null.
MyNamedValidator: self: 'My.Package:SomeValidator': ~
Using the SettingsValidator
The SettingsValidator can be used to reduce the number of @Flow\Validate annotations and gives you the possibility
of overwriting existing validation configurations in other packages.
Using on properties
Old PHP code:
/** * @Flow\Validate(type="My.Package:SomeValidator", options={"myOption"="myOptionValue"}) * @Flow\Validate(type="My.Package:SomeOtherValidator") * @var MyObject */ protected MyObject $myObject;
New PHP code:
/** * @Flow\Validate(type="DigiComp.SettingValidator:Settings", options={"name"="MyNamedValidator"}) * @var MyObject */ protected MyObject $myObject;
New validation configuration:
MyNamedValidator: self: 'My.Package:SomeValidator': myOption: "myOptionValue" 'My.Package:SomeOtherValidator': {}
Using on actions
Old PHP code:
/** * @Flow\Validate(argumentName="myObject", type="My.Package:SomeValidator", options={"myOption"="myOptionValue"}) * @Flow\Validate(argumentName="myObject", type="My.Package:SomeOtherValidator") * @param MyObject $myObject */ public function myAction(MyObject $myObject) { ... }
New PHP code:
/** * @Flow\Validate(argumentName="myObject", type="DigiComp.SettingValidator:Settings", options={"name"="MyNamedValidator"}) * @param MyObject $myObject */ public function myAction(MyObject $myObject) { ... }
New validation configuration:
MyNamedValidator: self: 'My.Package:SomeValidator': myOption: "myOptionValue" 'My.Package:SomeOtherValidator': {}
Using inside validator configurations
You can use the SettingsValidator inside the validator configuration to easily construct flexible structures.
MyNamedValidator: properties: myProperty1: 'DigiComp.SettingValidator:Settings': name: "MyOtherNamedValidator" MyOtherNamedValidator: self: 'My.Package:SomeOtherValidator': {}
Providing an empty validator
It can be useful to provide an empty validator in code that is used by many projects. By doing so you can make sure that a different validation is possible in any project.
/** * @Flow\Validate(argumentName="myObject", type="DigiComp.SettingValidator:Settings", options={"name"="MyNamedValidator"}) * @param MyObject $myObject */ public function myAction(MyObject $myObject) { ... }
MyNamedValidator: {}
digicomp/settingvalidator 适用场景与选型建议
digicomp/settingvalidator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.31k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 04 月 29 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「flow」 「validation」 「Neos」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 digicomp/settingvalidator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 digicomp/settingvalidator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 digicomp/settingvalidator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
An improved history backend module for Neos
Put images nicley in a row
Create link to static resources with cache-breaking segment based on md5 of the file
Allows changing uploaded asset filenames in Neos CMS
getting and sending flow
Adds request-parameter validation to the SLIM 3.x PHP framework
统计信息
- 总下载量: 5.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-29