Skip to content

Commit 767af1f

Browse files
committed
Resolve $PROJECT_DIR$ when generating PHPStorm xml
1 parent 0db89b2 commit 767af1f

File tree

1 file changed

+28
-1
lines changed
  • app/code/Magento/Developer/Model/XmlCatalog/Format

1 file changed

+28
-1
lines changed

app/code/Magento/Developer/Model/XmlCatalog/Format/PhpStorm.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
*/
1919
class PhpStorm implements FormatInterface
2020
{
21+
const PROJECT_PATH_IDENTIFIER = '$PROJECT_DIR$';
22+
const IDEA_PATH = '.idea';
2123

2224
/**
2325
* @var WriteFactory
@@ -54,6 +56,8 @@ public function generateCatalog(array $dictionary, $configFilePath)
5456
$componentNode = null;
5557
$projectNode = null;
5658

59+
$ideaDir = $this->resolveProjectPath($configFilePath);
60+
5761
try {
5862
$file = $this->fileWriteFactory->create(
5963
$configFilePath,
@@ -89,7 +93,7 @@ public function generateCatalog(array $dictionary, $configFilePath)
8993
foreach ($dictionary as $urn => $xsdPath) {
9094
$node = $dom->createElement('resource');
9195
$node->setAttribute('url', $urn);
92-
$node->setAttribute('location', $xsdPath);
96+
$node->setAttribute('location', $this->getFileLocationInProject($ideaDir, $xsdPath));
9397
$componentNode->appendChild($node);
9498
}
9599
$dom->formatOutput = true;
@@ -123,4 +127,27 @@ private function initEmptyFile(\DOMDocument $dom)
123127
$projectNode->appendChild($rootComponentNode);
124128
return $projectNode;
125129
}
130+
131+
/**
132+
* Resolve PhpStorm Project Path
133+
*
134+
* @param string $configFilePath
135+
* @return string
136+
*/
137+
public function resolveProjectPath($configFilePath): string
138+
{
139+
return \str_replace('/' . self::IDEA_PATH, '', realpath(dirname($configFilePath)));
140+
}
141+
142+
/**
143+
* Resolve xsdpath to xml project path
144+
*
145+
* @param string $ideaDir
146+
* @param string $xsdPath
147+
* @return string
148+
*/
149+
public function getFileLocationInProject(string $ideaDir, string $xsdPath): string
150+
{
151+
return \str_replace($ideaDir, self::PROJECT_PATH_IDENTIFIER, $xsdPath);
152+
}
126153
}

0 commit comments

Comments
 (0)