Skip to content

Commit a8e280e

Browse files
merge from 3.2.X
1 parent 78276bb commit a8e280e

2 files changed

Lines changed: 47 additions & 1 deletion

File tree

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the CleverAge/ProcessBundle package.
7+
*
8+
* Copyright (c) 2017-2023 Clever-Age
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace CleverAge\ProcessBundle\Transformer;
15+
16+
use ReflectionClass;
17+
use Symfony\Component\OptionsResolver\OptionsResolver;
18+
use UnexpectedValueException;
19+
20+
/**
21+
* Instantiate a new object with parameters from the input array
22+
*/
23+
class InstantiateTransformer implements ConfigurableTransformerInterface
24+
{
25+
public function transform(mixed $value, array $options = []): mixed
26+
{
27+
if (! is_array($value)) {
28+
throw new UnexpectedValueException('Input value must be an array for transformer instantiate');
29+
}
30+
31+
return (new ReflectionClass($options['class']))->newInstanceArgs($value);
32+
}
33+
34+
public function configureOptions(OptionsResolver $resolver): void
35+
{
36+
$resolver->setRequired(['class']);
37+
$resolver->setAllowedTypes('class', ['string']);
38+
}
39+
40+
public function getCode(): string
41+
{
42+
return 'instantiate';
43+
}
44+
}

src/Transformer/WrapperTransformer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public function transform(mixed $value, array $options = []): array
2929

3030
public function configureOptions(OptionsResolver $resolver): void
3131
{
32-
$resolver->setRequired(['wrapper_key']);
32+
$resolver->setDefaults([
33+
'wrapper_key' => 0,
34+
]);
3335
$resolver->setAllowedTypes('wrapper_key', ['string', 'int']);
3436
}
3537

0 commit comments

Comments
 (0)