1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-22 07:42:41 +00:00
pixelfed/app/Rules/MaxMultiLine.php

34 lines
824 B
PHP

<?php
namespace App\Rules;
use Illuminate\Support\Str;
use Illuminate\Contracts\Validation\InvokableRule;
class MaxMultiLine implements InvokableRule
{
private $maxCharacters;
public function __construct($maxCharacters)
{
$this->maxCharacters = $maxCharacters;
}
/**
* Run the validation rule.
*
* @param string $attribute
* @param mixed $value
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
* @return void
*/
public function __invoke($attribute, $value, $fail)
{
$realCount = Str::length($value) - Str::substrCount($value, "\r\n");
if($realCount > $this->maxCharacters)
{
$fail('validation.max.string')->translate(['max' => $this->maxCharacters]);
}
}
}