rsthn / rose-ext-shield
Shield Validation Extension
Installs: 748
Dependents: 3
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:rose-extension
pkg:composer/rsthn/rose-ext-shield
Requires
- dev-master
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.1
- v3.0.0
- v2.0.19
- v2.0.18
- v2.0.17
- v2.0.16
- v2.0.15
- v2.0.14
- v2.0.13
- v2.0.12
- v2.0.11
- v2.0.10
- v2.0.9
- v2.0.8
- v2.0.7
- v2.0.6
- v2.0.5
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- 1.0.36
- 1.0.35
- 1.0.34
- 1.0.33
- 1.0.32
- 1.0.31
- 1.0.30
- 1.0.29
- 1.0.28
- 1.0.27
- 1.0.26
- 1.0.25
- 1.0.24
- 1.0.23
- 1.0.22
- 1.0.21
- 1.0.20
- 1.0.19
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
This package is auto-updated.
Last update: 2026-01-12 09:47:39 UTC
README
Shield provides a set of functions to validate data in a very robust way.
Installation
composer require rsthn/rose-ext-shield
Functions
(shield:method-required <method...>)
Ensures the request was made using the specified method(s) or fails with 405/@messages.method_not_allowed.
(shield:body-required [false|true|content-type...])
Ensures the request's content-type is one of the specified types. Fails with 422/@messages.request_body_missing if there is no
request body, or with 422/@messages.invalid_content_type if the content-type is not valid. If no content type is provided then
it is assumed to be application/json. Use value true to allow any content type.
(shield:body-min-size <min-size>)
Ensures the request's body is at least the specified number of bytes. Fails with 422/@messages.request_body_too_small if not.
(shield:body-max-size <max-size>)
Ensures the request's body does not exceed the specified number of bytes. Fails with 422/@messages.request_body_too_large when so.
(shield:ruleset [ruleset-name] <rules...>)
Registers a set of validation rules with the given name. This can later be used by name
from the use \<ruleset-name> rule.
(shield:ruleset "email" max-length 256 pattern email )
(shield:model [name] <data-descriptor>)
Registers a validation model with the given name to be used later with shield:validate.
(shield:model "Model1" (object "username" (string) "password" (string) "email" (rules required true pattern email use "verify-unique" ) ) )
(shield:validate <input-object> <model-names>...)
Validates the input data using the specified models. If any validation error occurs an exception will be thrown.
(shield:validate (gateway.body) "Model1")
(shield:validate-ctx <context-object> <input-object> <model-names>...)
Validates the input data using the specified models and passes the provided context as "$ctx" variable to all validators. Returns the validated object and its context. If any validation error occurs an exception will be thrown.
(shield:validate-ctx {} (gateway.body) "Model1") ; {"data":{},"ctx":{}}
(shield:begin)
Begins quiet validation mode. All validation errors will be accumulated, and should later be retrieved by calling shield:end,
this is useful to batch multiple validation blocks at once.
(shield:end [automatic=true])
Ends quiet validation mode, if there are any errors and automatic is set to true (default), then Wind::R_VALIDATION_ERROR will
be thrown, otherwise, the error map will just be returned.