44
55namespace Http \Client \Plugin \Vcr \Recorder ;
66
7+ use GuzzleHttp \Psr7 \Message ;
78use GuzzleHttp \Psr7 ;
89use Psr \Http \Message \ResponseInterface ;
910use Psr \Log \LoggerAwareInterface ;
@@ -31,7 +32,12 @@ final class FilesystemRecorder implements RecorderInterface, PlayerInterface, Lo
3132 */
3233 private $ filesystem ;
3334
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 = [])
3541 {
3642 $ this ->filesystem = $ filesystem ?? new Filesystem ();
3743
@@ -44,6 +50,7 @@ public function __construct(string $directory, ?Filesystem $filesystem = null)
4450 }
4551
4652 $ this ->directory = realpath ($ directory ).\DIRECTORY_SEPARATOR ;
53+ $ this ->filters = $ filters ;
4754 }
4855
4956 public function replay (string $ name ): ?ResponseInterface
@@ -67,7 +74,8 @@ public function record(string $name, ResponseInterface $response): void
6774 $ filename = "{$ this ->directory }$ name.txt " ;
6875 $ context = compact ('name ' , 'filename ' );
6976
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 );
7179
7280 $ this ->log ('Response for {name} stored into {filename} ' , $ context );
7381 }
0 commit comments