65535 || str_contains($topic, "\0") || strpbrk($topic, '+#') !== false) { throw new \InvalidArgumentException('MQTT topic is invalid.'); } foreach (config('mqtt.publish_topics', []) as $filter) { if (self::matchesFilter($topic, $filter)) { return; } } throw new \InvalidArgumentException('MQTT topic is not permitted.'); } private static function matchesFilter(string $topic, string $filter): bool { $pattern = preg_quote($filter, '/'); $pattern = str_replace(['\\+', '\\#'], ['[^/]+', '.*'], $pattern); return (bool) preg_match('/^' . $pattern . '$/u', $topic); } }