Skip to content

Commit 6e84222

Browse files
author
Kirill Nesmeyanov
committed
Disable type decorators serialization
1 parent 50c1185 commit 6e84222

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/Runtime/Repository/TypeDecorator/LoggableType.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
final class LoggableType extends TypeDecorator
1616
{
1717
public function __construct(
18-
private readonly LoggerInterface $logger,
18+
private readonly ?LoggerInterface $logger,
1919
TypeInterface $delegate,
2020
) {
2121
parent::__construct($delegate);
@@ -39,6 +39,10 @@ private function getLoggerArguments(mixed $value, Context $context): array
3939

4040
public function match(mixed $value, Context $context): bool
4141
{
42+
if ($this->logger === null) {
43+
return parent::match($value, $context);
44+
}
45+
4246
$this->logger->debug(
4347
'Matching by the {type_name}',
4448
$this->getLoggerArguments($value, $context),
@@ -58,6 +62,10 @@ public function match(mixed $value, Context $context): bool
5862

5963
public function cast(mixed $value, Context $context): mixed
6064
{
65+
if ($this->logger === null) {
66+
return parent::cast($value, $context);
67+
}
68+
6169
$this->logger->debug(
6270
'Casting by the {type_name}',
6371
$this->getLoggerArguments($value, $context),

src/Runtime/Repository/TypeDecorator/TraceableType.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final class TraceableType extends TypeDecorator
2121
private readonly string $name;
2222

2323
public function __construct(
24-
private readonly TracerInterface $tracer,
24+
private readonly ?TracerInterface $tracer,
2525
TypeInterface $delegate,
2626
) {
2727
parent::__construct($delegate);
@@ -61,6 +61,10 @@ private static function getDirection(Context $context): Context\DirectionInterfa
6161

6262
public function match(mixed $value, Context $context): bool
6363
{
64+
if ($this->tracer === null) {
65+
return parent::match($value, $context);
66+
}
67+
6468
$span = $this->tracer->start(\sprintf('Match %s', $this->name));
6569

6670
try {
@@ -80,6 +84,10 @@ public function match(mixed $value, Context $context): bool
8084

8185
public function cast(mixed $value, Context $context): mixed
8286
{
87+
if ($this->tracer === null) {
88+
return parent::cast($value, $context);
89+
}
90+
8391
$span = $this->tracer->start(\sprintf('Cast %s', $this->name));
8492

8593
try {

src/Runtime/Repository/TypeDecorator/TypeDecorator.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
abstract class TypeDecorator implements TypeDecoratorInterface
1515
{
1616
public function __construct(
17-
private readonly TypeInterface $delegate,
17+
protected readonly TypeInterface $delegate,
1818
) {}
1919

2020
public function getDecoratedType(): TypeInterface
@@ -35,4 +35,12 @@ public function cast(mixed $value, Context $context): mixed
3535
{
3636
return $this->delegate->cast($value, $context);
3737
}
38+
39+
/**
40+
* @return array<array-key, mixed>
41+
*/
42+
public function __serialize(): array
43+
{
44+
return ['delegate' => $this->delegate];
45+
}
3846
}

0 commit comments

Comments
 (0)