예제 #1
0
 public function it_can_transform_file_to_array()
 {
     $attributes = $this->getAttributes($this->file);
     $attributes['name']->shouldBe($this->file->getName()->toString());
     $attributes['path']->shouldBe($this->file->getPath()->toString());
     $attributes['mime_type']->shouldBe($this->file->getMimeType()->toString());
     $attributes['meta']->shouldBe(['created' => $this->file->metaDataGetCreatedTimestamp()->format('c'), 'updated' => $this->file->metaDataGetUpdatedTimestamp()->format('c')]);
 }
예제 #2
0
 public function it_can_create_an_image(File $oldFile)
 {
     $name = FileNameValue::get('oldName.jpg');
     $path = FilePathValue::get('/path/to/something');
     $mime = MimeTypeValue::get('image/jpg');
     $oldFile->getName()->willReturn($name);
     $oldFile->getPath()->willReturn($path);
     $oldFile->getMimeType()->willReturn($mime);
     $imageContents = tmpfile();
     $this->fileRepository->createFromUpload(new Argument\Token\TypeToken(File::class));
     $newImage = $this->createImage($oldFile, $imageContents);
     $newImage->getUuid()->shouldHaveType(Uuid::class);
     $newImage->getName()->shouldReturn($name);
     $newImage->getPath()->shouldReturn($path);
     $newImage->getMimeType()->shouldReturn($mime);
     $newImage->getStream()->shouldReturn($imageContents);
 }
예제 #3
0
 public function updateMetaData(File $file)
 {
     $this->pdo->beginTransaction();
     try {
         $query = $this->executeSql('
             UPDATE files
                SET name = :name,
                    path = :path,
                    mime_type = :mime_type
              WHERE file_uuid = :file_uuid
         ', ['file_uuid' => $file->getUuid()->getBytes(), 'name' => $file->getName()->toString(), 'path' => $file->getPath()->toString(), 'mime_type' => $file->getMimeType()->toString()]);
         // When at least one of the fields changes, the rowCount will be 1 and an update occurred
         if ($query->rowCount() === 1) {
             $this->objectRepository->update(File::TYPE, $file->getUuid());
             $file->metaDataSetUpdateTimestamp(new \DateTimeImmutable());
         }
         $this->pdo->commit();
     } catch (\Throwable $exception) {
         $this->pdo->rollBack();
         throw $exception;
     }
 }
예제 #4
0
 public function createImage(File $file, $imageContents) : File
 {
     $newFile = new File(Uuid::uuid4(), $file->getName(), $file->getPath(), $file->getMimeType(), $imageContents);
     $this->fileRepository->createFromUpload($newFile);
     return $newFile;
 }