You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
urlhub/app/Rules/Url/KeywordBlacklist.php

31 lines
766 B

<?php
namespace App\Rules\Url;
use App\Services\KeyGeneratorService;
use Illuminate\Contracts\Validation\InvokableRule;
/**
* Check if keyword id is free (ie not already taken, not a URL path, and not
* reserved).
*/
class KeywordBlacklist implements InvokableRule
{
/**
* 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)
{
$stringCanBeUsedAsKey = app(KeyGeneratorService::class)->assertStringCanBeUsedAsKey($value);
if ($stringCanBeUsedAsKey === false) {
$fail('Not available.');
}
}
}