Mark V
1: <?php
2: namespace MOC\V\Core\FileSystem\Component\Bridge\Repository;
3:
4: use MOC\V\Core\FileSystem\Component\Bridge\Bridge;
5: use MOC\V\Core\FileSystem\Component\IBridgeInterface;
6: use MOC\V\Core\FileSystem\Component\Parameter\Repository\FileParameter;
7: use MOC\V\Core\FileSystem\Vendor\Universal\FileLoader;
8: use MOC\V\Core\GlobalsKernel\GlobalsKernel;
9:
10: /**
11: * Class UniversalFileLoader
12: *
13: * @package MOC\V\Core\FileSystem\Component\Bridge
14: */
15: class UniversalFileLoader extends Bridge implements IBridgeInterface
16: {
17:
18: /** @var FileLoader $Instance */
19: private $Instance = null;
20:
21: /**
22: * @param FileParameter $FileOption
23: */
24: public function __construct(FileParameter $FileOption)
25: {
26:
27: parent::__construct();
28: $this->Instance = new FileLoader($FileOption->getFile());
29: }
30:
31: /**
32: * @return string
33: */
34: public function __toString()
35: {
36:
37: if ($this->getRealPath()) {
38: return (string)file_get_contents($this->getRealPath());
39: } else {
40: return '';
41: }
42: }
43:
44: /**
45: * @return string
46: */
47: public function getRealPath()
48: {
49:
50: $SERVER = GlobalsKernel::getGlobals()->getSERVER();
51: $SplFileInfo = (new \SplFileInfo($this->Instance->getLocation()));
52: if (!$SplFileInfo->getRealPath()) {
53: $SplFileInfo = (new \SplFileInfo($SERVER['DOCUMENT_ROOT'].$this->Instance->getLocation()));
54: }
55: return $SplFileInfo->getRealPath() ? $SplFileInfo->getRealPath() : '';
56: }
57:
58: /**
59: * @return string
60: */
61: public function getLocation()
62: {
63:
64: return $this->Instance->getLocation();
65: }
66: }
67: