Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Annotation/AbstractValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@

namespace Ray\WebFormModule\Annotation;

/**
* Base of the attributes that validate the input with a form before the method runs
*/
abstract class AbstractValidation
{
/** @param string $form Name of the property that holds the form */
public function __construct(public string $form = 'form')
{
}
Expand Down
5 changes: 5 additions & 0 deletions src/Annotation/CsrfProtection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@

use Attribute;

/**
* Makes the validating form check the CSRF token and throw CsrfViolationException on mismatch
*
* @see https://bearsunday.github.io/manuals/1.0/en/form.html#csrf-protections
*/
#[Attribute(Attribute::TARGET_METHOD)]
final class CsrfProtection
{
Expand Down
11 changes: 11 additions & 0 deletions src/Annotation/FormValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@

use Attribute;

/**
* Validates the input with the form before the method runs and hands a failure to the failure handler
*
* @see https://bearsunday.github.io/manuals/1.0/en/form.html#controller
* @see \Ray\WebFormModule\AuraInputInterceptor
*/
#[Attribute(Attribute::TARGET_METHOD)]
final class FormValidation extends AbstractValidation
{
/**
* @param string $form Name of the property that holds the form
* @param string|null $onFailure Method called on failure, `<method>ValidationFailed` when null;
* FormVndErrorModule throws ValidationException without calling it
*/
public function __construct(
string $form = 'form',
public string|null $onFailure = null,
Expand Down
6 changes: 6 additions & 0 deletions src/Annotation/InputValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

use Attribute;

/**
* Validates the input with the form before the method runs and throws ValidationException on failure
*
* @see https://bearsunday.github.io/manuals/1.0/en/form.html#validation-exception
* @see \Ray\WebFormModule\InputValidationInterceptor
*/
#[Attribute(Attribute::TARGET_METHOD)]
final class InputValidation extends AbstractValidation
{
Expand Down
8 changes: 7 additions & 1 deletion src/Annotation/VndError.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@

use Attribute;

/**
* Sets the message, path, logref and links of the vnd.error body when validation fails
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
* VndErrorHandler reads it for #[InputValidation], and for #[FormValidation] when FormVndErrorModule is installed
*
* @see https://bearsunday.github.io/manuals/1.0/en/form.html#validation-exception
*/
#[Attribute(Attribute::TARGET_METHOD)]
final class VndError
{
/**
* @param array<string, mixed> $href
* @param array<string, mixed> $href URIs keyed by link relation, e.g. `help`
*
* @see http://www.w3.org/TR/html5/links.html#link-type-help
* @see http://tools.ietf.org/html/rfc6903#section-2
Expand Down
Loading