<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">&lt;?php
namespace MyApp\Rules;

use Illuminate\Contracts\Validation\Rule;

/**
 * Verify that the size (length) is one of the given sizes.
 *
 * Usage example:
 *   $rules['serialnumber'] = 'sizeoneof:8,14,20';
 *
 * @author Christian Weiske &lt;weiske@mogic.com&gt;
 */
class SizeOneOf implements Rule
{
    /**
     * Determine if the validation rule passes.
     *
     * @param string $attribute    Attribute name
     * @param mixed  $value        Attribute value
     * @param array  $allowedSizes Array of sizes/lengths
     * @param object $validator    Validator object with all form data
     *
     * @return bool If it validates
     */
    public function passes(
        $attribute, $value, $allowedSizes = [], $validator = null
    ) {
        if (!count($allowedSizes)) {
            throw new \Exception(
                'sizeoneof: No sizes defined'
            );
        }

        if (is_array($value)) {
            $size = count($value);
        } else {
            $size = strlen($value);
        }

        return in_array($size, $allowedSizes);
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return trans('validation.sizeoneof');
    }

    /**
     * Replace the ":values" parameter in the message
     *
     * @param string $message    Translated message with parameter
     * @param string $attribute  Attribute name
     * @param string $ruleName   Name of rule
     * @param array  $parameters Parameters for rule
     *
     * @return string Message with replaced other and max
     */
    public function replace($message, $attribute, $ruleName, $parameters)
    {
        return str_replace(
            ':values', implode(', ', $parameters), $message
        );
    }
}
</pre></body></html>