4
4
5
5
namespace Http \Client \Plugin \Vcr \Recorder ;
6
6
7
+ use GuzzleHttp \Psr7 \Message ;
7
8
use GuzzleHttp \Psr7 ;
8
9
use Psr \Http \Message \ResponseInterface ;
9
10
use Psr \Log \LoggerAwareInterface ;
@@ -31,7 +32,12 @@ final class FilesystemRecorder implements RecorderInterface, PlayerInterface, Lo
31
32
*/
32
33
private $ filesystem ;
33
34
34
- public function __construct (string $ directory , ?Filesystem $ filesystem = null )
35
+ /**
36
+ * @var array
37
+ */
38
+ private $ filters ;
39
+
40
+ public function __construct (string $ directory , ?Filesystem $ filesystem = null , array $ filters = [])
35
41
{
36
42
$ this ->filesystem = $ filesystem ?? new Filesystem ();
37
43
@@ -44,6 +50,7 @@ public function __construct(string $directory, ?Filesystem $filesystem = null)
44
50
}
45
51
46
52
$ this ->directory = realpath ($ directory ).\DIRECTORY_SEPARATOR ;
53
+ $ this ->filters = $ filters ;
47
54
}
48
55
49
56
public function replay (string $ name ): ?ResponseInterface
@@ -67,7 +74,8 @@ public function record(string $name, ResponseInterface $response): void
67
74
$ filename = "{$ this ->directory }$ name.txt " ;
68
75
$ context = compact ('name ' , 'filename ' );
69
76
70
- $ this ->filesystem ->dumpFile ($ filename , Psr7 \str ($ response ));
77
+ $ content = preg_replace (array_keys ($ this ->filters ), array_values ($ this ->filters ), Message::toString ($ response ));
78
+ $ this ->filesystem ->dumpFile ($ filename , $ content );
71
79
72
80
$ this ->log ('Response for {name} stored into {filename} ' , $ context );
73
81
}
0 commit comments