Skip to content

Commit d84bfbc

Browse files
committed
refactor: rename context key property to name
1 parent dc3e1f5 commit d84bfbc

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

packages/database/src/DatabaseContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
final class DatabaseContext implements Context
99
{
10-
private(set) string $key = self::class;
10+
private(set) string $name = self::class;
1111

1212
public function __construct(
1313
private(set) DatabaseDialect $dialect,

packages/mapper/src/Attributes/Context.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
#[Attribute(Attribute::TARGET_CLASS)]
1616
final class Context implements MapperContext
1717
{
18-
public string $key {
18+
public string $name {
1919
get {
20-
if ($this->name instanceof BackedEnum) {
21-
return $this->name->value;
20+
if ($this->context instanceof BackedEnum) {
21+
return $this->context->value;
2222
}
2323

24-
if ($this->name instanceof UnitEnum) {
25-
return $this->name->name;
24+
if ($this->context instanceof UnitEnum) {
25+
return $this->context->name;
2626
}
2727

28-
return $this->name;
28+
return $this->context;
2929
}
3030
}
3131

3232
public function __construct(
33-
public BackedEnum|UnitEnum|string $name,
33+
public BackedEnum|UnitEnum|string $context,
3434
) {}
3535
}

packages/mapper/src/CasterFactory.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ public function addCaster(string|array|Closure $for, string|Closure $casterClass
3333
{
3434
$context = MappingContext::from($context);
3535

36-
$this->casters[$context->key] ??= [];
37-
$this->casters[$context->key][] = [$for, $casterClass, $priority];
36+
$this->casters[$context->name] ??= [];
37+
$this->casters[$context->name][] = [$for, $casterClass, $priority];
3838

39-
usort($this->casters[$context->key], static fn (array $a, array $b) => $a[2] <=> $b[2]);
39+
usort($this->casters[$context->name], static fn (array $a, array $b) => $a[2] <=> $b[2]);
4040

4141
return $this;
4242
}
@@ -122,8 +122,8 @@ private function casterMatches(Closure|string|array $for, PropertyReflector $pro
122122
private function resolveCasters(): array
123123
{
124124
return [
125-
...($this->casters[MappingContext::from($this->context)->key] ?? []),
126-
...($this->casters[MappingContext::default()->key] ?? []),
125+
...($this->casters[MappingContext::from($this->context)->name] ?? []),
126+
...($this->casters[MappingContext::default()->name] ?? []),
127127
];
128128
}
129129
}

packages/mapper/src/Context.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
interface Context
99
{
1010
/**
11-
* A unique identifier for this context.
11+
* A unique name for this context.
1212
*/
13-
public string $key {
13+
public string $name {
1414
get;
1515
}
1616
}

packages/mapper/src/MappingContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
final class MappingContext implements Context, Stringable
99
{
1010
public function __construct(
11-
private(set) string $key,
11+
private(set) string $name,
1212
) {}
1313

1414
public static function default(): Context
@@ -35,6 +35,6 @@ public static function from(Context|UnitEnum|string|null $context): Context
3535

3636
public function __toString(): string
3737
{
38-
return $this->key;
38+
return $this->name;
3939
}
4040
}

packages/mapper/src/SerializerFactory.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ public function addSerializer(string|array|Closure $for, string|Closure $seriali
3434
{
3535
$context = MappingContext::from($context);
3636

37-
$this->serializers[$context->key] ??= [];
38-
$this->serializers[$context->key][] = [$for, $serializerClass, $priority];
37+
$this->serializers[$context->name] ??= [];
38+
$this->serializers[$context->name][] = [$for, $serializerClass, $priority];
3939

40-
usort($this->serializers[$context->key], static fn (array $a, array $b) => $a[2] <=> $b[2]);
40+
usort($this->serializers[$context->name], static fn (array $a, array $b) => $a[2] <=> $b[2]);
4141

4242
return $this;
4343
}
@@ -166,8 +166,8 @@ private function serializerMatches(Closure|string|array $for, TypeReflector|stri
166166
private function resolveSerializers(): array
167167
{
168168
return [
169-
...($this->serializers[MappingContext::from($this->context)->key] ?? []),
170-
...($this->serializers[MappingContext::default()->key] ?? []),
169+
...($this->serializers[MappingContext::from($this->context)->name] ?? []),
170+
...($this->serializers[MappingContext::default()->name] ?? []),
171171
];
172172
}
173173
}

0 commit comments

Comments
 (0)