1 | <?php |
||
22 | abstract class StorageServer extends Component implements ServerInterface |
||
23 | { |
||
24 | /** |
||
25 | * Default mimetype to be used when nothing else can be applied. |
||
26 | */ |
||
27 | const DEFAULT_MIMETYPE = 'application/octet-stream'; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $options = []; |
||
33 | |||
34 | /** |
||
35 | * @var FilesInterface |
||
36 | */ |
||
37 | protected $files = null; |
||
38 | |||
39 | /** |
||
40 | * @param FilesInterface $files Required for local filesystem operations. |
||
41 | * @param array $options Server specific options. |
||
42 | */ |
||
43 | public function __construct(FilesInterface $files, array $options) |
||
44 | { |
||
45 | $this->options = $options + $this->options; |
||
46 | $this->files = $files; |
||
47 | } |
||
48 | |||
49 | /** |
||
50 | * {@inheritdoc} |
||
51 | */ |
||
52 | public function allocateFilename(BucketInterface $bucket, $name) |
||
53 | { |
||
54 | if (empty($stream = $this->allocateStream($bucket, $name))) { |
||
55 | throw new ServerException("Unable to allocate local filename for '{$name}'."); |
||
56 | } |
||
57 | |||
58 | //Default implementation will use stream to create temporary filename, such filename |
||
59 | //can't be used outside php scope |
||
60 | return StreamWrapper::getUri($stream); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | public function copy(BucketInterface $bucket, BucketInterface $destination, $name) |
||
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | public function replace(BucketInterface $bucket, BucketInterface $destination, $name) |
||
84 | |||
85 | /** |
||
86 | * Cast local filename to be used in file based methods and etc. |
||
87 | * |
||
88 | * @param string|StreamInterface $source |
||
89 | * @return string |
||
90 | */ |
||
91 | protected function castFilename($source) |
||
116 | |||
117 | /** |
||
118 | * Cast stream associated with origin data. |
||
119 | * |
||
120 | * @param string|StreamInterface $source |
||
121 | * @return StreamInterface |
||
122 | */ |
||
123 | protected function castStream($source) |
||
140 | } |