Mark V
1: <?php
2: namespace MOC\V\Core\AutoLoader\Vendor\Universal;
3:
4: use MOC\V\Core\AutoLoader\Vendor\Universal\NamespaceLoader\NamespaceSearch;
5:
6: /**
7: * Class NamespaceLoader
8: *
9: * @package MOC\V\Core\AutoLoader\Vendor\Universal
10: */
11: class NamespaceLoader extends NamespaceSearch
12: {
13:
14: /**
15: * @return string
16: */
17: public function getLoaderHash()
18: {
19:
20: return sha1(
21: serialize(
22: get_object_vars($this)
23: )
24: );
25: }
26:
27: /**
28: * @param string $ClassName
29: *
30: * @return bool
31: */
32: public function loadClass($ClassName)
33: {
34:
35: if ($this->findSource($ClassName)) {
36: return true;
37: }
38: return false;
39: }
40:
41: /**
42: * @param string $ClassName
43: *
44: * @return bool
45: */
46: private function findSource($ClassName)
47: {
48:
49: $LoadNamespace = $this->getClassNamespace($ClassName);
50: /**
51: * @var string $Namespace
52: * @var array $DirectoryList
53: */
54: foreach ((array)$this->getNamespaceList() as $Namespace) {
55: if (empty( $LoadNamespace ) || empty( $Namespace ) || 0 !== strpos($LoadNamespace, $Namespace)) {
56: continue;
57: }
58: $DirectoryList = $this->getNamespaceMapping($Namespace);
59: if ($this->searchForClass($DirectoryList, $ClassName)) {
60: // @codeCoverageIgnoreStart
61: return true;
62: // @codeCoverageIgnoreEnd
63: }
64: if ($this->searchForClassFallback($DirectoryList, $ClassName, $Namespace)) {
65: // @codeCoverageIgnoreStart
66: return true;
67: // @codeCoverageIgnoreEnd
68: }
69: if ($this->searchForInterface($DirectoryList, $ClassName)) {
70: // @codeCoverageIgnoreStart
71: return true;
72: // @codeCoverageIgnoreEnd
73: }
74: if ($this->searchForInterfaceFallback($DirectoryList, $ClassName, $Namespace)) {
75: // @codeCoverageIgnoreStart
76: return true;
77: // @codeCoverageIgnoreEnd
78: }
79: }
80: return false;
81: }
82:
83: /**
84: * @param string $ClassName
85: *
86: * @return string
87: */
88: protected function getClassNamespace($ClassName)
89: {
90:
91: return substr($ClassName, 0, strrpos($ClassName, '\\'));
92: }
93: }
94:
95: