|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the eZ Publish Kernel package. |
|
5
|
|
|
* |
|
6
|
|
|
* @copyright Copyright (C) eZ Systems AS. All rights reserved. |
|
7
|
|
|
* @license For full copyright and license information view LICENSE file distributed with this source code. |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace eZ\Publish\Core\IO\IOMetadataHandler; |
|
10
|
|
|
|
|
11
|
|
|
use DateTime; |
|
12
|
|
|
use eZ\Publish\Core\IO\Exception\BinaryFileNotFoundException; |
|
13
|
|
|
use eZ\Publish\Core\IO\IOMetadataHandler; |
|
14
|
|
|
use eZ\Publish\SPI\IO\BinaryFile as SPIBinaryFile; |
|
15
|
|
|
use eZ\Publish\SPI\IO\BinaryFileCreateStruct as SPIBinaryFileCreateStruct; |
|
16
|
|
|
use League\Flysystem\FileNotFoundException; |
|
17
|
|
|
use League\Flysystem\FilesystemInterface; |
|
18
|
|
|
|
|
19
|
|
|
class Flysystem implements IOMetadataHandler |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
/** @var FilesystemInterface */ |
|
22
|
|
|
private $filesystem; |
|
23
|
|
|
|
|
24
|
|
|
public function __construct(FilesystemInterface $filesystem) |
|
25
|
|
|
{ |
|
26
|
|
|
$this->filesystem = $filesystem; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Only reads & return metadata, since the binarydata handler took care of creating the file already. |
|
31
|
|
|
* |
|
32
|
|
|
* @throws BinaryFileNotFoundException |
|
33
|
|
|
*/ |
|
34
|
|
|
public function create(SPIBinaryFileCreateStruct $spiBinaryFileCreateStruct) |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->load($spiBinaryFileCreateStruct->id); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Does really nothing, the binary data handler takes care of it. |
|
41
|
|
|
* |
|
42
|
|
|
* @param $spiBinaryFileId |
|
43
|
|
|
*/ |
|
44
|
|
|
public function delete($spiBinaryFileId) |
|
45
|
|
|
{ |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function load($spiBinaryFileId) |
|
49
|
|
|
{ |
|
50
|
|
|
try { |
|
51
|
|
|
$info = $this->filesystem->getMetadata($spiBinaryFileId); |
|
52
|
|
|
} catch (FileNotFoundException $e) { |
|
53
|
|
|
throw new BinaryFileNotFoundException($spiBinaryFileId); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$spiBinaryFile = new SPIBinaryFile(); |
|
57
|
|
|
$spiBinaryFile->id = $spiBinaryFileId; |
|
58
|
|
|
$spiBinaryFile->size = $info['size']; |
|
59
|
|
|
|
|
60
|
|
|
if (isset($info['timestamp'])) { |
|
61
|
|
|
$spiBinaryFile->mtime = new DateTime('@' . $info['timestamp']); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return $spiBinaryFile; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function exists($spiBinaryFileId) |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->filesystem->has($spiBinaryFileId); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function getMimeType($spiBinaryFileId) |
|
73
|
|
|
{ |
|
74
|
|
|
return $this->filesystem->getMimetype($spiBinaryFileId); |
|
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Does nothing, as the binarydata handler takes care of it. |
|
79
|
|
|
*/ |
|
80
|
|
|
public function deleteDirectory($spiPath) |
|
81
|
|
|
{ |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|