|
18 | 18 | */
|
19 | 19 | class PhpStorm implements FormatInterface
|
20 | 20 | {
|
| 21 | + const PROJECT_PATH_IDENTIFIER = '$PROJECT_DIR$'; |
| 22 | + const IDEA_PATH = '.idea'; |
21 | 23 |
|
22 | 24 | /**
|
23 | 25 | * @var WriteFactory
|
@@ -54,6 +56,8 @@ public function generateCatalog(array $dictionary, $configFilePath)
|
54 | 56 | $componentNode = null;
|
55 | 57 | $projectNode = null;
|
56 | 58 |
|
| 59 | + $ideaDir = $this->resolveProjectPath($configFilePath); |
| 60 | + |
57 | 61 | try {
|
58 | 62 | $file = $this->fileWriteFactory->create(
|
59 | 63 | $configFilePath,
|
@@ -89,7 +93,7 @@ public function generateCatalog(array $dictionary, $configFilePath)
|
89 | 93 | foreach ($dictionary as $urn => $xsdPath) {
|
90 | 94 | $node = $dom->createElement('resource');
|
91 | 95 | $node->setAttribute('url', $urn);
|
92 |
| - $node->setAttribute('location', $xsdPath); |
| 96 | + $node->setAttribute('location', $this->getFileLocationInProject($ideaDir, $xsdPath)); |
93 | 97 | $componentNode->appendChild($node);
|
94 | 98 | }
|
95 | 99 | $dom->formatOutput = true;
|
@@ -123,4 +127,27 @@ private function initEmptyFile(\DOMDocument $dom)
|
123 | 127 | $projectNode->appendChild($rootComponentNode);
|
124 | 128 | return $projectNode;
|
125 | 129 | }
|
| 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 | + } |
126 | 153 | }
|
0 commit comments