라라벨 Validator

개요[ | ]

라라벨 Validator
<?php
namespace Illuminate\Validation;
use Closure;
use DateTime;
use Countable;
use Exception;
use DateTimeZone;
use RuntimeException;
use DateTimeInterface;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use BadMethodCallException;
use InvalidArgumentException;
use Illuminate\Support\Fluent;
use Illuminate\Support\MessageBag;
use Illuminate\Contracts\Container\Container;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Translation\TranslatorInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Illuminate\Contracts\Validation\Validator as ValidatorContract;
class Validator implements ValidatorContract
{
    protected $translator;
    protected $presenceVerifier;
    protected $container;
    protected $failedRules = [];
    protected $messages;
    protected $data;
    protected $files = [];
    protected $initialRules;
    protected $rules;
    protected $implicitAttributes = [];
    protected $after = [];
    protected $customMessages = [];
    protected $fallbackMessages = [];
    protected $customAttributes = [];
    protected $customValues = [];
    protected $extensions = [];
    protected $replacers = [];
    protected $sizeRules = ['Size', 'Between', 'Min', 'Max'];
    protected $numericRules = ['Numeric', 'Integer'];
    protected $implicitRules = [
        'Required', 'Filled', 'RequiredWith', 'RequiredWithAll', 'RequiredWithout', 'RequiredWithoutAll',
        'RequiredIf', 'RequiredUnless', 'Accepted', 'Present',
            ];
    protected $dependentRules = [
        'RequiredWith', 'RequiredWithAll', 'RequiredWithout', 'RequiredWithoutAll',
        'RequiredIf', 'RequiredUnless', 'Confirmed', 'Same', 'Different', 'Unique',
        'Before', 'After',
    ];
    public function __construct(TranslatorInterface $translator, array $data, array $rules, array $messages = [], array $customAttributes = [])
    {
        $this->translator = $translator;
        $this->customMessages = $messages;
        $this->data = $this->parseData($data);
        $this->customAttributes = $customAttributes;
        $this->initialRules = $rules;
        $this->setRules($rules);
    }
    protected function parseData(array $data, $arrayKey = null)
    {
        if (is_null($arrayKey)) {
            $this->files = [];
        }
        foreach ($data as $key => $value) {
            $key = ($arrayKey) ? "$arrayKey.$key" : $key;
                                                if ($value instanceof File) {
                $this->files[$key] = $value;
                unset($data[$key]);
            } elseif (is_array($value)) {
                $this->parseData($value, $key);
            }
        }
        return $data;
    }
    protected function explodeRules($rules)
    {
        foreach ($rules as $key => $rule) {
            if (Str::contains($key, '*')) {
                $this->each($key, [$rule]);
                unset($rules[$key]);
            } else {
                $rules[$key] = (is_string($rule)) ? explode('|', $rule) : $rule;
            }
        }
        return $rules;
    }
    public function after($callback)
    {
        $this->after[] = function () use ($callback) {
            return call_user_func_array($callback, [$this]);
        };
        return $this;
    }
    public function sometimes($attribute, $rules, callable $callback)
    {
        $payload = new Fluent($this->attributes());
        if (call_user_func($callback, $payload)) {
            foreach ((array) $attribute as $key) {
                if (Str::contains($key, '*')) {
                    $this->explodeRules([$key => $rules]);
                } else {
                    $this->mergeRules($key, $rules);
                }
            }
        }
    }
    public function each($attribute, $rules)
    {
        $data = Arr::dot($this->initializeAttributeOnData($attribute));
        $pattern = str_replace('\*', '[^\.]+', preg_quote($attribute));
        $data = array_merge($data, $this->extractValuesForWildcards(
            $data, $attribute
        ));
        foreach ($data as $key => $value) {
            if (Str::startsWith($key, $attribute) || (bool) preg_match('/^'.$pattern.'\z/', $key)) {
                foreach ((array) $rules as $ruleKey => $ruleValue) {
                    if (! is_string($ruleKey) || Str::endsWith($key, $ruleKey)) {
                        $this->implicitAttributes[$attribute][] = $key;
                        $this->mergeRules($key, $ruleValue);
                    }
                }
            }
        }
    }
    protected function initializeAttributeOnData($attribute)
    {
        $explicitPath = $this->getLeadingExplicitAttributePath($attribute);
        $data = $this->extractDataFromPath($explicitPath);
        if (! Str::contains($attribute, '*') || Str::endsWith($attribute, '*')) {
            return $data;
        }
        return data_set($data, $attribute, null, true);
    }
    public function extractValuesForWildcards($data, $attribute)
    {
        $keys = [];
        $pattern = str_replace('\*', '[^\.]+', preg_quote($attribute));
        foreach ($data as $key => $value) {
            if ((bool) preg_match('/^'.$pattern.'/', $key, $matches)) {
                $keys[] = $matches[0];
            }
        }
        $keys = array_unique($keys);
        $data = [];
        foreach ($keys as $key) {
            $data[$key] = array_get($this->data, $key);
        }
        return $data;
    }
    public function mergeRules($attribute, $rules = [])
    {
        if (is_array($attribute)) {
            foreach ($attribute as $innerAttribute => $innerRules) {
                $this->mergeRulesForAttribute($innerAttribute, $innerRules);
            }
            return $this;
        }
        return $this->mergeRulesForAttribute($attribute, $rules);
    }
    protected function mergeRulesForAttribute($attribute, $rules)
    {
        $current = isset($this->rules[$attribute]) ? $this->rules[$attribute] : [];
        $merge = head($this->explodeRules([$rules]));
        $this->rules[$attribute] = array_merge($current, $merge);
        return $this;
    }
    public function passes()
    {
        $this->messages = new MessageBag;
                                foreach ($this->rules as $attribute => $rules) {
            foreach ($rules as $rule) {
                $this->validate($attribute, $rule);
                if ($this->shouldStopValidating($attribute)) {
                    break;
                }
            }
        }
                                foreach ($this->after as $after) {
            call_user_func($after);
        }
        return $this->messages->isEmpty();
    }
    public function fails()
    {
        return ! $this->passes();
    }
    protected function validate($attribute, $rule)
    {
        list($rule, $parameters) = $this->parseRule($rule);
        if ($rule == '') {
            return;
        }
                                if (($keys = $this->getExplicitKeys($attribute)) &&
            $this->dependsOnOtherFields($rule)) {
            $parameters = $this->replaceAsterisksInParameters($parameters, $keys);
        }
                                $value = $this->getValue($attribute);
        $validatable = $this->isValidatable($rule, $attribute, $value);
        $method = "validate{$rule}";
        if ($validatable && ! $this->$method($attribute, $value, $parameters, $this)) {
            $this->addFailure($attribute, $rule, $parameters);
        }
    }
    public function valid()
    {
        if (! $this->messages) {
            $this->passes();
        }
        return array_diff_key($this->data, $this->messages()->toArray());
    }
    public function invalid()
    {
        if (! $this->messages) {
            $this->passes();
        }
        return array_intersect_key($this->data, $this->messages()->toArray());
    }
    protected function getValue($attribute)
    {
        if (! is_null($value = Arr::get($this->data, $attribute))) {
            return $value;
        } elseif (! is_null($value = Arr::get($this->files, $attribute))) {
            return $value;
        }
    }
    protected function isValidatable($rule, $attribute, $value)
    {
        return $this->presentOrRuleIsImplicit($rule, $attribute, $value) &&
               $this->passesOptionalCheck($attribute) &&
               $this->hasNotFailedPreviousRuleIfPresenceRule($rule, $attribute);
    }
    protected function presentOrRuleIsImplicit($rule, $attribute, $value)
    {
        return $this->validateRequired($attribute, $value) || $this->isImplicit($rule);
    }
    protected function passesOptionalCheck($attribute)
    {
        if ($this->hasRule($attribute, ['Sometimes'])) {
            return array_key_exists($attribute, Arr::dot($this->data))
                || in_array($attribute, array_keys($this->data))
                || array_key_exists($attribute, $this->files);
        }
        return true;
    }
    protected function isImplicit($rule)
    {
        return in_array($rule, $this->implicitRules);
    }
    protected function hasNotFailedPreviousRuleIfPresenceRule($rule, $attribute)
    {
        return in_array($rule, ['Unique', 'Exists'])
                        ? ! $this->messages->has($attribute) : true;
    }
    protected function addFailure($attribute, $rule, $parameters)
    {
        $this->addError($attribute, $rule, $parameters);
        $this->failedRules[$attribute][$rule] = $parameters;
    }
    protected function addError($attribute, $rule, $parameters)
    {
        $message = $this->getMessage($attribute, $rule);
        $message = $this->doReplacements($message, $attribute, $rule, $parameters);
        $this->messages->add($attribute, $message);
    }
    protected function validateSometimes()
    {
        return true;
    }
    protected function validateBail()
    {
        return true;
    }
    protected function shouldStopValidating($attribute)
    {
        if (! $this->hasRule($attribute, ['Bail'])) {
            return false;
        }
        return $this->messages->has($attribute);
    }
    protected function validateRequired($attribute, $value)
    {
        if (is_null($value)) {
            return false;
        } elseif (is_string($value) && trim($value) === '') {
            return false;
        } elseif ((is_array($value) || $value instanceof Countable) && count($value) < 1) {
            return false;
        } elseif ($value instanceof File) {
            return (string) $value->getPath() != '';
        }
        return true;
    }
    protected function validatePresent($attribute, $value)
    {
        return Arr::has($this->data, $attribute);
    }
    protected function validateFilled($attribute, $value)
    {
        if (Arr::has(array_merge($this->data, $this->files), $attribute)) {
            return $this->validateRequired($attribute, $value);
        }
        return true;
    }
    protected function anyFailingRequired(array $attributes)
    {
        foreach ($attributes as $key) {
            if (! $this->validateRequired($key, $this->getValue($key))) {
                return true;
            }
        }
        return false;
    }
    protected function allFailingRequired(array $attributes)
    {
        foreach ($attributes as $key) {
            if ($this->validateRequired($key, $this->getValue($key))) {
                return false;
            }
        }
        return true;
    }
    protected function validateRequiredWith($attribute, $value, $parameters)
    {
        if (! $this->allFailingRequired($parameters)) {
            return $this->validateRequired($attribute, $value);
        }
        return true;
    }
    protected function validateRequiredWithAll($attribute, $value, $parameters)
    {
        if (! $this->anyFailingRequired($parameters)) {
            return $this->validateRequired($attribute, $value);
        }
        return true;
    }
    protected function validateRequiredWithout($attribute, $value, $parameters)
    {
        if ($this->anyFailingRequired($parameters)) {
            return $this->validateRequired($attribute, $value);
        }
        return true;
    }
    protected function validateRequiredWithoutAll($attribute, $value, $parameters)
    {
        if ($this->allFailingRequired($parameters)) {
            return $this->validateRequired($attribute, $value);
        }
        return true;
    }
    protected function validateRequiredIf($attribute, $value, $parameters)
    {
        $this->requireParameterCount(2, $parameters, 'required_if');
        $data = Arr::get($this->data, $parameters[0]);
        $values = array_slice($parameters, 1);
        if (is_bool($data)) {
            array_walk($values, function (&$value) {
                if ($value === 'true') {
                    $value = true;
                } elseif ($value === 'false') {
                    $value = false;
                }
            });
        }
        if (in_array($data, $values)) {
            return $this->validateRequired($attribute, $value);
        }
        return true;
    }
    protected function validateRequiredUnless($attribute, $value, $parameters)
    {
        $this->requireParameterCount(2, $parameters, 'required_unless');
        $data = Arr::get($this->data, $parameters[0]);
        $values = array_slice($parameters, 1);
        if (! in_array($data, $values)) {
            return $this->validateRequired($attribute, $value);
        }
        return true;
    }
    protected function getPresentCount($attributes)
    {
        $count = 0;
        foreach ($attributes as $key) {
            if (Arr::get($this->data, $key) || Arr::get($this->files, $key)) {
                $count++;
            }
        }
        return $count;
    }
    protected function validateInArray($attribute, $value, $parameters)
    {
        $this->requireParameterCount(1, $parameters, 'in_array');
        $explicitPath = $this->getLeadingExplicitAttributePath($parameters[0]);
        $attributeData = $this->extractDataFromPath($explicitPath);
        $otherValues = Arr::where(Arr::dot($attributeData), function ($key) use ($parameters) {
            return Str::is($parameters[0], $key);
        });
        return in_array($value, $otherValues);
    }
    protected function validateConfirmed($attribute, $value)
    {
        return $this->validateSame($attribute, $value, [$attribute.'_confirmation']);
    }
    protected function validateSame($attribute, $value, $parameters)
    {
        $this->requireParameterCount(1, $parameters, 'same');
        $other = Arr::get($this->data, $parameters[0]);
        return isset($other) && $value === $other;
    }
    protected function validateDifferent($attribute, $value, $parameters)
    {
        $this->requireParameterCount(1, $parameters, 'different');
        $other = Arr::get($this->data, $parameters[0]);
        return isset($other) && $value !== $other;
    }
    protected function validateAccepted($attribute, $value)
    {
        $acceptable = ['yes', 'on', '1', 1, true, 'true'];
        return $this->validateRequired($attribute, $value) && in_array($value, $acceptable, true);
    }
    protected function validateArray($attribute, $value)
    {
        if (! $this->hasAttribute($attribute)) {
            return true;
        }
        return is_null($value) || is_array($value);
    }
    protected function validateBoolean($attribute, $value)
    {
        if (! $this->hasAttribute($attribute)) {
            return true;
        }
        $acceptable = [true, false, 0, 1, '0', '1'];
        return is_null($value) || in_array($value, $acceptable, true);
    }
    protected function validateInteger($attribute, $value)
    {
        if (! $this->hasAttribute($attribute)) {
            return true;
        }
        return is_null($value) || filter_var($value, FILTER_VALIDATE_INT) !== false;
    }
    protected function validateNumeric($attribute, $value)
    {
        if (! $this->hasAttribute($attribute)) {
            return true;
        }
        return is_null($value) || is_numeric($value);
    }
    protected function validateString($attribute, $value)
    {
        if (! $this->hasAttribute($attribute)) {
            return true;
        }
        return is_null($value) || is_string($value);
    }
    protected function validateJson($attribute, $value)
    {
        if (! is_scalar($value) && ! method_exists($value, '__toString')) {
            return false;
        }
        json_decode($value);
        return json_last_error() === JSON_ERROR_NONE;
    }
    protected function validateDigits($attribute, $value, $parameters)
    {
        $this->requireParameterCount(1, $parameters, 'digits');
        return $this->validateNumeric($attribute, $value)
            && strlen((string) $value) == $parameters[0];
    }
    protected function validateDigitsBetween($attribute, $value, $parameters)
    {
        $this->requireParameterCount(2, $parameters, 'digits_between');
        $length = strlen((string) $value);
        return $this->validateNumeric($attribute, $value)
          && $length >= $parameters[0] && $length <= $parameters[1];
    }
    protected function validateSize($attribute, $value, $parameters)
    {
        $this->requireParameterCount(1, $parameters, 'size');
        return $this->getSize($attribute, $value) == $parameters[0];
    }
    protected function validateBetween($attribute, $value, $parameters)
    {
        $this->requireParameterCount(2, $parameters, 'between');
        $size = $this->getSize($attribute, $value);
        return $size >= $parameters[0] && $size <= $parameters[1];
    }
    protected function validateMin($attribute, $value, $parameters)
    {
        $this->requireParameterCount(1, $parameters, 'min');
        return $this->getSize($attribute, $value) >= $parameters[0];
    }
    protected function validateMax($attribute, $value, $parameters)
    {
        $this->requireParameterCount(1, $parameters, 'max');
        if ($value instanceof UploadedFile && ! $value->isValid()) {
            return false;
        }
        return $this->getSize($attribute, $value) <= $parameters[0];
    }
    protected function getSize($attribute, $value)
    {
        $hasNumeric = $this->hasRule($attribute, $this->numericRules);
                                        if (is_numeric($value) && $hasNumeric) {
            return $value;
        } elseif (is_array($value)) {
            return count($value);
        } elseif ($value instanceof File) {
            return $value->getSize() / 1024;
        }
        return mb_strlen($value);
    }
    protected function validateIn($attribute, $value, $parameters)
    {
        if (is_array($value) && $this->hasRule($attribute, 'Array')) {
            foreach ($value as $element) {
                if (is_array($element)) {
                    return false;
                }
            }
            return count(array_diff($value, $parameters)) == 0;
        }
        return ! is_array($value) && in_array((string) $value, $parameters);
    }
    protected function validateNotIn($attribute, $value, $parameters)
    {
        return ! $this->validateIn($attribute, $value, $parameters);
    }
    protected function validateDistinct($attribute, $value, $parameters)
    {
        $attributeName = $this->getPrimaryAttribute($attribute);
        $explicitPath = $this->getLeadingExplicitAttributePath($attributeName);
        $attributeData = $this->extractDataFromPath($explicitPath);
        $data = Arr::where(Arr::dot($attributeData), function ($key) use ($attribute, $attributeName) {
            return $key != $attribute && Str::is($attributeName, $key);
        });
        return ! in_array($value, array_values($data));
    }
    protected function validateUnique($attribute, $value, $parameters)
    {
        $this->requireParameterCount(1, $parameters, 'unique');
        list($connection, $table) = $this->parseTable($parameters[0]);
                                $column = isset($parameters[1])
                    ? $parameters[1] : $this->guessColumnForQuery($attribute);
        list($idColumn, $id) = [null, null];
        if (isset($parameters[2])) {
            list($idColumn, $id) = $this->getUniqueIds($parameters);
            if (preg_match('/\[(.*)\]/', $id, $matches)) {
                $id = $this->getValue($matches[1]);
            }
            if (strtolower($id) == 'null') {
                $id = null;
            }
            if (filter_var($id, FILTER_VALIDATE_INT) !== false) {
                $id = intval($id);
            }
        }
                                $verifier = $this->getPresenceVerifier();
        $verifier->setConnection($connection);
        $extra = $this->getUniqueExtra($parameters);
        return $verifier->getCount(
            $table, $column, $value, $id, $idColumn, $extra
        ) == 0;
    }
    protected function parseTable($table)
    {
        return Str::contains($table, '.') ? explode('.', $table, 2) : [null, $table];
    }
    protected function getUniqueIds($parameters)
    {
        $idColumn = isset($parameters[3]) ? $parameters[3] : 'id';
        return [$idColumn, $parameters[2]];
    }
    protected function getUniqueExtra($parameters)
    {
        if (isset($parameters[4])) {
            return $this->getExtraConditions(array_slice($parameters, 4));
        }
        return [];
    }
    protected function validateExists($attribute, $value, $parameters)
    {
        $this->requireParameterCount(1, $parameters, 'exists');
        list($connection, $table) = $this->parseTable($parameters[0]);
                                $column = isset($parameters[1])
                    ? $parameters[1] : $this->guessColumnForQuery($attribute);
        $expected = (is_array($value)) ? count($value) : 1;
        return $this->getExistCount(
            $connection, $table, $column, $value, $parameters
        ) >= $expected;
    }
    protected function getExistCount($connection, $table, $column, $value, $parameters)
    {
        $verifier = $this->getPresenceVerifier();
        $verifier->setConnection($connection);
        $extra = $this->getExtraExistConditions($parameters);
        if (is_array($value)) {
            return $verifier->getMultiCount($table, $column, $value, $extra);
        }
        return $verifier->getCount($table, $column, $value, null, null, $extra);
    }
    protected function getExtraExistConditions(array $parameters)
    {
        return $this->getExtraConditions(array_values(array_slice($parameters, 2)));
    }
    protected function getExtraConditions(array $segments)
    {
        $extra = [];
        $count = count($segments);
        for ($i = 0; $i < $count; $i = $i + 2) {
            $extra[$segments[$i]] = $segments[$i + 1];
        }
        return $extra;
    }
    public function guessColumnForQuery($attribute)
    {
        if (in_array($attribute, array_collapse($this->implicitAttributes))
                && ! is_numeric($last = last(explode('.', $attribute)))) {
            return $last;
        }
        return $attribute;
    }
    protected function validateIp($attribute, $value)
    {
        return filter_var($value, FILTER_VALIDATE_IP) !== false;
    }
    protected function validateEmail($attribute, $value)
    {
        return filter_var($value, FILTER_VALIDATE_EMAIL) !== false;
    }
    protected function validateUrl($attribute, $value)
    {
        $pattern = '~^
            ((aaa|aaas|about|acap|acct|acr|adiumxtra|afp|afs|aim|apt|attachment|aw|barion|beshare|bitcoin|blob|bolo|callto|cap|chrome|chrome-extension|cid|coap|coaps|com-eventbrite-attendee|content|crid|cvs|data|dav|dict|dlna-playcontainer|dlna-playsingle|dns|dntp|dtn|dvb|ed2k|example|facetime|fax|feed|feedready|file|filesystem|finger|fish|ftp|geo|gg|git|gizmoproject|go|gopher|gtalk|h323|ham|hcp|http|https|iax|icap|icon|im|imap|info|iotdisco|ipn|ipp|ipps|irc|irc6|ircs|iris|iris.beep|iris.lwz|iris.xpc|iris.xpcs|itms|jabber|jar|jms|keyparc|lastfm|ldap|ldaps|magnet|mailserver|mailto|maps|market|message|mid|mms|modem|ms-help|ms-settings|ms-settings-airplanemode|ms-settings-bluetooth|ms-settings-camera|ms-settings-cellular|ms-settings-cloudstorage|ms-settings-emailandaccounts|ms-settings-language|ms-settings-location|ms-settings-lock|ms-settings-nfctransactions|ms-settings-notifications|ms-settings-power|ms-settings-privacy|ms-settings-proximity|ms-settings-screenrotation|ms-settings-wifi|ms-settings-workplace|msnim|msrp|msrps|mtqp|mumble|mupdate|mvn|news|nfs|ni|nih|nntp|notes|oid|opaquelocktoken|pack|palm|paparazzi|pkcs11|platform|pop|pres|prospero|proxy|psyc|query|redis|rediss|reload|res|resyntaxhighlight|rmi|rsync|rtmfp|rtmp|rtsp|rtsps|rtspu|secondlife|service|session|sftp|sgn|shttp|sieve|sip|sips|skype|smb|sms|smtp|snews|snmp|soap.beep|soap.beeps|soldat|spotify|ssh|steam|stun|stuns|submit|svn|tag|teamspeak|tel|teliaeid|telnet|tftp|things|thismessage|tip|tn3270|turn|turns|tv|udp|unreal|urn|ut2004|vemmi|ventrilo|videotex|view-syntaxhighlight|wais|webcal|ws|wss|wtai|wyciwyg|xcon|xcon-userid|xfire|xmlrpc\.beep|xmlrpc.beeps|xmpp|xri|ymsgr|z39\.50|z39\.50r|z39\.50s))://                                 # protocol
            (([\pL\pN-]+:)?([\pL\pN-]+)@)?          # basic auth
            (
                ([\pL\pN\pS-\.])+(\.?([\pL]|xn\-\-[\pL\pN-]+)+\.?) # a domain name
                    |                                              # or
                \d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}                 # a IP address
                    |                                              # or
                \[
                    (?:(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){6})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:::(?:(?:(?:[0-9a-f]{1,4})):){5})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){4})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,1}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){3})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,2}(?:(?:[0-9a-f]{1,4})))?::(?:(?:(?:[0-9a-f]{1,4})):){2})(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,3}(?:(?:[0-9a-f]{1,4})))?::(?:(?:[0-9a-f]{1,4})):)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,4}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:(?:(?:(?:[0-9a-f]{1,4})):(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9]))\.){3}(?:(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])))))))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,5}(?:(?:[0-9a-f]{1,4})))?::)(?:(?:[0-9a-f]{1,4})))|(?:(?:(?:(?:(?:(?:[0-9a-f]{1,4})):){0,6}(?:(?:[0-9a-f]{1,4})))?::))))
                \]  # a IPv6 address
            )
            (:[0-9]+)?                              # a port (optional)
            (/?|/\S+|\?\S*|\#\S*)                   # a /, nothing, a / with something, a query or a fragment
        $~ixu';
        return preg_match($pattern, $value) > 0;
    }
    protected function validateActiveUrl($attribute, $value)
    {
        if (! is_string($value)) {
            return false;
        }
        if ($url = parse_url($value, PHP_URL_HOST)) {
            return count(dns_get_record($url, DNS_A | DNS_AAAA)) > 0;
        }
        return false;
    }
    protected function validateFile($attribute, $value)
    {
        return $this->isAValidFileInstance($value);
    }
    protected function validateImage($attribute, $value)
    {
        return $this->validateMimes($attribute, $value, ['jpeg', 'png', 'gif', 'bmp', 'svg']);
    }
    protected function validateDimensions($attribute, $value, $parameters)
    {
        if (! $this->isAValidFileInstance($value) || ! $sizeDetails = getimagesize($value->getRealPath())) {
            return false;
        }
        $this->requireParameterCount(1, $parameters, 'dimensions');
        list($width, $height) = $sizeDetails;
        $parameters = $this->parseNamedParameters($parameters);
        if (
            isset($parameters['width']) && $parameters['width'] != $width ||
            isset($parameters['min_width']) && $parameters['min_width'] > $width ||
            isset($parameters['max_width']) && $parameters['max_width'] < $width ||
            isset($parameters['height']) && $parameters['height'] != $height ||
            isset($parameters['min_height']) && $parameters['min_height'] > $height ||
            isset($parameters['max_height']) && $parameters['max_height'] < $height
        ) {
            return false;
        }
        if (isset($parameters['ratio'])) {
            list($numerator, $denominator) = array_pad(sscanf($parameters['ratio'], '%d/%d'), 2, 1);
            return $numerator / $denominator == $width / $height;
        }
        return true;
    }
    protected function validateMimes($attribute, $value, $parameters)
    {
        if (! $this->isAValidFileInstance($value)) {
            return false;
        }
        return $value->getPath() != '' && in_array($value->guessExtension(), $parameters);
    }
    protected function validateMimetypes($attribute, $value, $parameters)
    {
        if (! $this->isAValidFileInstance($value)) {
            return false;
        }
        return $value->getPath() != '' && in_array($value->getMimeType(), $parameters);
    }
    public function isAValidFileInstance($value)
    {
        if ($value instanceof UploadedFile && ! $value->isValid()) {
            return false;
        }
        return $value instanceof File;
    }
    protected function validateAlpha($attribute, $value)
    {
        return is_string($value) && preg_match('/^[\pL\pM]+$/u', $value);
    }
    protected function validateAlphaNum($attribute, $value)
    {
        if (! is_string($value) && ! is_numeric($value)) {
            return false;
        }
        return preg_match('/^[\pL\pM\pN]+$/u', $value) > 0;
    }
    protected function validateAlphaDash($attribute, $value)
    {
        if (! is_string($value) && ! is_numeric($value)) {
            return false;
        }
        return preg_match('/^[\pL\pM\pN_-]+$/u', $value) > 0;
    }
    protected function validateRegex($attribute, $value, $parameters)
    {
        if (! is_string($value) && ! is_numeric($value)) {
            return false;
        }
        $this->requireParameterCount(1, $parameters, 'regex');
        return preg_match($parameters[0], $value) > 0;
    }
    protected function validateDate($attribute, $value)
    {
        if ($value instanceof DateTime) {
            return true;
        }
        if ((! is_string($value) && ! is_numeric($value)) || strtotime($value) === false) {
            return false;
        }
        $date = date_parse($value);
        return checkdate($date['month'], $date['day'], $date['year']);
    }
    protected function validateDateFormat($attribute, $value, $parameters)
    {
        $this->requireParameterCount(1, $parameters, 'date_format');
        if (! is_string($value) && ! is_numeric($value)) {
            return false;
        }
        $parsed = date_parse_from_format($parameters[0], $value);
        return $parsed['error_count'] === 0 && $parsed['warning_count'] === 0;
    }
    protected function validateBefore($attribute, $value, $parameters)
    {
        $this->requireParameterCount(1, $parameters, 'before');
        if (! is_string($value) && ! is_numeric($value) && ! $value instanceof DateTimeInterface) {
            return false;
        }
        if ($format = $this->getDateFormat($attribute)) {
            return $this->validateBeforeWithFormat($format, $value, $parameters);
        }
        if (! $date = $this->getDateTimestamp($parameters[0])) {
            $date = $this->getDateTimestamp($this->getValue($parameters[0]));
        }
        return $this->getDateTimestamp($value) < $date;
    }
    protected function validateBeforeWithFormat($format, $value, $parameters)
    {
        $param = $this->getValue($parameters[0]) ?: $parameters[0];
        return $this->checkDateTimeOrder($format, $value, $param);
    }
    protected function validateAfter($attribute, $value, $parameters)
    {
        $this->requireParameterCount(1, $parameters, 'after');
        if (! is_string($value) && ! is_numeric($value) && ! $value instanceof DateTimeInterface) {
            return false;
        }
        if ($format = $this->getDateFormat($attribute)) {
            return $this->validateAfterWithFormat($format, $value, $parameters);
        }
        if (! $date = $this->getDateTimestamp($parameters[0])) {
            $date = $this->getDateTimestamp($this->getValue($parameters[0]));
        }
        return $this->getDateTimestamp($value) > $date;
    }
    protected function validateAfterWithFormat($format, $value, $parameters)
    {
        $param = $this->getValue($parameters[0]) ?: $parameters[0];
        return $this->checkDateTimeOrder($format, $param, $value);
    }
    protected function checkDateTimeOrder($format, $before, $after)
    {
        $before = $this->getDateTimeWithOptionalFormat($format, $before);
        $after = $this->getDateTimeWithOptionalFormat($format, $after);
        return ($before && $after) && ($after > $before);
    }
    protected function getDateTimeWithOptionalFormat($format, $value)
    {
        $date = DateTime::createFromFormat($format, $value);
        if ($date) {
            return $date;
        }
        try {
            return new DateTime($value);
        } catch (Exception $e) {
                    }
    }
    protected function validateTimezone($attribute, $value)
    {
        try {
            new DateTimeZone($value);
        } catch (Exception $e) {
            return false;
        }
        return true;
    }
    protected function getDateFormat($attribute)
    {
        if ($result = $this->getRule($attribute, 'DateFormat')) {
            return $result[1][0];
        }
    }
    protected function getDateTimestamp($value)
    {
        return $value instanceof DateTimeInterface ? $value->getTimestamp() : strtotime($value);
    }
    protected function getMessage($attribute, $rule)
    {
        $lowerRule = Str::snake($rule);
        $inlineMessage = $this->getInlineMessage($attribute, $lowerRule);
                                if (! is_null($inlineMessage)) {
            return $inlineMessage;
        }
        $customKey = "validation.custom.{$attribute}.{$lowerRule}";
        $customMessage = $this->getCustomMessageFromTranslator($customKey);
                                if ($customMessage !== $customKey) {
            return $customMessage;
        }
                                elseif (in_array($rule, $this->sizeRules)) {
            return $this->getSizeMessage($attribute, $rule);
        }
                                $key = "validation.{$lowerRule}";
        if ($key != ($value = $this->translator->trans($key))) {
            return $value;
        }
        return $this->getInlineMessage(
            $attribute, $lowerRule, $this->fallbackMessages
        ) ?: $key;
    }
    protected function getInlineMessage($attribute, $lowerRule, $syntaxhighlight = null)
    {
        $syntaxhighlight = $syntaxhighlight ?: $this->customMessages;
        $keys = ["{$attribute}.{$lowerRule}", $lowerRule];
                                foreach ($keys as $key) {
            foreach (array_keys($syntaxhighlight) as $syntaxhighlightKey) {
                if (Str::is($syntaxhighlightKey, $key)) {
                    return $syntaxhighlight[$syntaxhighlightKey];
                }
            }
        }
    }
    protected function getCustomMessageFromTranslator($customKey)
    {
        if (($message = $this->translator->trans($customKey)) !== $customKey) {
            return $message;
        }
        $shortKey = preg_replace('/^validation\.custom\./', '', $customKey);
        $customMessages = Arr::dot(
            (array) $this->translator->trans('validation.custom')
        );
        foreach ($customMessages as $key => $message) {
            if (Str::contains($key, ['*']) && Str::is($key, $shortKey)) {
                return $message;
            }
        }
        return $customKey;
    }
    protected function getSizeMessage($attribute, $rule)
    {
        $lowerRule = Str::snake($rule);
                                $type = $this->getAttributeType($attribute);
        $key = "validation.{$lowerRule}.{$type}";
        return $this->translator->trans($key);
    }
    protected function getAttributeType($attribute)
    {
                                if ($this->hasRule($attribute, $this->numericRules)) {
            return 'numeric';
        } elseif ($this->hasRule($attribute, ['Array'])) {
            return 'array';
        } elseif (array_key_exists($attribute, $this->files)) {
            return 'file';
        }
        return 'string';
    }
    protected function doReplacements($message, $attribute, $rule, $parameters)
    {
        $value = $this->getAttribute($attribute);
        $message = str_replace(
            [':attribute', ':ATTRIBUTE', ':Attribute'],
            [$value, Str::upper($value), Str::ucfirst($value)],
            $message
        );
        if (isset($this->replacers[Str::snake($rule)])) {
            $message = $this->callReplacer($message, $attribute, Str::snake($rule), $parameters);
        } elseif (method_exists($this, $replacer = "replace{$rule}")) {
            $message = $this->$replacer($message, $attribute, $rule, $parameters);
        }
        return $message;
    }
    protected function getAttributeList(array $values)
    {
        $attributes = [];
                                foreach ($values as $key => $value) {
            $attributes[$key] = $this->getAttribute($value);
        }
        return $attributes;
    }
    protected function getAttribute($attribute)
    {
        $primaryAttribute = $this->getPrimaryAttribute($attribute);
        $expectedAttributes = $attribute != $primaryAttribute ? [$attribute, $primaryAttribute] : [$attribute];
        foreach ($expectedAttributes as $expectedAttributeName) {
                                                if (isset($this->customAttributes[$expectedAttributeName])) {
                return $this->customAttributes[$expectedAttributeName];
            }
            $key = "validation.attributes.{$expectedAttributeName}";
                                                if (($line = $this->translator->trans($key)) !== $key) {
                return $line;
            }
        }
                                if (isset($this->implicitAttributes[$primaryAttribute])) {
            return $attribute;
        }
        return str_replace('_', ' ', Str::snake($attribute));
    }
    protected function getPrimaryAttribute($attribute)
    {
        foreach ($this->implicitAttributes as $unparsed => $parsed) {
            if (in_array($attribute, $parsed)) {
                return $unparsed;
            }
        }
        return $attribute;
    }
    public function getDisplayableValue($attribute, $value)
    {
        if (isset($this->customValues[$attribute][$value])) {
            return $this->customValues[$attribute][$value];
        }
        $key = "validation.values.{$attribute}.{$value}";
        if (($line = $this->translator->trans($key)) !== $key) {
            return $line;
        }
        return $value;
    }
    protected function replaceBetween($message, $attribute, $rule, $parameters)
    {
        return str_replace([':min', ':max'], $parameters, $message);
    }
    protected function replaceDateFormat($message, $attribute, $rule, $parameters)
    {
        return str_replace(':format', $parameters[0], $message);
    }
    protected function replaceDifferent($message, $attribute, $rule, $parameters)
    {
        return $this->replaceSame($message, $attribute, $rule, $parameters);
    }
    protected function replaceDigits($message, $attribute, $rule, $parameters)
    {
        return str_replace(':digits', $parameters[0], $message);
    }
    protected function replaceDigitsBetween($message, $attribute, $rule, $parameters)
    {
        return $this->replaceBetween($message, $attribute, $rule, $parameters);
    }
    protected function replaceMin($message, $attribute, $rule, $parameters)
    {
        return str_replace(':min', $parameters[0], $message);
    }
    protected function replaceMax($message, $attribute, $rule, $parameters)
    {
        return str_replace(':max', $parameters[0], $message);
    }
    protected function replaceIn($message, $attribute, $rule, $parameters)
    {
        foreach ($parameters as &$parameter) {
            $parameter = $this->getDisplayableValue($attribute, $parameter);
        }
        return str_replace(':values', implode(', ', $parameters), $message);
    }
    protected function replaceNotIn($message, $attribute, $rule, $parameters)
    {
        return $this->replaceIn($message, $attribute, $rule, $parameters);
    }
    protected function replaceInArray($message, $attribute, $rule, $parameters)
    {
        return str_replace(':other', $this->getAttribute($parameters[0]), $message);
    }
    protected function replaceMimes($message, $attribute, $rule, $parameters)
    {
        return str_replace(':values', implode(', ', $parameters), $message);
    }
    protected function replaceRequiredWith($message, $attribute, $rule, $parameters)
    {
        $parameters = $this->getAttributeList($parameters);
        return str_replace(':values', implode(' / ', $parameters), $message);
    }
    protected function replaceRequiredWithAll($message, $attribute, $rule, $parameters)
    {
        return $this->replaceRequiredWith($message, $attribute, $rule, $parameters);
    }
    protected function replaceRequiredWithout($message, $attribute, $rule, $parameters)
    {
        return $this->replaceRequiredWith($message, $attribute, $rule, $parameters);
    }
    protected function replaceRequiredWithoutAll($message, $attribute, $rule, $parameters)
    {
        return $this->replaceRequiredWith($message, $attribute, $rule, $parameters);
    }
    protected function replaceSize($message, $attribute, $rule, $parameters)
    {
        return str_replace(':size', $parameters[0], $message);
    }
    protected function replaceRequiredIf($message, $attribute, $rule, $parameters)
    {
        $parameters[1] = $this->getDisplayableValue($parameters[0], Arr::get($this->data, $parameters[0]));
        $parameters[0] = $this->getAttribute($parameters[0]);
        return str_replace([':other', ':value'], $parameters, $message);
    }
    protected function replaceRequiredUnless($message, $attribute, $rule, $parameters)
    {
        $other = $this->getAttribute(array_shift($parameters));
        return str_replace([':other', ':values'], [$other, implode(', ', $parameters)], $message);
    }
    protected function replaceSame($message, $attribute, $rule, $parameters)
    {
        return str_replace(':other', $this->getAttribute($parameters[0]), $message);
    }
    protected function replaceBefore($message, $attribute, $rule, $parameters)
    {
        if (! (strtotime($parameters[0]))) {
            return str_replace(':date', $this->getAttribute($parameters[0]), $message);
        }
        return str_replace(':date', $parameters[0], $message);
    }
    protected function replaceAfter($message, $attribute, $rule, $parameters)
    {
        return $this->replaceBefore($message, $attribute, $rule, $parameters);
    }
    public function attributes()
    {
        return array_merge($this->data, $this->files);
    }
    public function hasAttribute($attribute)
    {
        return Arr::has($this->attributes(), $attribute);
    }
    protected function hasRule($attribute, $rules)
    {
        return ! is_null($this->getRule($attribute, $rules));
    }
    protected function getRule($attribute, $rules)
    {
        if (! array_key_exists($attribute, $this->rules)) {
            return;
        }
        $rules = (array) $rules;
        foreach ($this->rules[$attribute] as $rule) {
            list($rule, $parameters) = $this->parseRule($rule);
            if (in_array($rule, $rules)) {
                return [$rule, $parameters];
            }
        }
    }
    protected function parseRule($rules)
    {
        if (is_array($rules)) {
            $rules = $this->parseArrayRule($rules);
        } else {
            $rules = $this->parseStringRule($rules);
        }
        $rules[0] = $this->normalizeRule($rules[0]);
        return $rules;
    }
    protected function parseArrayRule(array $rules)
    {
        return [Str::studly(trim(Arr::get($rules, 0))), array_slice($rules, 1)];
    }
    protected function parseStringRule($rules)
    {
        $parameters = [];
                                if (strpos($rules, ':') !== false) {
            list($rules, $parameter) = explode(':', $rules, 2);
            $parameters = $this->parseParameters($rules, $parameter);
        }
        return [Str::studly(trim($rules)), $parameters];
    }
    protected function parseParameters($rule, $parameter)
    {
        if (strtolower($rule) == 'regex') {
            return [$parameter];
        }
        return str_getcsv($parameter);
    }
    protected function parseNamedParameters($parameters)
    {
        return array_reduce($parameters, function ($result, $item) {
            list($key, $value) = array_pad(explode('=', $item, 2), 2, null);
            $result[$key] = $value;
            return $result;
        });
    }
    protected function normalizeRule($rule)
    {
        switch ($rule) {
            case 'Int':
                return 'Integer';
            case 'Bool':
                return 'Boolean';
            default:
                return $rule;
        }
    }
    protected function dependsOnOtherFields($rule)
    {
        return in_array($rule, $this->dependentRules);
    }
    protected function getExplicitKeys($attribute)
    {
        $pattern = str_replace('\*', '([^\.]+)', preg_quote($this->getPrimaryAttribute($attribute)));
        if (preg_match('/^'.$pattern.'/', $attribute, $keys)) {
            array_shift($keys);
            return $keys;
        }
        return [];
    }
    protected function getLeadingExplicitAttributePath($attribute)
    {
        return rtrim(explode('*', $attribute)[0], '.') ?: null;
    }
    protected function extractDataFromPath($attribute)
    {
        $results = [];
        $value = Arr::get($this->data, $attribute, '__missing__');
        if ($value != '__missing__') {
            Arr::set($results, $attribute, $value);
        }
        return $results;
    }
    protected function replaceAsterisksInParameters(array $parameters, array $keys)
    {
        return array_map(function ($field) use ($keys) {
            return $this->replaceAsterisksWithKeys($field, $keys);
        }, $parameters);
    }
    protected function replaceAsterisksWithKeys($field, array $keys)
    {
        return vsprintf(str_replace('*', '%s', $field), $keys);
    }
    public function getExtensions()
    {
        return $this->extensions;
    }
    public function addExtensions(array $extensions)
    {
        if ($extensions) {
            $keys = array_map('\Illuminate\Support\Str::snake', array_keys($extensions));
            $extensions = array_combine($keys, array_values($extensions));
        }
        $this->extensions = array_merge($this->extensions, $extensions);
    }
    public function addImplicitExtensions(array $extensions)
    {
        $this->addExtensions($extensions);
        foreach ($extensions as $rule => $extension) {
            $this->implicitRules[] = Str::studly($rule);
        }
    }
    public function addExtension($rule, $extension)
    {
        $this->extensions[Str::snake($rule)] = $extension;
    }
    public function addImplicitExtension($rule, $extension)
    {
        $this->addExtension($rule, $extension);
        $this->implicitRules[] = Str::studly($rule);
    }
    public function getReplacers()
    {
        return $this->replacers;
    }
    public function addReplacers(array $replacers)
    {
        if ($replacers) {
            $keys = array_map('\Illuminate\Support\Str::snake', array_keys($replacers));
            $replacers = array_combine($keys, array_values($replacers));
        }
        $this->replacers = array_merge($this->replacers, $replacers);
    }
    public function addReplacer($rule, $replacer)
    {
        $this->replacers[Str::snake($rule)] = $replacer;
    }
    public function getData()
    {
        return $this->data;
    }
    public function setData(array $data)
    {
        $this->data = $this->parseData($data);
        $this->setRules($this->initialRules);
        return $this;
    }
    public function getRules()
    {
        return $this->rules;
    }
    public function setRules(array $rules)
    {
        $this->initialRules = $rules;
        $this->rules = [];
        $rules = $this->explodeRules($this->initialRules);
        $this->rules = array_merge($this->rules, $rules);
        return $this;
    }
    public function setAttributeNames(array $attributes)
    {
        $this->customAttributes = $attributes;
        return $this;
    }
    public function setValueNames(array $values)
    {
        $this->customValues = $values;
        return $this;
    }
    public function getFiles()
    {
        return $this->files;
    }
    public function setFiles(array $files)
    {
        $this->files = $files;
        return $this;
    }
    public function getPresenceVerifier()
    {
        if (! isset($this->presenceVerifier)) {
            throw new RuntimeException('Presence verifier has not been set.');
        }
        return $this->presenceVerifier;
    }
    public function setPresenceVerifier(PresenceVerifierInterface $presenceVerifier)
    {
        $this->presenceVerifier = $presenceVerifier;
    }
    public function getTranslator()
    {
        return $this->translator;
    }
    public function setTranslator(TranslatorInterface $translator)
    {
        $this->translator = $translator;
    }
    public function getCustomMessages()
    {
        return $this->customMessages;
    }
    public function setCustomMessages(array $messages)
    {
        $this->customMessages = array_merge($this->customMessages, $messages);
    }
    public function getCustomAttributes()
    {
        return $this->customAttributes;
    }
    public function addCustomAttributes(array $customAttributes)
    {
        $this->customAttributes = array_merge($this->customAttributes, $customAttributes);
        return $this;
    }
    public function getCustomValues()
    {
        return $this->customValues;
    }
    public function addCustomValues(array $customValues)
    {
        $this->customValues = array_merge($this->customValues, $customValues);
        return $this;
    }
    public function getFallbackMessages()
    {
        return $this->fallbackMessages;
    }
    public function setFallbackMessages(array $messages)
    {
        $this->fallbackMessages = $messages;
    }
    public function failed()
    {
        return $this->failedRules;
    }
    public function messages()
    {
        if (! $this->messages) {
            $this->passes();
        }
        return $this->messages;
    }
    public function errors()
    {
        return $this->messages();
    }
    public function getMessageBag()
    {
        return $this->messages();
    }
    public function setContainer(Container $container)
    {
        $this->container = $container;
    }
    protected function callExtension($rule, $parameters)
    {
        $callback = $this->extensions[$rule];
        if ($callback instanceof Closure) {
            return call_user_func_array($callback, $parameters);
        } elseif (is_string($callback)) {
            return $this->callClassBasedExtension($callback, $parameters);
        }
    }
    protected function callClassBasedExtension($callback, $parameters)
    {
        if (Str::contains($callback, '@')) {
            list($class, $method) = explode('@', $callback);
        } else {
            list($class, $method) = [$callback, 'validate'];
        }
        return call_user_func_array([$this->container->make($class), $method], $parameters);
    }
    protected function callReplacer($message, $attribute, $rule, $parameters)
    {
        $callback = $this->replacers[$rule];
        if ($callback instanceof Closure) {
            return call_user_func_array($callback, func_get_args());
        } elseif (is_string($callback)) {
            return $this->callClassBasedReplacer($callback, $message, $attribute, $rule, $parameters);
        }
    }
    protected function callClassBasedReplacer($callback, $message, $attribute, $rule, $parameters)
    {
        list($class, $method) = explode('@', $callback);
        return call_user_func_array([$this->container->make($class), $method], array_slice(func_get_args(), 1));
    }
    protected function requireParameterCount($count, $parameters, $rule)
    {
        if (count($parameters) < $count) {
            throw new InvalidArgumentException("Validation rule $rule requires at least $count parameters.");
        }
    }
    public function __call($method, $parameters)
    {
        $rule = Str::snake(substr($method, 8));
        if (isset($this->extensions[$rule])) {
            return $this->callExtension($rule, $parameters);
        }
        throw new BadMethodCallException("Method [$method] does not exist.");
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}