CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 6.0 API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 6.0
      • 6.0
      • 5.4
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • AttributeResolver
    • Cache
    • Collection
    • Command
    • Console
    • Container
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Lock
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Class ValidationRule

ValidationRule object. Represents a validation method, error message and rules for applying such method to a field.

Namespace: Cake\Validation

Method Summary

  • __construct() public

    Constructor

  • process() public

    Dispatches the validation rule to the given validator method and returns a boolean indicating whether the rule passed or not. If a string is returned it is assumed that the rule failed and the error message was given as a result.

  • skip() protected

    Checks if the validation rule should be skipped

Method Detail

__construct() ¶ public

__construct(Closure $callable, ?string $name = null, ?string $message = null, Closure|string|null $on = null, bool $last = false, array $pass = [])

Constructor

Parameters
Closure $callable
?string $name optional
?string $message optional
Closure|string|null $on optional
bool $last optional
array $pass optional

process() ¶ public

process(mixed $value, array<string, mixed> $context = []): array|string|bool

Dispatches the validation rule to the given validator method and returns a boolean indicating whether the rule passed or not. If a string is returned it is assumed that the rule failed and the error message was given as a result.

Parameters
mixed $value

The data to validate be passed as the last argument for the validation method

array<string, mixed> $context optional

A key value list of data that could be used as context during validation. Recognized keys are:

  • newRecord: (boolean) whether the data to be validated belongs to a new record
  • data: The full data that was passed to the validation process
  • field: The name of the field that is being processed
Returns
array|string|bool
Throws
InvalidArgumentException
when the supplied rule is not a valid callable for the configured scope

skip() ¶ protected

skip(array<string, mixed> $context): bool

Checks if the validation rule should be skipped

Parameters
array<string, mixed> $context

A key value list of data that could be used as context during validation. Recognized keys are:

  • newRecord: (boolean) whether the data to be validated belongs to a new record
  • data: The full data that was passed to the validation process
  • providers associative array with objects or class names that will be passed as the last argument for the validation method
Returns
bool

True if the ValidationRule should be skipped

OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs