slug($projectName, '_')->lower()->toString(); // \d matches any digit character, equivalent to [0-9]. So, the regular expression '/\d/' will match any digit in the string. $str = preg_replace('/\d/', '', $slug); return $projectPrefix . '_' . $str; } public function isApplicationArrayValid(array $applicationArray): bool { foreach ($applicationArray as $app) { $app = (int) $app; if (empty($app) || $app <= 0 || empty($this->appsRepository->findOneBy(['id' => $app]))) { return false; } } return true; } public function handleLogoUpload($logoFile, $projectBddName): ?string { // 1. Define the destination directory (adjust path as needed, e.g., 'public/uploads/profile_pictures') $destinationDir = 'uploads/project_logos'; // 2. Create the directory if it doesn't exist if (!file_exists($destinationDir)) { // 0755 is the standard permission (Owner: read/write/exec, Others: read/exec) if (!mkdir($destinationDir, 0755, true) && !is_dir($destinationDir)) { throw new \RuntimeException(sprintf('Directory "%s" was not created', $destinationDir)); } } $extension = $logoFile->guessExtension(); // Sanitize the filename to remove special characters/spaces to prevent filesystem errors $customFilename = $projectBddName . '.' . $extension; try { // 4. Move the file to the destination directory $logoFile->move($destinationDir, $customFilename); // 5. Update the user entity with the relative path // Ensure you store the path relative to your public folder usually return $destinationDir . '/' . $customFilename; } catch (\Exception $e) { // 6. Log the critical error as requested $this->loggerService->logError('File upload failed',[ 'target_user_id' => $this->security->getUser()->getId(), 'message' => $e->getMessage(), 'file_name' => $customFilename, ]); // Optional: Re-throw the exception if you want the controller/user to know the upload failed throw new FileException('File upload failed.'); } } }