Mark V
1: <?php
2: namespace MOC\V\Core\FileSystem;
3:
4: use MOC\V\Core\FileSystem\Component\Bridge\Repository\SymfonyFinder;
5: use MOC\V\Core\FileSystem\Component\Bridge\Repository\UniversalDownload;
6: use MOC\V\Core\FileSystem\Component\Bridge\Repository\UniversalFileLoader;
7: use MOC\V\Core\FileSystem\Component\Bridge\Repository\UniversalFileWriter;
8: use MOC\V\Core\FileSystem\Component\IBridgeInterface;
9: use MOC\V\Core\FileSystem\Component\IVendorInterface;
10: use MOC\V\Core\FileSystem\Component\Parameter\Repository\FileParameter;
11: use MOC\V\Core\FileSystem\Exception\FileSystemException;
12: use MOC\V\Core\FileSystem\Vendor\Vendor;
13:
14: /**
15: * Class FileSystem
16: *
17: * @package MOC\V\Core\FileSystem
18: */
19: class FileSystem implements IVendorInterface
20: {
21:
22: /** @var IVendorInterface $VendorInterface */
23: private $VendorInterface = null;
24:
25: /**
26: * @param IVendorInterface $VendorInterface
27: */
28: public function __construct(IVendorInterface $VendorInterface)
29: {
30:
31: $this->setVendorInterface($VendorInterface);
32: }
33:
34: /**
35: * @param string $Location
36: *
37: * @return IBridgeInterface
38: * @throws FileSystemException
39: */
40: public static function getFileLoader($Location)
41: {
42:
43: $Result = self::getUniversalFileLoader($Location);
44: if (!$Result->getRealPath()) {
45: return self::getSymfonyFinder($Location);
46: }
47: return $Result;
48: }
49:
50: /**
51: * @param string $Location
52: *
53: * @return IBridgeInterface
54: */
55: private static function getUniversalFileLoader($Location)
56: {
57:
58: $Loader = new FileSystem(
59: new Vendor(
60: new UniversalFileLoader(
61: new FileParameter($Location)
62: )
63: )
64: );
65:
66: return $Loader->getBridgeInterface();
67: }
68:
69: /**
70: * @return IBridgeInterface
71: */
72: public function getBridgeInterface()
73: {
74:
75: return $this->VendorInterface->getBridgeInterface();
76: }
77:
78: /**
79: * @param string $Location
80: *
81: * @return IBridgeInterface
82: */
83: private static function getSymfonyFinder($Location)
84: {
85:
86: $Loader = new FileSystem(
87: new Vendor(
88: new SymfonyFinder(
89: new FileParameter($Location)
90: )
91: )
92: );
93:
94: return $Loader->getBridgeInterface();
95: }
96:
97: /**
98: * @param string $Location
99: * @param null|string $Filename
100: *
101: * @return IBridgeInterface
102: * @throws FileSystemException
103: */
104: public static function getDownload($Location, $Filename = null)
105: {
106:
107: return self::getUniversalDownload($Location, $Filename);
108: }
109:
110: /**
111: * @param string $Location
112: * @param null|string $Filename
113: *
114: * @return IBridgeInterface
115: */
116: private static function getUniversalDownload($Location, $Filename = null)
117: {
118:
119: $Loader = new FileSystem(
120: new Vendor(
121: new UniversalDownload(
122: new FileParameter($Location),
123: new FileParameter($Filename)
124: )
125: )
126: );
127:
128: return $Loader->getBridgeInterface();
129: }
130:
131: /**
132: * @param string $Location
133: *
134: * @return IBridgeInterface
135: * @throws FileSystemException
136: */
137: public static function getFileWriter($Location)
138: {
139:
140: return self::getUniversalFileWriter($Location);
141: }
142:
143: /**
144: * @param string $Location
145: *
146: * @return IBridgeInterface
147: */
148: private static function getUniversalFileWriter($Location)
149: {
150:
151: $Loader = new FileSystem(
152: new Vendor(
153: new UniversalFileWriter(
154: new FileParameter($Location)
155: )
156: )
157: );
158:
159: return $Loader->getBridgeInterface();
160: }
161:
162: /**
163: * @return IVendorInterface
164: */
165: public function getVendorInterface()
166: {
167:
168: return $this->VendorInterface;
169: }
170:
171: /**
172: * @param IVendorInterface $VendorInterface
173: *
174: * @return IVendorInterface
175: */
176: public function setVendorInterface(IVendorInterface $VendorInterface)
177: {
178:
179: $this->VendorInterface = $VendorInterface;
180: return $this;
181: }
182:
183: /**
184: * @param IBridgeInterface $BridgeInterface
185: *
186: * @return IBridgeInterface
187: */
188: public function setBridgeInterface(IBridgeInterface $BridgeInterface)
189: {
190:
191: return $this->VendorInterface->setBridgeInterface($BridgeInterface);
192: }
193: }
194: