Mark V
1: <?php
2: namespace MOC\V\Core\AutoLoader;
3:
4: require_once( __DIR__.'/Exception/AutoLoaderException.php' );
5:
6: require_once( __DIR__.'/Component/Exception/ComponentException.php' );
7: require_once( __DIR__.'/Component/Exception/Repository/DirectoryNotFoundException.php' );
8: require_once( __DIR__.'/Component/Exception/Repository/EmptyDirectoryException.php' );
9: require_once( __DIR__.'/Component/Exception/Repository/EmptyNamespaceException.php' );
10:
11: require_once( __DIR__.'/Component/IVendorInterface.php' );
12: require_once( __DIR__.'/Vendor/Vendor.php' );
13:
14: require_once( __DIR__.'/Component/IParameterInterface.php' );
15: require_once( __DIR__.'/Component/Parameter/Parameter.php' );
16: require_once( __DIR__.'/Component/Parameter/Repository/NamespaceParameter.php' );
17: require_once( __DIR__.'/Component/Parameter/Repository/DirectoryParameter.php' );
18:
19: require_once( __DIR__.'/Component/IBridgeInterface.php' );
20: require_once( __DIR__.'/Component/Bridge/Bridge.php' );
21: require_once( __DIR__.'/Component/Bridge/Repository/MultitonNamespace.php' );
22: require_once( __DIR__.'/Component/Bridge/Repository/UniversalNamespace.php' );
23:
24: require_once( __DIR__.'/Vendor/Multiton/NamespaceLoader.php' );
25: require_once( __DIR__.'/Vendor/Universal/NamespaceLoader/NamespaceMapping.php' );
26: require_once( __DIR__.'/Vendor/Universal/NamespaceLoader/NamespaceSearch.php' );
27: require_once( __DIR__.'/Vendor/Universal/NamespaceLoader.php' );
28:
29: use MOC\V\Core\AutoLoader\Component\Bridge\Repository\MultitonNamespace;
30: use MOC\V\Core\AutoLoader\Component\Bridge\Repository\UniversalNamespace;
31: use MOC\V\Core\AutoLoader\Component\IBridgeInterface;
32: use MOC\V\Core\AutoLoader\Component\IVendorInterface;
33: use MOC\V\Core\AutoLoader\Component\Parameter\Repository\DirectoryParameter;
34: use MOC\V\Core\AutoLoader\Component\Parameter\Repository\NamespaceParameter;
35: use MOC\V\Core\AutoLoader\Vendor\Vendor;
36:
37: /**
38: * Class AutoLoader
39: *
40: * @package MOC\V\Core\AutoLoader
41: */
42: class AutoLoader implements IVendorInterface
43: {
44:
45: /** @var IVendorInterface $VendorInterface */
46: private $VendorInterface = null;
47:
48: /**
49: * @param IVendorInterface $VendorInterface
50: */
51: public function __construct(IVendorInterface $VendorInterface)
52: {
53:
54: $this->setVendorInterface($VendorInterface);
55: }
56:
57: /**
58: * @param string $Namespace
59: * @param string $Directory
60: * @param null|string $Prefix
61: *
62: * @return IBridgeInterface
63: */
64: public static function getNamespaceAutoLoader($Namespace, $Directory, $Prefix = null)
65: {
66:
67: return self::getMultitonNamespaceAutoLoader($Namespace, $Directory, $Prefix);
68: }
69:
70: /**
71: * @param string $Namespace
72: * @param string $Directory
73: * @param null|string $Prefix
74: *
75: * @return IBridgeInterface
76: */
77: public static function getMultitonNamespaceAutoLoader($Namespace, $Directory, $Prefix = null)
78: {
79:
80: $Loader = new AutoLoader(
81: new Vendor(
82: new MultitonNamespace(
83: new NamespaceParameter($Namespace),
84: new DirectoryParameter($Directory),
85: new NamespaceParameter($Prefix))
86: )
87: );
88: $Loader->getBridgeInterface()->registerLoader();
89:
90: return $Loader->getBridgeInterface();
91: }
92:
93: /**
94: * @return IBridgeInterface
95: */
96: public function getBridgeInterface()
97: {
98:
99: return $this->VendorInterface->getBridgeInterface();
100: }
101:
102: /**
103: * @param string $Namespace
104: * @param string $Directory
105: *
106: * @return IBridgeInterface
107: */
108: public static function getUniversalNamespaceAutoLoader($Namespace, $Directory)
109: {
110:
111: $Loader = new AutoLoader(
112: new Vendor(
113: new UniversalNamespace()
114: )
115: );
116: $Loader->getBridgeInterface()->addNamespaceDirectoryMapping(
117: new NamespaceParameter($Namespace), new DirectoryParameter($Directory)
118: );
119: $Loader->getBridgeInterface()->registerLoader();
120:
121: return $Loader->getBridgeInterface();
122: }
123:
124: /**
125: * @return IVendorInterface
126: */
127: public function getVendorInterface()
128: {
129:
130: return $this->VendorInterface;
131: }
132:
133: /**
134: * @param IVendorInterface $VendorInterface
135: *
136: * @return IVendorInterface
137: */
138: public function setVendorInterface(IVendorInterface $VendorInterface)
139: {
140:
141: $this->VendorInterface = $VendorInterface;
142: return $this;
143: }
144:
145: /**
146: * @param IBridgeInterface $BridgeInterface
147: *
148: * @return IBridgeInterface
149: */
150: public function setBridgeInterface(IBridgeInterface $BridgeInterface)
151: {
152:
153: return $this->VendorInterface->setBridgeInterface($BridgeInterface);
154: }
155: }
156: