/** * @return bool */ public function isValid() : bool { if (!$this->has()) { return false; } $return = CallSilencerFactory::create(function () { return preg_match(sprintf('{%s}', $this->get()), null); })->setValidator(function ($result) { return $result !== false; })->invoke(); return $return->isValid(); }
/** * Try to compile message with provided string and replacement array. * * @param string $message The message string, which may contain placeholders for vsprintf * @param mixed[] $replace Array of replacements for the string * @param bool $removes If true extra placeholders will be removed from the string such that the number of * placeholders matches the number of replacements * * @return bool|string */ private final function compileMessagePlaceholders(string $message, array $replace = [], $removes = false) { if ($removes) { $message = $this->removePlaceholders($message, count($replace)); } $return = CallSilencerFactory::create(function () use($message, $replace) { return vsprintf($message, $replace); }, function ($ret) { return $ret !== null && !empty($ret); })->invoke(); return $return->isValid() ? $return->getReturn() : false; }