|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the limit0/assets package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Limit Zero, LLC <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Limit0\Assets; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* The AssetManager provides a wrapper for your configured storage engine. |
|
16
|
|
|
* |
|
17
|
|
|
* @author Josh Worden <[email protected]> |
|
18
|
|
|
*/ |
|
19
|
|
|
class AssetManager |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var StorageEngineInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
private $storageEngine; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Returns the storage engine |
|
28
|
|
|
* |
|
29
|
|
|
* @throws Exception\ManagerException |
|
30
|
|
|
* @return StorageEngineInterface |
|
31
|
|
|
*/ |
|
32
|
|
|
public function getStorageEngine() |
|
33
|
|
|
{ |
|
34
|
|
|
if (null === $this->storageEngine) { |
|
35
|
|
|
throw Exception\ManagerException::missingStorageEngine(); |
|
36
|
|
|
} |
|
37
|
|
|
return $this->storageEngine; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Removes an asset |
|
42
|
|
|
* |
|
43
|
|
|
* @param string $identifier |
|
44
|
|
|
*/ |
|
45
|
|
|
public function remove($identifier) |
|
46
|
|
|
{ |
|
47
|
|
|
return $this->getStorageEngine()->remove($identifier); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Retrieves an asset |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $identifier |
|
54
|
|
|
* @return Asset |
|
55
|
|
|
*/ |
|
56
|
|
|
public function retrieve($identifier) |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->getStorageEngine()->retrieve($identifier); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Stores an asset |
|
63
|
|
|
* |
|
64
|
|
|
* @param Asset $asset |
|
65
|
|
|
* @return Asset |
|
66
|
|
|
*/ |
|
67
|
|
|
public function store(Asset $asset, $path = null, $filename = null) |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->getStorageEngine()->store($asset, $path, $filename); |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Sets the storage engine |
|
74
|
|
|
* |
|
75
|
|
|
* @param StorageEngineInterface |
|
76
|
|
|
*/ |
|
77
|
|
|
public function setStorageEngine(StorageEngineInterface $storageEngine) |
|
78
|
|
|
{ |
|
79
|
|
|
$this->storageEngine = $storageEngine; |
|
80
|
|
|
return $this; |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|