original_string: protected function validateFile($file, FormEvent $event)
      {
          if ($file instanceof File) {
  
              $isValidFile  = true;
  
              //check if the file is allowed by the MIME-types constraint given
              if (!empty($this->allowedFileTypes) && null !== $mime = $file->getMimeType()) {
                  if (!in_array($mime, $this->allowedFileTypes)) {
                      $isValidFile = false;
                      $message = $this->translator->trans(
                          'zicht_filemanager.wrong_type',
                          array(
                              '%this_type%'     => $mime,
                              '%allowed_types%' => implode(', ', $this->allowedFileTypes)
                          ),
                          $event->getForm()->getConfig()->getOption('translation_domain')
                      );
  
                      $event->getForm()->addError(new FormError($message));
                      /** Set back data to old so we don`t see new file */
                      $event->setData(array(FileType::UPLOAD_FIELDNAME => $event->getForm()->getData()));
                  }
              }
  
              if ($isValidFile) {
                  $purgatoryFileManager = $this->getPurgatoryFileManager();
                  $entity = $event->getForm()->getParent()->getConfig()->getDataClass();
  
                  $data = $event->getData();
                  $replaceFile = isset($data[FileType::KEEP_PREVIOUS_FILENAME]) && $data[FileType::KEEP_PREVIOUS_FILENAME] === '1';
                  $forceFilename = $replaceFile ? $event->getForm()->getData() : '';
  
                  $path = $purgatoryFileManager->prepare($file, $entity, $this->field, true, $forceFilename);
                  $purgatoryFileManager->save($file, $path);
                  $this->prepareData($data, $path, $event->getForm()->getPropertyPath());
                  $event->setData($data);
              }
          }
      }
code: protected function validateFile($file, FormEvent $event)
      {
          if ($file instanceof File) {
  
              $isValidFile  = true;
  
              //check if the file is allowed by the MIME-types constraint given
              if (!empty($this->allowedFileTypes) && null !== $mime = $file->getMimeType()) {
                  if (!in_array($mime, $this->allowedFileTypes)) {
                      $isValidFile = false;
                      $message = $this->translator->trans(
                          'zicht_filemanager.wrong_type',
                          array(
                              '%this_type%'     => $mime,
                              '%allowed_types%' => implode(', ', $this->allowedFileTypes)
                          ),
                          $event->getForm()->getConfig()->getOption('translation_domain')
                      );
  
                      $event->getForm()->addError(new FormError($message));
                      /** Set back data to old so we don`t see new file */
                      $event->setData(array(FileType::UPLOAD_FIELDNAME => $event->getForm()->getData()));
                  }
              }
  
              if ($isValidFile) {
                  $purgatoryFileManager = $this->getPurgatoryFileManager();
                  $entity = $event->getForm()->getParent()->getConfig()->getDataClass();
  
                  $data = $event->getData();
                  $replaceFile = isset($data[FileType::KEEP_PREVIOUS_FILENAME]) && $data[FileType::KEEP_PREVIOUS_FILENAME] === '1';
                  $forceFilename = $replaceFile ? $event->getForm()->getData() : '';
  
                  $path = $purgatoryFileManager->prepare($file, $entity, $this->field, true, $forceFilename);
                  $purgatoryFileManager->save($file, $path);
                  $this->prepareData($data, $path, $event->getForm()->getPropertyPath());
                  $event->setData($data);
              }
          }
      }
code_tokens: protected function validateFile ( $ file , FormEvent $ event ) { if ( $ file instanceof File ) { $ isValidFile = true ; //check if the file is allowed by the MIME-types constraint given if ( ! empty ( $ this -> allowedFileTypes ) && null !== $ mime = $ file -> getMimeType ( ) ) { if ( ! in_array ( $ mime , $ this -> allowedFileTypes ) ) { $ isValidFile = false ; $ message = $ this -> translator -> trans ( 'zicht_filemanager.wrong_type' , array ( '%this_type%' => $ mime , '%allowed_types%' => implode ( ', ' , $ this -> allowedFileTypes ) ) , $ event -> getForm ( ) -> getConfig ( ) -> getOption ( 'translation_domain' ) ) ; $ event -> getForm ( ) -> addError ( new FormError ( $ message ) ) ; /** Set back data to old so we don`t see new file */ $ event -> setData ( array ( FileType :: UPLOAD_FIELDNAME => $ event -> getForm ( ) -> getData ( ) ) ) ; } } if ( $ isValidFile ) { $ purgatoryFileManager = $ this -> getPurgatoryFileManager ( ) ; $ entity = $ event -> getForm ( ) -> getParent ( ) -> getConfig ( ) -> getDataClass ( ) ; $ data = $ event -> getData ( ) ; $ replaceFile = isset ( $ data [ FileType :: KEEP_PREVIOUS_FILENAME ] ) && $ data [ FileType :: KEEP_PREVIOUS_FILENAME ] === '1' ; $ forceFilename = $ replaceFile ? $ event -> getForm ( ) -> getData ( ) : '' ; $ path = $ purgatoryFileManager -> prepare ( $ file , $ entity , $ this -> field , true , $ forceFilename ) ; $ purgatoryFileManager -> save ( $ file , $ path ) ; $ this -> prepareData ( $ data , $ path , $ event -> getForm ( ) -> getPropertyPath ( ) ) ; $ event -> setData ( $ data ) ; } } }
docstring: Validate file.
  
  @param File $file
  @param FormEvent $event
docstring_tokens: Validate file .