master

laravel/framework

Last updated at: 29/12/2023 09:21

Factory.php

TLDR

This file provides an interface for the Factory class in the Illuminate\Contracts\Validation namespace. It defines methods for creating a new Validator instance, registering custom validator extensions, and registering custom implicit validator message replacers.

Methods

make

Creates a new Validator instance.

  • Parameters:
    • $data (array): The data to be validated.
    • $rules (array): The validation rules.
    • $messages (array, optional): Custom error messages.
    • $attributes (array, optional): Custom attribute names.
  • Returns:
    • \Illuminate\Contracts\Validation\Validator: The newly created Validator instance.

extend

Registers a custom validator extension.

  • Parameters:
    • $rule (string): The name of the rule.
    • $extension (\Closure|string): The extension to be registered.
    • $message (string|null, optional): The error message for the rule.
  • Returns:
    • void

extendImplicit

Registers a custom implicit validator extension.

  • Parameters:
    • $rule (string): The name of the rule.
    • $extension (\Closure|string): The extension to be registered.
    • $message (string|null, optional): The error message for the rule.
  • Returns:
    • void

replacer

Registers a custom implicit validator message replacer.

  • Parameters:
    • $rule (string): The name of the rule.
    • $replacer (\Closure|string): The replacer function or class.
  • Returns:
    • void
<?php

namespace Illuminate\Contracts\Validation;

interface Factory
{
    /**
     * Create a new Validator instance.
     *
     * @param  array  $data
     * @param  array  $rules
     * @param  array  $messages
     * @param  array  $attributes
     * @return \Illuminate\Contracts\Validation\Validator
     */
    public function make(array $data, array $rules, array $messages = [], array $attributes = []);

    /**
     * Register a custom validator extension.
     *
     * @param  string  $rule
     * @param  \Closure|string  $extension
     * @param  string|null  $message
     * @return void
     */
    public function extend($rule, $extension, $message = null);

    /**
     * Register a custom implicit validator extension.
     *
     * @param  string  $rule
     * @param  \Closure|string  $extension
     * @param  string|null  $message
     * @return void
     */
    public function extendImplicit($rule, $extension, $message = null);

    /**
     * Register a custom implicit validator message replacer.
     *
     * @param  string  $rule
     * @param  \Closure|string  $replacer
     * @return void
     */
    public function replacer($rule, $replacer);
}