1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-26 17:56:48 +00:00
pixelfed/app/Rules/MaxMultiLine.php

35 lines
824 B
PHP
Raw Normal View History

<?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]);
}
}
}