private function handleUpload(UploadedFile $file = null, Badge $badge)
 {
     $ds = DIRECTORY_SEPARATOR;
     if ($file !== null) {
         if (file_exists($this->uploadDir . $ds . $badge->getImagePath())) {
             @unlink($this->uploadDir . $ds . $badge->getImagePath());
         }
         $filename = sha1(uniqid(mt_rand(), true)) . '.' . $file->guessExtension();
         $badge->setImagePath($filename);
         $realpathUploadRootDir = realpath($this->uploadDir);
         if (false === $realpathUploadRootDir) {
             throw new \Exception(sprintf("Invalid upload root dir '%s'for uploading badge images.", $this->uploadDir));
         }
         $file->move($this->uploadDir, $filename);
     }
 }