Mark V
1: <?php
2: namespace MOC\V\Core\AutoLoader\Vendor\Universal\NamespaceLoader;
3:
4: /**
5: * Class NamespaceSearch
6: *
7: * @package MOC\V\Core\AutoLoader\Vendor\Universal
8: */
9: abstract class NamespaceSearch extends NamespaceMapping
10: {
11:
12: /**
13: * @param array $DirectoryList
14: * @param string $ClassName
15: * @param string $Namespace
16: *
17: * @return bool
18: */
19: protected function searchForInterfaceFallback($DirectoryList, $ClassName, $Namespace)
20: {
21:
22: return $this->searchForInterface($DirectoryList,
23: trim(preg_replace('!^'.preg_quote($Namespace).'!is', '', $ClassName), '\\')
24: );
25: }
26:
27: /**
28: * @param array $DirectoryList
29: * @param string $ClassName
30: *
31: * @return bool
32: */
33: protected function searchForInterface($DirectoryList, $ClassName)
34: {
35:
36: return $this->searchForClass($DirectoryList,
37: preg_replace('!(.*?)I([^'.preg_quote('\\').']*?)Interface$!is', '$1$2', $ClassName));
38: }
39:
40: /**
41: * @param array $DirectoryList
42: * @param string $ClassName
43: *
44: * @return bool
45: */
46: protected function searchForClass($DirectoryList, $ClassName)
47: {
48:
49: foreach ((array)$DirectoryList as $Directory) {
50: $File = $Directory.DIRECTORY_SEPARATOR.str_replace(array('_', '\\', '/'), DIRECTORY_SEPARATOR,
51: $ClassName).'.php';
52: if (is_file($File)) {
53: /** @noinspection PhpIncludeInspection */
54: require_once( $File );
55: return true;
56: }
57: }
58: return false;
59: }
60:
61: /**
62: * @param array $DirectoryList
63: * @param string $ClassName
64: * @param string $Namespace
65: *
66: * @return bool
67: */
68: protected function searchForClassFallback($DirectoryList, $ClassName, $Namespace)
69: {
70:
71: return $this->searchForClass($DirectoryList,
72: trim(preg_replace('!^'.preg_quote($Namespace).'!is', '', $ClassName), '\\')
73: );
74: }
75: }
76: