1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2016 |
6
|
|
|
* @package MW |
7
|
|
|
* @subpackage Filesystem |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\MW\Filesystem\Manager; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Standard file system manager |
16
|
|
|
* |
17
|
|
|
* @package MW |
18
|
|
|
* @subpackage Filesystem |
19
|
|
|
*/ |
20
|
|
|
class Standard implements Iface |
21
|
|
|
{ |
22
|
|
|
private $config; |
23
|
|
|
private $objects = []; |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Initializes the object |
28
|
|
|
* |
29
|
|
|
* @param \Aimeos\MW\Config\Iface $config Configuration object |
30
|
|
|
*/ |
31
|
|
|
public function __construct( \Aimeos\MW\Config\Iface $config ) |
32
|
|
|
{ |
33
|
|
|
$this->config = $config; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Cleans up the object |
39
|
|
|
*/ |
40
|
|
|
public function __destruct() |
41
|
|
|
{ |
42
|
|
|
foreach( $this->objects as $object ) { |
43
|
|
|
unset( $object ); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Clones the objects inside. |
50
|
|
|
*/ |
51
|
|
|
public function __clone() |
52
|
|
|
{ |
53
|
|
|
$this->config = clone $this->config; |
54
|
|
|
|
55
|
|
|
foreach( $this->objects as $name => $object ) { |
56
|
|
|
unset( $this->objects[$name] ); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Returns the file system for the given name |
63
|
|
|
* |
64
|
|
|
* @param string $name Key for the file system |
65
|
|
|
* @return \Aimeos\MW\Filesystem\Iface File system object |
66
|
|
|
* @throws \Aimeos\MW\Filesystem\Exception If an no configuration for that name is found |
67
|
|
|
*/ |
68
|
|
|
public function get( $name ) |
69
|
|
|
{ |
70
|
|
|
$conf = (array) $this->getConfig( $name ); |
71
|
|
|
|
72
|
|
|
if( !isset( $this->objects[$name] ) ) { |
73
|
|
|
$this->objects[$name] = \Aimeos\MW\Filesystem\Factory::create( $conf ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $this->objects[$name]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Returns the configuration for the given name |
82
|
|
|
* |
83
|
|
|
* @param string $name Name of the resource, e.g. "fs" or "fs-media" |
84
|
|
|
* @return array|string Configuration values |
85
|
|
|
* @throws \Aimeos\MW\Filesystem\Exception If an no configuration for that name is found |
86
|
|
|
*/ |
87
|
|
|
protected function getConfig( $name ) |
88
|
|
|
{ |
89
|
|
|
if( ( $conf = $this->config->get( 'resource/' . $name ) ) !== null ) { |
90
|
|
|
return $conf; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$name = 'fs'; |
94
|
|
|
if( ( $conf = $this->config->get( 'resource/fs' ) ) !== null ) { |
95
|
|
|
return $conf; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$msg = sprintf( 'No resource configuration for "%1$s" available', $name ); |
99
|
|
|
throw new \Aimeos\MW\Filesystem\Exception( $msg ); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|