Skip to content

Commit

Permalink
TASK: Add support for PSR4 Flow package
Browse files Browse the repository at this point in the history
Fixes #3
  • Loading branch information
dfeyer committed Dec 29, 2015
1 parent 5dc1d13 commit 12dd444
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
29 changes: 22 additions & 7 deletions flowpathmapper/flowpathmapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var (
regexpPhpFile = regexp.MustCompile(`(?://)?(/[^ ]*\.php)`)
regexpFilename = regexp.MustCompile(`filename=["]?file://(\S+)/Data/Temporary/[^/]*/Cache/Code/Flow_Object_Classes/([^"]*)\.php`)
regexpPathAndFilename = regexp.MustCompile(`(?m)^# PathAndFilename: (.*)$`)
regexpPackageClass = regexp.MustCompile(`(.*?)/Packages/(.*?)/Classes/(.*).php`)
regexpPackageClass = regexp.MustCompile(`(.*?)/Packages/[^/]*/(.*?)/Classes/(.*).php`)
regexpDot = regexp.MustCompile(`[\./]`)
)

Expand Down Expand Up @@ -172,21 +172,36 @@ func (p *PathMapper) readOriginalPathFromCache(path string) string {
}

func (p *PathMapper) buildClassNameFromPath(path string) (string, string) {
basePath, className := pathToClassPath(path)
if className == "" {
// Other (vendor) packages, todo add support for vendor package with Flow proxy class
p.logger.Warn(h, "Vendor package detected")
p.logger.Warn("Class mapping not supported currently for path: %s, \n", path)
}
return basePath, className
}

// Convert absolute path to class path (internal use only)
func pathToClassPath(path string) (string, string) {
var (
basePath string
className string
classPath string
)
match := regexpPackageClass.FindStringSubmatch(path)
if len(match) == 4 {
// Flow standard packages
packagePath := regexpDot.ReplaceAllString(match[2], "/")
classPath = match[3]
if strings.Contains(classPath, packagePath) == false {
// Quick'n dirty PSR4 support
classPath = packagePath + "/" + classPath
}
basePath = match[1]
className = regexpDot.ReplaceAllString(match[3], "_")
classPath = regexpDot.ReplaceAllString(classPath, "_")
} else {
// Other (vendor) packages, todo add support for vendor package with Flow proxy class
p.logger.Warn(h, "Vendor package detected")
p.logger.Warn("Class mapping not supported currently for path: %s, \n", path)
basePath = path
className = ""
classPath = ""
}
return basePath, className
return basePath, classPath
}
18 changes: 18 additions & 0 deletions flowpathmapper/flowpathmapper_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package flowpathmapper

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestBuildClassNameFromPathSupportPSR2(t *testing.T) {
basePath, className := pathToClassPath("/your/path/sites/dev/master-dev.neos-workplace.dev/Packages/Application/Ttree.FlowDebugProxyHelper/Classes/Ttree/FlowDebugProxyHelper/ProxyClassMapperComponent.php")
assert.Equal(t, "/your/path/sites/dev/master-dev.neos-workplace.dev", basePath, "they should be equal")
assert.Equal(t, "Ttree_FlowDebugProxyHelper_ProxyClassMapperComponent", className, "they should be equal")
}

func TestBuildClassNameFromPathSupportPSR4(t *testing.T) {
basePath, className := pathToClassPath("/your/path/sites/dev/master-dev.neos-workplace.dev/Packages/Application/Ttree.FlowDebugProxyHelper/Classes/ProxyClassMapperComponent.php")
assert.Equal(t, "/your/path/sites/dev/master-dev.neos-workplace.dev", basePath, "they should be equal")
assert.Equal(t, "Ttree_FlowDebugProxyHelper_ProxyClassMapperComponent", className, "they should be equal")
}

0 comments on commit 12dd444

Please sign in to comment.