3declare(strict_types=1);
10use InvalidArgumentException;
203 if (!is_string($from)) {
204 throw new InvalidArgumentException(__METHOD__ .
" the argument is not a string.");
207 if (empty($this->language_key)) {
208 throw new LogicException(
"Please specify a language for the title capitalization");
211 if (!isset($this->not_capitalize[$this->language_key])) {
212 throw new LogicException(
"Language " . $this->language_key .
" is not supported for the title capitalization");
216 $to = ucwords(strtolower($from));
219 $to = preg_replace_callback_array($this->
buildPatterns($this->not_capitalize[$this->language_key]), $to);
234 return array_reduce($words,
function (array $patterns,
string $word) : array {
235 $patterns[$this->
buildPattern($word)] = [ $this,
"replaceHelper" ];
252 return "/(\s|^)" . preg_quote($word) .
"(\s|$)/i";
263 return strtolower(
$result[0] ??
"");
An exception for terminatinating execution or to throw for unit testing.
__construct(string $language_key, Factory $factory)
CaseOfLabel constructor.
transform($from)
@inheritDoc
replaceHelper(array $result)
buildPatterns(array $words)
buildPattern(string $word)
trait DeriveInvokeFromTransform
trait DeriveApplyToFromTransform