restriction()->appliesTo($user->type)) { return true; } $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); if ($extension === '') { return false; } return in_array($extension, $this->allowedExtensions(), true); } /** * Client-side UX hint only (server-side enforcement is `isAllowed()` * above) — the allowed extensions when the restriction currently * applies to this user, or null when it doesn't (nothing to hint). * * @return list|null */ public function hintFor(User $user): ?array { return $this->restriction()->appliesTo($user->type) ? $this->allowedExtensions() : null; } private function restriction(): UploadTypeRestriction { $value = $this->settings->get(Setting::UploadTypeRestriction); return (is_string($value) ? UploadTypeRestriction::tryFrom($value) : null) ?? UploadTypeRestriction::All; } /** * @return list */ private function allowedExtensions(): array { $value = $this->settings->get(Setting::AllowedUploadExtensions); return is_array($value) ? array_values(array_map(fn ($extension): string => strtolower((string) $extension), $value)) : []; } }