/** * Test that method returns true if is temporary file. */ public function testIsTmpFile() { $file = new File(); $this->assertFalse($file->isTmpFile()); $file->setTmpPathname('/tmp/path'); $this->assertTrue($file->isTmpFile()); }
/** * {@inheritdoc} */ public function setFile(File $file) { // "updating" or "replacing" an already existing file is not allowed if (!$file->isTmpFile()) { throw new \RuntimeException(sprintf('Updating or replacing an existing physical file is not allowed. You should rather create a new Attachment entity.')); } $this->file = $file; return $this; }
/** * {@inheritdoc} */ public function persist(File $file) : bool { // only write temporary, i.e. not yet persisted files, to backend file storage if ($file->isTmpFile()) { // use streams for writing to backend file storage $stream = fopen($file->getTmpPathname(), 'r+'); return $this->filesystem->writeStream($file->getKey(), $stream); } return true; }