32 $this->mapper = $mapper;
39 private function getPattern()
41 if ($this->pattern ===
null) {
42 $this->pattern =
'~\b(?<class>(?<module>(' 43 . implode(
'[_\\\\]|',
Files::init()->getNamespaces())
44 .
'[_\\\\])[a-zA-Z0-9]+)[a-zA-Z0-9_\\\\]*)\b~';
47 return $this->pattern;
53 private static $tagNameMap = [
60 'virtualType' => [
'type']
76 if (pathinfo($file, PATHINFO_BASENAME) !==
'di.xml') {
80 $dependenciesInfo = [];
81 $scope = $this->mapper->getScopeFromFile($file);
82 foreach ($this->fetchPossibleDependencies(
$contents) as
$type => $deps) {
83 foreach ($deps as $dep) {
84 $dep = $this->mapper->getType($dep, $scope);
85 if (preg_match($this->getPattern(), $dep, $matches)) {
86 $referenceModule = str_replace(
'_',
'\\', $matches[
'module']);
87 if ($currentModule === $referenceModule) {
90 $dependenciesInfo[] = [
91 'module' => $referenceModule,
93 'source' => $matches[
'class'],
98 return $dependenciesInfo;
105 private function fetchPossibleDependencies(
$contents)
107 $doc =
new DOMDocument();
119 private function getSoftDependencies(DOMDocument $doc)
122 foreach (self::$tagNameMap as $tagName => $attributeNames) {
123 $nodes = $doc->getElementsByTagName($tagName);
125 foreach ($nodes as $node) {
126 foreach ($attributeNames as $attributeName) {
127 $result[] = $node->getAttribute($attributeName);
139 private function getHardDependencies(DOMDocument $doc)
142 $xpath =
new DOMXPath($doc);
143 $textNodes = $xpath->query(
'//*[@xsi:type="object"]');
145 foreach ($textNodes as $node) {
__construct(VirtualTypeMapper $mapper)
getDependencyInfo($currentModule, $fileType, $file, &$contents)