Skip to content

Commit 12dd444

Browse files
committed
TASK: Add support for PSR4 Flow package
Fixes #3
1 parent 5dc1d13 commit 12dd444

2 files changed

Lines changed: 40 additions & 7 deletions

File tree

flowpathmapper/flowpathmapper.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var (
3030
regexpPhpFile = regexp.MustCompile(`(?://)?(/[^ ]*\.php)`)
3131
regexpFilename = regexp.MustCompile(`filename=["]?file://(\S+)/Data/Temporary/[^/]*/Cache/Code/Flow_Object_Classes/([^"]*)\.php`)
3232
regexpPathAndFilename = regexp.MustCompile(`(?m)^# PathAndFilename: (.*)$`)
33-
regexpPackageClass = regexp.MustCompile(`(.*?)/Packages/(.*?)/Classes/(.*).php`)
33+
regexpPackageClass = regexp.MustCompile(`(.*?)/Packages/[^/]*/(.*?)/Classes/(.*).php`)
3434
regexpDot = regexp.MustCompile(`[\./]`)
3535
)
3636

@@ -172,21 +172,36 @@ func (p *PathMapper) readOriginalPathFromCache(path string) string {
172172
}
173173

174174
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) {
175186
var (
176187
basePath string
177-
className string
188+
classPath string
178189
)
179190
match := regexpPackageClass.FindStringSubmatch(path)
180191
if len(match) == 4 {
181192
// 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+
}
182199
basePath = match[1]
183-
className = regexpDot.ReplaceAllString(match[3], "_")
200+
classPath = regexpDot.ReplaceAllString(classPath, "_")
184201
} else {
185202
// 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)
188203
basePath = path
189-
className = ""
204+
classPath = ""
190205
}
191-
return basePath, className
206+
return basePath, classPath
192207
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package flowpathmapper
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"testing"
6+
)
7+
8+
func TestBuildClassNameFromPathSupportPSR2(t *testing.T) {
9+
basePath, className := pathToClassPath("/your/path/sites/dev/master-dev.neos-workplace.dev/Packages/Application/Ttree.FlowDebugProxyHelper/Classes/Ttree/FlowDebugProxyHelper/ProxyClassMapperComponent.php")
10+
assert.Equal(t, "/your/path/sites/dev/master-dev.neos-workplace.dev", basePath, "they should be equal")
11+
assert.Equal(t, "Ttree_FlowDebugProxyHelper_ProxyClassMapperComponent", className, "they should be equal")
12+
}
13+
14+
func TestBuildClassNameFromPathSupportPSR4(t *testing.T) {
15+
basePath, className := pathToClassPath("/your/path/sites/dev/master-dev.neos-workplace.dev/Packages/Application/Ttree.FlowDebugProxyHelper/Classes/ProxyClassMapperComponent.php")
16+
assert.Equal(t, "/your/path/sites/dev/master-dev.neos-workplace.dev", basePath, "they should be equal")
17+
assert.Equal(t, "Ttree_FlowDebugProxyHelper_ProxyClassMapperComponent", className, "they should be equal")
18+
}

0 commit comments

Comments
 (0)