Skip to content

Commit b02215d

Browse files
committed
FIX: Ensures provided services are always the same
Due the PHPVCR library provides its own factory method to create instances we should consider using the same mechanism to always use the same instances!
1 parent e894a7a commit b02215d

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

src/Resources/config/services.yml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,33 @@ services:
88
vcr.logger:
99
class: VCR\VCRBundle\VCR\Logger
1010

11+
vcr.factory:
12+
class: VCR\VCRFactory
13+
factory: [VCR\VCRFactory, getInstance]
14+
1115
vcr.config:
12-
class: VCR\Configuration
16+
class: VCR\Configuration
17+
factory: ['@vcr.factory', getOrCreate]
18+
arguments: [VCR\Configuration]
1319
calls:
1420
- [ enableLibraryHooks, [ "%vcr.library_hooks%" ]]
1521
- [ enableRequestMatchers, [ "%vcr.request_matchers%" ] ]
1622
- [ setCassettePath, [ "%vcr.cassette.path%" ] ]
1723
- [ setStorage, [ "%vcr.cassette.type%" ] ]
1824

19-
vcr.http_client:
20-
class: VCR\Util\HttpClient
25+
# passing '@vcr.config' as third parameter to getOrCreate ensures the VCR\Configuration class is
26+
# created and configured by the symfony di as expected (because the configuration object is already
27+
# created by the factory) #hack
2128

22-
vcr.factory:
23-
class: VCR\VCRFactory
24-
factory: [VCR\VCRFactory, getInstance]
25-
arguments: [ '@vcr.config' ]
29+
vcr.http_client:
30+
class: VCR\Util\HttpClient
31+
factory: ['@vcr.factory', getOrCreate]
32+
arguments: [VCR\Util\HttpClient, [], '@vcr.config']
2633

2734
vcr.recorder:
2835
class: VCR\Videorecorder
29-
arguments: [ '@vcr.config', '@vcr.http_client', '@vcr.factory' ]
36+
factory: ['@vcr.factory', getOrCreate]
37+
arguments: [ VCR\Videorecorder, [], '@vcr.config']
3038
calls:
3139
- [ setEventDispatcher, [ '@event_dispatcher' ] ]
3240
public: true

0 commit comments

Comments
 (0)