| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
namespace Symfony\Component\Serializer\Context; |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
trait ContextBuilderTrait |
| 18 |
{ |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
private array $context = []; |
| 23 |
|
| 24 |
protected function with(string $key, mixed $value): static |
| 25 |
{ |
| 26 |
$instance = new static(); |
| 27 |
$instance->context = array_merge($this->context, [$key => $value]); |
| 28 |
|
| 29 |
return $instance; |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public function withContext(ContextBuilderInterface|array $context): static |
| 36 |
{ |
| 37 |
if ($context instanceof ContextBuilderInterface) { |
| 38 |
$context = $context->toArray(); |
| 39 |
} |
| 40 |
|
| 41 |
$instance = new static(); |
| 42 |
$instance->context = array_merge($this->context, $context); |
| 43 |
|
| 44 |
return $instance; |
| 45 |
} |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
public function toArray(): array |
| 51 |
{ |
| 52 |
return $this->context; |
| 53 |
} |
| 54 |
} |