|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +/* |
| 6 | + * This file is part of TYPO3 CMS-based extension "db_file_storage" by b13. |
| 7 | + * |
| 8 | + * It is free software; you can redistribute it and/or modify it under |
| 9 | + * the terms of the GNU General Public License, either version 2 |
| 10 | + * of the License, or any later version. |
| 11 | + */ |
| 12 | + |
| 13 | +namespace B13\DbFileStorage\Domain\Model; |
| 14 | + |
| 15 | +use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; |
| 16 | + |
| 17 | +/** |
| 18 | + * Extbase entity that maps a row of `tx_dbfilestorage_domain_model_file`. |
| 19 | + * |
| 20 | + * Use this on the consumer side whenever you want to relate domain models to |
| 21 | + * stored files via Extbase MM relations or ObjectStorage<StoredFileReference> |
| 22 | + * properties — typical pattern: |
| 23 | + * |
| 24 | + * // Domain\Model\Model.php |
| 25 | + * use B13\DbFileStorage\Domain\Model\StoredFileReference; |
| 26 | + * |
| 27 | + * class Task extends AbstractEntity |
| 28 | + * { |
| 29 | + * // @param ObjectStorage<StoredFileReference> $attachments |
| 30 | + * public function __construct( |
| 31 | + * protected ObjectStorage $attachments, |
| 32 | + * // ... |
| 33 | + * ) {} |
| 34 | + * } |
| 35 | +
|
| 36 | + * Note: |
| 37 | + * - StoredFile: full data including bytes; what services hand back. |
| 38 | + * - StoredFileReference: metadata-only handle; what Extbase relations point at. |
| 39 | + */ |
| 40 | +class StoredFileReference extends AbstractEntity implements \JsonSerializable |
| 41 | +{ |
| 42 | + protected string $filename = ''; |
| 43 | + protected string $mimeType = ''; |
| 44 | + protected int $size = 0; |
| 45 | + protected string $sha1 = ''; |
| 46 | + |
| 47 | + public function getFilename(): string |
| 48 | + { |
| 49 | + return $this->filename; |
| 50 | + } |
| 51 | + |
| 52 | + public function getMimeType(): string |
| 53 | + { |
| 54 | + return $this->mimeType; |
| 55 | + } |
| 56 | + |
| 57 | + public function getSize(): int |
| 58 | + { |
| 59 | + return $this->size; |
| 60 | + } |
| 61 | + |
| 62 | + public function getSha1(): string |
| 63 | + { |
| 64 | + return $this->sha1; |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @return array<string, mixed> |
| 69 | + */ |
| 70 | + public function jsonSerialize(): array |
| 71 | + { |
| 72 | + return [ |
| 73 | + 'uid' => $this->getUid(), |
| 74 | + 'filename' => $this->filename, |
| 75 | + 'mimeType' => $this->mimeType, |
| 76 | + 'size' => $this->size, |
| 77 | + 'sha1' => $this->sha1, |
| 78 | + ]; |
| 79 | + } |
| 80 | +} |
0 commit comments