Skip to content

Commit ed55bb3

Browse files
committed
Improve configuration params
1 parent f6e22e7 commit ed55bb3

File tree

11 files changed

+48
-33
lines changed

11 files changed

+48
-33
lines changed

src/Context/ChildContext.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,40 @@ protected function __construct(
1919
private readonly EntryInterface $entry,
2020
mixed $value,
2121
Direction $direction,
22+
ConfigurationInterface $config,
2223
TypeExtractorInterface $extractor,
2324
TypeParserInterface $parser,
2425
TypeRepositoryInterface $types,
25-
ConfigurationInterface $config,
26-
private readonly ?bool $isStrictTypes = null,
26+
private readonly ?bool $overrideStrictTypes = null,
27+
private readonly ?bool $overrideObjectAsArray = null,
2728
) {
2829
parent::__construct(
2930
value: $value,
3031
direction: $direction,
32+
config: $config,
3133
extractor: $extractor,
3234
parser: $parser,
3335
types: $types,
34-
config: $config,
3536
);
3637
}
3738

3839
#[\Override]
3940
public function isStrictTypesEnabled(): bool
4041
{
41-
return $this->isStrictTypes
42-
?? $this->config->isStrictTypesEnabled();
42+
return $this->overrideStrictTypes
43+
?? parent::isStrictTypesEnabled();
44+
}
45+
46+
#[\Override]
47+
public function isObjectAsArray(): bool
48+
{
49+
return $this->overrideObjectAsArray
50+
?? parent::isObjectAsArray();
4351
}
4452

4553
/**
54+
* Gets parent context
55+
*
4656
* @api
4757
*/
4858
public function getParent(): Context

src/Context/Context.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,32 @@ abstract class Context implements
2525
protected function __construct(
2626
protected readonly mixed $value,
2727
protected readonly Direction $direction,
28+
protected readonly ConfigurationInterface $config,
2829
protected readonly TypeExtractorInterface $extractor,
2930
protected readonly TypeParserInterface $parser,
3031
protected readonly TypeRepositoryInterface $types,
31-
protected readonly ConfigurationInterface $config,
3232
) {}
3333

3434
/**
3535
* Creates new child context.
3636
*/
37-
public function enter(mixed $value, EntryInterface $entry, ?bool $isStrictTypes = null): self
38-
{
37+
public function enter(
38+
mixed $value,
39+
EntryInterface $entry,
40+
?bool $strictTypes = null,
41+
?bool $objectAsArray = null,
42+
): self {
3943
return new ChildContext(
4044
parent: $this,
4145
entry: $entry,
4246
value: $value,
4347
direction: $this->direction,
48+
config: $this->config,
4449
extractor: $this->extractor,
4550
parser: $this->parser,
4651
types: $this->types,
47-
config: $this->config,
48-
isStrictTypes: $isStrictTypes,
52+
overrideStrictTypes: $strictTypes,
53+
overrideObjectAsArray: $objectAsArray,
4954
);
5055
}
5156

@@ -54,24 +59,24 @@ public function getValue(): mixed
5459
return $this->value;
5560
}
5661

57-
public function isObjectsAsArrays(): bool
62+
public function isObjectAsArray(): bool
5863
{
59-
return $this->config->isObjectsAsArrays();
64+
return $this->config->isObjectAsArray();
6065
}
6166

6267
public function isStrictTypesEnabled(): bool
6368
{
6469
return $this->config->isStrictTypesEnabled();
6570
}
6671

67-
public function getLogger(): ?LoggerInterface
72+
public function findLogger(): ?LoggerInterface
6873
{
69-
return $this->config->getLogger();
74+
return $this->config->findLogger();
7075
}
7176

72-
public function getTracer(): ?TracerInterface
77+
public function findTracer(): ?TracerInterface
7378
{
74-
return $this->config->getTracer();
79+
return $this->config->findTracer();
7580
}
7681

7782
/**

src/Context/RootContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ public static function forNormalization(
3939
return new self(
4040
value: $value,
4141
direction: Direction::Normalize,
42+
config: $config,
4243
extractor: $extractor,
4344
parser: $parser,
4445
types: $types,
45-
config: $config,
4646
);
4747
}
4848

@@ -65,10 +65,10 @@ public static function forDenormalization(
6565
return new self(
6666
value: $value,
6767
direction: Direction::Denormalize,
68+
config: $config,
6869
extractor: $extractor,
6970
parser: $parser,
7071
types: $types,
71-
config: $config,
7272
);
7373
}
7474

src/Runtime/Configuration.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function withObjectsAsArrays(?bool $enabled = null): self
6565
);
6666
}
6767

68-
public function isObjectsAsArrays(): bool
68+
public function isObjectAsArray(): bool
6969
{
7070
return $this->isObjectsAsArrays ?? self::OBJECTS_AS_ARRAYS_DEFAULT_VALUE;
7171
}
@@ -128,7 +128,7 @@ public function withLogger(?LoggerInterface $logger = null): self
128128
);
129129
}
130130

131-
public function getLogger(): ?LoggerInterface
131+
public function findLogger(): ?LoggerInterface
132132
{
133133
return $this->logger;
134134
}
@@ -150,7 +150,7 @@ public function withTracer(?TracerInterface $tracer = null): self
150150
);
151151
}
152152

153-
public function getTracer(): ?TracerInterface
153+
public function findTracer(): ?TracerInterface
154154
{
155155
return $this->tracer;
156156
}

src/Runtime/ConfigurationInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface ConfigurationInterface
1515
* In case of the method returns {@see true}, the object will be converted
1616
* to an associative array (hash map) unless otherwise specified.
1717
*/
18-
public function isObjectsAsArrays(): bool;
18+
public function isObjectAsArray(): bool;
1919

2020
/**
2121
* In case of method returns {@see true}, all types will be checked
@@ -30,11 +30,11 @@ public function isStrictTypesEnabled(): bool;
3030
* If this method returns {@see LoggerInterface}, then the given logger
3131
* will be enabled. Otherwise logger should be disabled.
3232
*/
33-
public function getLogger(): ?LoggerInterface;
33+
public function findLogger(): ?LoggerInterface;
3434

3535
/**
3636
* If this method returns {@see TracerInterface}, then the application
3737
* tracing will be enabled. Otherwise tracing should be disabled.
3838
*/
39-
public function getTracer(): ?TracerInterface;
39+
public function findTracer(): ?TracerInterface;
4040
}

src/Runtime/Parser/Factory/DefaultTypeParserFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private function createDefaultParser(PlatformInterface $platform): TypeLangParse
3535

3636
private function withTracing(Configuration $config, TypeParserInterface $parser): TypeParserInterface
3737
{
38-
$tracer = $config->getTracer();
38+
$tracer = $config->findTracer();
3939

4040
if ($tracer === null) {
4141
return $parser;
@@ -46,7 +46,7 @@ private function withTracing(Configuration $config, TypeParserInterface $parser)
4646

4747
private function withLogging(Configuration $config, TypeParserInterface $parser): TypeParserInterface
4848
{
49-
$logger = $config->getLogger();
49+
$logger = $config->findLogger();
5050

5151
if ($logger === null) {
5252
return $parser;

src/Runtime/Repository/Factory/DefaultTypeRepositoryFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private function createDefaultRepository(
4646

4747
private function withTracing(Configuration $config, TypeRepositoryInterface $types): TypeRepositoryInterface
4848
{
49-
$tracer = $config->getTracer();
49+
$tracer = $config->findTracer();
5050

5151
if ($tracer === null) {
5252
return $types;
@@ -57,7 +57,7 @@ private function withTracing(Configuration $config, TypeRepositoryInterface $typ
5757

5858
private function withLogging(Configuration $config, TypeRepositoryInterface $types): TypeRepositoryInterface
5959
{
60-
$logger = $config->getLogger();
60+
$logger = $config->findLogger();
6161

6262
if ($logger === null) {
6363
return $types;

src/Type/ClassTypeFromArrayType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private function denormalizeObject(array $value, object $object, Context $contex
121121
$entrance = $context->enter(
122122
value: $value,
123123
entry: new ObjectPropertyEntry($meta->alias),
124-
isStrictTypes: $meta->write->strict,
124+
strictTypes: $meta->write->strict,
125125
);
126126

127127
// Skip the property when not writable

src/Type/ClassTypeToArrayType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function cast(mixed $value, Context $context): object|array
5757

5858
$result = $this->normalizeObject($value, $entrance);
5959

60-
if ($this->metadata->isNormalizeAsArray ?? $context->isObjectsAsArrays()) {
60+
if ($this->metadata->isNormalizeAsArray ?? $context->isObjectAsArray()) {
6161
return $result;
6262
}
6363

@@ -77,7 +77,7 @@ protected function normalizeObject(object $object, Context $context): array
7777
$entrance = $context->enter(
7878
value: $object,
7979
entry: new ObjectPropertyEntry($meta->name),
80-
isStrictTypes: $meta->read->strict,
80+
strictTypes: $meta->read->strict,
8181
);
8282

8383
// Skip the property when not readable

src/Type/ListFromIterableType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ protected function process(iterable $value, Context $context): array
5858
$entrance = $context->enter(
5959
value: $item,
6060
entry: new ArrayIndexEntry($index),
61-
isStrictTypes: $context->isStrictTypesEnabled(),
61+
strictTypes: $context->isStrictTypesEnabled(),
6262
);
6363

6464
try {

0 commit comments

Comments
 (0)