meemalabs /
laravel-media-recognition
| 1 | <?php |
||
| 2 | |||
| 3 | namespace Meema\MediaRecognition\Traits; |
||
| 4 | |||
| 5 | trait InteractsWithStorage |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * The disk of where the file to analyze is stored. |
||
| 9 | * |
||
| 10 | * @var string |
||
| 11 | */ |
||
| 12 | protected string $disk; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * The path to the source of the file to analyze. |
||
| 16 | * |
||
| 17 | * @var string |
||
| 18 | */ |
||
| 19 | protected string $source; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * The path to the source of the file to analyze. |
||
| 23 | * |
||
| 24 | * @var string|null |
||
| 25 | */ |
||
| 26 | protected ?string $mimeType = null; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * The id of your model that is related to this recognition. |
||
| 30 | * |
||
| 31 | * @var int|null |
||
| 32 | */ |
||
| 33 | protected ?int $mediaId = null; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Set which S3 disk to use. |
||
| 37 | * |
||
| 38 | * @param string $disk |
||
| 39 | * @return $this |
||
| 40 | */ |
||
| 41 | public function disk(string $disk) |
||
| 42 | { |
||
| 43 | $this->disk = $disk; |
||
| 44 | |||
| 45 | return $this; |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * The equivalent of the S3 Key / the path of the file inside the bucket. |
||
| 50 | * |
||
| 51 | * @param string $source |
||
| 52 | * @param string|null $mimeType |
||
| 53 | * @param int|null $mediaId |
||
| 54 | * @return $this |
||
| 55 | */ |
||
| 56 | public function source(string $source, string $mimeType = null, int $mediaId = null) |
||
| 57 | { |
||
| 58 | $this->source = $source; |
||
| 59 | $this->mimeType = $mimeType; |
||
| 60 | $this->mediaId = $mediaId; |
||
| 61 | |||
| 62 | return $this; |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Alias of source(). |
||
| 67 | * |
||
| 68 | * @param string $source |
||
| 69 | * @param string|null $mimeType |
||
| 70 | * @param int|null $mediaId |
||
| 71 | * @return $this |
||
| 72 | */ |
||
| 73 | public function path(string $source, string $mimeType = null, int $mediaId = null) |
||
| 74 | { |
||
| 75 | return $this->source($source, $mimeType, $mediaId); |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Ensures the source/path not to be null if it is null it will thrown an exception. |
||
| 80 | * |
||
| 81 | * @return void |
||
| 82 | * @throws \Exception |
||
| 83 | */ |
||
| 84 | public function ensureSourceIsNotNull() |
||
| 85 | { |
||
| 86 | if (is_null($this->source)) { |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 87 | throw new \Exception('Please set a $source to run the analysis on'); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 |