Download the PHP package friendsofhyperf/command-validation without Composer
On this page you can find all versions of the php package friendsofhyperf/command-validation. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download friendsofhyperf/command-validation
More information about friendsofhyperf/command-validation
Files in friendsofhyperf/command-validation
Package command-validation
Short Description The command validation component for Hyperf.
License MIT
Informations about the package command-validation
Command Validation
中文说明
Validate a Hyperf command's arguments and options before the command runs.
Installation
The package requires Hyperf ~3.2.0, including hyperf/validation, and declares
no optional dependencies. Hyperf discovers the component's empty
ConfigProvider automatically, so the component has no configuration to
publish.
Usage
Add the ValidatesInput trait to a command and override rules(). You may also
override messages() and attributes() to customize validation errors.
Validation Behavior
Hyperf discovers the trait's setUpValidatesInput() hook and runs it before
the command executes. The component:
- Returns immediately when
rules()is empty. - Merges all command arguments and options into the validation data. If an argument and an option have the same key, the option value takes precedence.
- Creates a validator with the rules, messages, and attribute names supplied by the command.
- Calls
validate(). Failed validation throwsHyperf\Validation\ValidationException, so the command handler does not run.
The component ignores the validated data returned by validate() and does not
modify the command input. The handler continues to read the original argument
and option values. If the container does not provide
ValidatorFactoryInterface, validation throws a RuntimeException asking you
to install hyperf/validation.
Do not call setUpValidatesInput() directly.
Customization Methods
| Method | Purpose | Default |
|---|---|---|
rules(): array |
Validation rules for command arguments and options. | [] |
messages(): array |
Custom validation messages. | [] |
attributes(): array |
Custom display names for validated fields. | [] |
All versions of command-validation with dependencies
hyperf/context Version ~3.2.0
hyperf/di Version ~3.2.0
hyperf/stringable Version ~3.2.0
hyperf/support Version ~3.2.0
hyperf/validation Version ~3.2.0