/** * @return File */ public function getFile() { if ($this->file) { return $this->file; } // validate $this->validate(); // test if format supported if ($this->supportedFormats && !in_array($this->file->getExtension(), $this->supportedFormats)) { throw new WrongFormatException('File type not allowed'); } // check checksum if ($this->isChecksumValidationAllowed) { if ($this->getExpectedChecksum() !== $this->file->getChecksum()) { throw new WrongChecksumException('Checksum missmatch'); } } // build file $this->file = $this->buildFile(); return $this->file; }
private function buildTargetBasename(File $sourceFile, $targetFilename = null) { if ($targetFilename) { $extension = $sourceFile->getExtension(); if ($extension) { $targetBasename = $targetFilename . '.' . $extension; } else { $targetBasename = $targetFilename; } } else { $targetBasename = $sourceFile->getOriginalBasename(); } return $targetBasename; }