File tree Expand file tree Collapse file tree 7 files changed +59
-7
lines changed
tests/Flow/ETL/Tests/Double Expand file tree Collapse file tree 7 files changed +59
-7
lines changed Original file line number Diff line number Diff line change 22
33namespace Flow \ETL ;
44
5- interface Cache
5+ use Flow \Serializer \Serializable ;
6+
7+ /**
8+ * @template T
9+ * @extends Serializable<T>
10+ */
11+ interface Cache extends Serializable
612{
713 public function add (string $ id , Rows $ rows ) : void ;
814
Original file line number Diff line number Diff line change 77use Flow \ETL \Cache ;
88use Flow \ETL \Rows ;
99
10+ /**
11+ * @implements Cache<array<mixed>>
12+ */
1013final class InMemoryCache implements Cache
1114{
1215 /**
1316 * @var array<string, array<Rows>>
1417 */
1518 private array $ cache = [];
1619
20+ public function __serialize () : array
21+ {
22+ return [];
23+ }
24+
25+ public function __unserialize (array $ data ) : void
26+ {
27+ }
28+
1729 public function add (string $ id , Rows $ rows ) : void
1830 {
1931 if (!\array_key_exists ($ id , $ this ->cache )) {
Original file line number Diff line number Diff line change 1010use Flow \Serializer \Serializer ;
1111
1212/**
13+ * @implements Cache<array{path: string, serializer: Serializer}>
1314 * @infection-ignore-all
1415 */
1516final class LocalFilesystemCache implements Cache
@@ -23,6 +24,20 @@ public function __construct(
2324 }
2425 }
2526
27+ public function __serialize () : array
28+ {
29+ return [
30+ 'path ' => $ this ->path ,
31+ 'serializer ' => $ this ->serializer ,
32+ ];
33+ }
34+
35+ public function __unserialize (array $ data ) : void
36+ {
37+ $ this ->path = $ data ['path ' ];
38+ $ this ->serializer = $ data ['serializer ' ];
39+ }
40+
2641 public function add (string $ id , Rows $ rows ) : void
2742 {
2843 $ cacheStream = \fopen ($ this ->cachePath ($ id ), 'a ' );
Original file line number Diff line number Diff line change 99use Flow \ETL \ExternalSort \MemorySort ;
1010use Flow \ETL \Monitoring \Memory \Unit ;
1111use Flow \Serializer \CompressingSerializer ;
12- use Flow \Serializer \NativePHPSerializer ;
1312use Flow \Serializer \Serializer ;
1413
1514final class ConfigBuilder
@@ -39,7 +38,7 @@ public function __construct()
3938 public function build () : Config
4039 {
4140 $ this ->id ??= \uniqid ('flow_php ' );
42- $ this ->serializer ??= new CompressingSerializer (new NativePHPSerializer () );
41+ $ this ->serializer ??= new CompressingSerializer ();
4342 $ this ->cache ??= new LocalFilesystemCache (
4443 \is_string (\getenv (Config::CACHE_DIR_ENV ))
4544 ? \getenv (Config::CACHE_DIR_ENV )
Original file line number Diff line number Diff line change 88
99final class CompressingSerializer implements Serializer
1010{
11- public function __construct (
12- private readonly Serializer $ serializer ,
13- private readonly int $ compressionLevel = 9
14- ) {
11+ private readonly int $ compressionLevel ;
12+
13+ private readonly Serializer $ serializer ;
14+
15+ public function __construct ()
16+ {
17+ $ this ->serializer = new NativePHPSerializer ();
18+ $ this ->compressionLevel = 9 ;
1519 }
1620
1721 public function serialize (Serializable $ serializable ) : string
Original file line number Diff line number Diff line change 88
99final class NativePHPSerializer implements Serializer
1010{
11+ public function __construct ()
12+ {
13+ }
14+
1115 public function serialize (Serializable $ serializable ) : string
1216 {
1317 return \serialize ($ serializable );
Original file line number Diff line number Diff line change 77use Flow \ETL \Cache ;
88use Flow \ETL \Rows ;
99
10+ /**
11+ * @implements Cache<array<mixed>>
12+ */
1013final class CacheSpy implements Cache
1114{
1215 /**
@@ -28,6 +31,15 @@ public function __construct(private readonly Cache $cache)
2831 {
2932 }
3033
34+ public function __serialize () : array
35+ {
36+ return [];
37+ }
38+
39+ public function __unserialize (array $ data ) : void
40+ {
41+ }
42+
3143 public function add (string $ id , Rows $ rows ) : void
3244 {
3345 if (!\array_key_exists ($ id , $ this ->writes )) {
You can’t perform that action at this time.
0 commit comments