| Server IP : 127.0.0.1 / Your IP : 192.168.99.1 Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9 System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64 User : Administrator ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /laragon4/www/wa-gateway/vendor/laravel/framework/src/Illuminate/Validation/ |
Upload File : |
<?php
namespace Illuminate\Validation;
use Illuminate\Support\Fluent;
class ConditionalRules
{
/**
* The boolean condition indicating if the rules should be added to the attribute.
*
* @var callable|bool
*/
protected $condition;
/**
* The rules to be added to the attribute.
*
* @var array|string
*/
protected $rules;
/**
* The rules to be added to the attribute if the condition fails.
*
* @var array|string
*/
protected $defaultRules;
/**
* Create a new conditional rules instance.
*
* @param callable|bool $condition
* @param array|string $rules
* @param array|string $defaultRules
* @return void
*/
public function __construct($condition, $rules, $defaultRules = [])
{
$this->condition = $condition;
$this->rules = $rules;
$this->defaultRules = $defaultRules;
}
/**
* Determine if the conditional rules should be added.
*
* @param array $data
* @return bool
*/
public function passes(array $data = [])
{
return is_callable($this->condition)
? call_user_func($this->condition, new Fluent($data))
: $this->condition;
}
/**
* Get the rules.
*
* @return array
*/
public function rules()
{
return is_string($this->rules) ? explode('|', $this->rules) : $this->rules;
}
/**
* Get the default rules.
*
* @return array
*/
public function defaultRules()
{
return is_string($this->defaultRules) ? explode('|', $this->defaultRules) : $this->defaultRules;
}
}