Skip to content

Commit fa962ff

Browse files
Merge pull request #128 from VincentChalnot/v3.2-dev
Various fixes
2 parents e94bc10 + ae37db4 commit fa962ff

File tree

2 files changed

+47
-2
lines changed

2 files changed

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

Transformer/WrapperTransformer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ public function transform($input, array $options = [])
4141
*/
4242
public function configureOptions(OptionsResolver $resolver)
4343
{
44-
$resolver->setRequired(
44+
$resolver->setDefaults(
4545
[
46-
'wrapper_key',
46+
'wrapper_key' => 0,
4747
]
4848
);
4949
$resolver->setAllowedTypes('wrapper_key', ['string', 'int']);

0 commit comments

Comments
 (0)