-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFactory.php
More file actions
34 lines (29 loc) · 862 Bytes
/
Factory.php
File metadata and controls
34 lines (29 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
declare(strict_types=1);
/**
* This file is part of MineAdmin.
*
* @link https://www.mineadmin.com
* @document https://doc.mineadmin.com
* @contact root@imoi.cn
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE
*/
namespace Mine\Upload;
use Mine\Upload\Event\UploadEvent;
use Mine\Upload\Exception\UploadFailException;
use Psr\EventDispatcher\EventDispatcherInterface;
final class Factory implements UploadInterface
{
public function __construct(
private readonly EventDispatcherInterface $dispatcher
) {}
public function upload(\SplFileInfo $fileInfo): Upload
{
$event = new UploadEvent($fileInfo);
$this->dispatcher->dispatch($event);
if ($event->isUploaded()) {
return $event->getUpload();
}
throw new UploadFailException($event);
}
}