1 | <?php |
||
9 | class UploadFileStorageProvider extends FileStorageProvider |
||
10 | { |
||
11 | private $targetDirectory; |
||
12 | |||
13 | 4 | public function __construct($targetDirectory, StorageFactoryInterface $storageFactory = null) |
|
23 | |||
24 | /** |
||
25 | * (non-PHPdoc). |
||
26 | * |
||
27 | * @see \Mathielen\ImportEngine\Storage\Provider\StorageProviderInterface::select() |
||
28 | */ |
||
29 | 2 | public function select($id = null) |
|
30 | { |
||
31 | 2 | if ($id instanceof UploadedFile) { |
|
32 | 2 | if (!$id->isValid()) { |
|
33 | 1 | throw new \InvalidArgumentException('Upload was not successful'); |
|
34 | } |
||
35 | |||
36 | 1 | $newFile = $id->move($this->targetDirectory, $this->generateTargetFilename($id)); |
|
37 | |||
38 | 1 | $selection = new StorageSelection( |
|
39 | 1 | new \SplFileInfo($newFile), |
|
40 | 1 | $this->targetDirectory.'/'.$newFile->getFilename(), |
|
41 | 1 | $id->getClientOriginalName()); |
|
42 | |||
43 | 1 | return $selection; |
|
44 | } |
||
45 | |||
46 | return parent::select($id); |
||
47 | } |
||
48 | |||
49 | 1 | private function generateTargetFilename(UploadedFile $file) |
|
53 | } |
||
54 |