Skip to content

Commit c3d660b

Browse files
author
Andreas Sacher
committed
BUGFIX: Fix using multiple contexts
1 parent 6fc1c63 commit c3d660b

File tree

4 files changed

+36
-24
lines changed

4 files changed

+36
-24
lines changed

dummypathmapper/dummypathmapper.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,33 @@ import (
99
"github.com/dfeyer/flow-debugproxy/logger"
1010
"github.com/dfeyer/flow-debugproxy/pathmapperfactory"
1111
"github.com/dfeyer/flow-debugproxy/pathmapping"
12+
"github.com/dfeyer/flow-debugproxy/xdebugproxy"
1213
)
1314

1415
const framework = "dummy"
1516

1617
func init() {
17-
p := &PathMapper{}
18+
p := &PathMapperFactory{}
1819
pathmapperfactory.Register(framework, p)
1920
}
2021

22+
type PathMapperFactory struct{}
23+
24+
func (p *PathMapperFactory) Create(c *config.Config, l *logger.Logger, m *pathmapping.PathMapping) xdebugproxy.XDebugProcessorPlugin {
25+
return &PathMapper{
26+
config: c,
27+
logger: l,
28+
pathMapping: m,
29+
}
30+
}
31+
2132
// PathMapper handle the mapping between real code and proxy
2233
type PathMapper struct {
2334
config *config.Config
2435
logger *logger.Logger
2536
pathMapping *pathmapping.PathMapping
2637
}
2738

28-
// Initialize the path mapper dependencies
29-
func (p *PathMapper) Initialize(c *config.Config, l *logger.Logger, m *pathmapping.PathMapping) {
30-
p.config = c
31-
p.logger = l
32-
p.pathMapping = m
33-
}
34-
3539
// ApplyMappingToTextProtocol change file path in xDebug text protocol
3640
func (p *PathMapper) ApplyMappingToTextProtocol(message []byte) ([]byte, error) {
3741
return message, nil

flowpathmapper/flowpathmapper.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/dfeyer/flow-debugproxy/logger"
1010
"github.com/dfeyer/flow-debugproxy/pathmapperfactory"
1111
"github.com/dfeyer/flow-debugproxy/pathmapping"
12+
"github.com/dfeyer/flow-debugproxy/xdebugproxy"
1213

1314
"bytes"
1415
"fmt"
@@ -37,7 +38,7 @@ var (
3738
)
3839

3940
func init() {
40-
p := &PathMapper{}
41+
p := &PathMapperFactory{}
4142
pathmapperfactory.Register(framework, p)
4243
}
4344

@@ -48,20 +49,23 @@ func regexpFilename() *regexp.Regexp {
4849
return regexpFilename__Unix
4950
}
5051

52+
type PathMapperFactory struct{}
53+
54+
func (p *PathMapperFactory) Create(c *config.Config, l *logger.Logger, m *pathmapping.PathMapping) xdebugproxy.XDebugProcessorPlugin {
55+
return &PathMapper{
56+
config: c,
57+
logger: l,
58+
pathMapping: m,
59+
}
60+
}
61+
5162
// PathMapper handle the mapping between real code and proxy
5263
type PathMapper struct {
5364
config *config.Config
5465
logger *logger.Logger
5566
pathMapping *pathmapping.PathMapping
5667
}
5768

58-
// Initialize the path mapper dependencies
59-
func (p *PathMapper) Initialize(c *config.Config, l *logger.Logger, m *pathmapping.PathMapping) {
60-
p.config = c
61-
p.logger = l
62-
p.pathMapping = m
63-
}
64-
6569
// ApplyMappingToTextProtocol change file path in xDebug text protocol
6670
func (p *PathMapper) ApplyMappingToTextProtocol(message []byte) ([]byte, error) {
6771
return p.doTextPathMapping(message), nil
@@ -109,7 +113,9 @@ func (p *PathMapper) getCachePath(base, filename string) string {
109113
context := p.config.Context
110114
if strings.Contains(context, "/") {
111115
contextParts := strings.Split(context, "/")
112-
contextParts[1] = "SubContext" + contextParts[1]
116+
for i := 1; i < len(contextParts); i++ {
117+
contextParts[i] = "SubContext" + contextParts[i]
118+
}
113119
context = strings.Join(contextParts, "/")
114120
}
115121
cachePath = strings.Replace(cachePath, "@context@", context, 1)

pathmapperfactory/pathmapperfactory.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,19 @@ import (
1313
"errors"
1414
)
1515

16-
var pathMapperRegistry = map[string]xdebugproxy.XDebugProcessorPlugin{}
16+
var pathMapperRegistry = map[string]xdebugproxy.XDebugProcessorPluginFactory{}
1717

1818
// Register a path mapper
19-
func Register(f string, p xdebugproxy.XDebugProcessorPlugin) {
19+
func Register(f string, p xdebugproxy.XDebugProcessorPluginFactory) {
2020
pathMapperRegistry[f] = p
2121
}
2222

2323
// Create return a pathmapper for the given framework
2424
func Create(c *config.Config, p *pathmapping.PathMapping, l *logger.Logger) (xdebugproxy.XDebugProcessorPlugin, error) {
2525
if _, exist := pathMapperRegistry[c.Framework]; exist {
26-
pathmapper := pathMapperRegistry[c.Framework]
27-
pathmapper.Initialize(c, l, p)
28-
return pathmapper, nil
26+
pathmapperFactory := pathMapperRegistry[c.Framework]
27+
return pathmapperFactory.Create(c, l, p), nil
2928
}
3029

31-
return nil, errors.New("Unsupported framework")
30+
return nil, errors.New("unsupported framework")
3231
}

xdebugproxy/xdebugproxy.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ import (
1818

1919
const h = "%s"
2020

21+
type XDebugProcessorPluginFactory interface {
22+
Create(c *config.Config, l *logger.Logger, m *pathmapping.PathMapping) XDebugProcessorPlugin
23+
}
24+
2125
// XDebugProcessorPlugin process message in xDebug protocol
2226
type XDebugProcessorPlugin interface {
23-
Initialize(c *config.Config, l *logger.Logger, m *pathmapping.PathMapping)
2427
ApplyMappingToTextProtocol(message []byte) ([]byte, error)
2528
ApplyMappingToXML(message []byte) ([]byte, error)
2629
}

0 commit comments

Comments
 (0)