|
30 | 30 | regexpPhpFile = regexp.MustCompile(`(?://)?(/[^ ]*\.php)`) |
31 | 31 | regexpFilename = regexp.MustCompile(`filename=["]?file://(\S+)/Data/Temporary/[^/]*/Cache/Code/Flow_Object_Classes/([^"]*)\.php`) |
32 | 32 | regexpPathAndFilename = regexp.MustCompile(`(?m)^# PathAndFilename: (.*)$`) |
33 | | - regexpPackageClass = regexp.MustCompile(`(.*?)/Packages/(.*?)/Classes/(.*).php`) |
| 33 | + regexpPackageClass = regexp.MustCompile(`(.*?)/Packages/[^/]*/(.*?)/Classes/(.*).php`) |
34 | 34 | regexpDot = regexp.MustCompile(`[\./]`) |
35 | 35 | ) |
36 | 36 |
|
@@ -172,21 +172,36 @@ func (p *PathMapper) readOriginalPathFromCache(path string) string { |
172 | 172 | } |
173 | 173 |
|
174 | 174 | func (p *PathMapper) buildClassNameFromPath(path string) (string, string) { |
| 175 | + basePath, className := pathToClassPath(path) |
| 176 | + if className == "" { |
| 177 | + // Other (vendor) packages, todo add support for vendor package with Flow proxy class |
| 178 | + p.logger.Warn(h, "Vendor package detected") |
| 179 | + p.logger.Warn("Class mapping not supported currently for path: %s, \n", path) |
| 180 | + } |
| 181 | + return basePath, className |
| 182 | +} |
| 183 | + |
| 184 | +// Convert absolute path to class path (internal use only) |
| 185 | +func pathToClassPath(path string) (string, string) { |
175 | 186 | var ( |
176 | 187 | basePath string |
177 | | - className string |
| 188 | + classPath string |
178 | 189 | ) |
179 | 190 | match := regexpPackageClass.FindStringSubmatch(path) |
180 | 191 | if len(match) == 4 { |
181 | 192 | // Flow standard packages |
| 193 | + packagePath := regexpDot.ReplaceAllString(match[2], "/") |
| 194 | + classPath = match[3] |
| 195 | + if strings.Contains(classPath, packagePath) == false { |
| 196 | + // Quick'n dirty PSR4 support |
| 197 | + classPath = packagePath + "/" + classPath |
| 198 | + } |
182 | 199 | basePath = match[1] |
183 | | - className = regexpDot.ReplaceAllString(match[3], "_") |
| 200 | + classPath = regexpDot.ReplaceAllString(classPath, "_") |
184 | 201 | } else { |
185 | 202 | // Other (vendor) packages, todo add support for vendor package with Flow proxy class |
186 | | - p.logger.Warn(h, "Vendor package detected") |
187 | | - p.logger.Warn("Class mapping not supported currently for path: %s, \n", path) |
188 | 203 | basePath = path |
189 | | - className = "" |
| 204 | + classPath = "" |
190 | 205 | } |
191 | | - return basePath, className |
| 206 | + return basePath, classPath |
192 | 207 | } |
0 commit comments