-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayTransformer.php
More file actions
45 lines (42 loc) · 1.38 KB
/
ArrayTransformer.php
File metadata and controls
45 lines (42 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Bdf\Form\Attribute\Aggregate;
use Attribute;
use Bdf\Form\Attribute\Element\Transformer;
use Bdf\Form\Transformer\TransformerInterface;
/**
* Add a transformer on the array element, using a transformer class
*
* This attribute will simply set the array flag to true on the {@see Transformer} attribute.
*
* This attribute is equivalent to call :
* <code>
* $builder->string('foo')->arrayTransformer(new MyTransformer(...$arguments));
* </code>
*
* Usage:
* <code>
* class MyForm extends AttributeForm
* {
* #[ArrayTransformer(MyTransformer::class, ['foo', 'bar']), ElementType(IntegerElement::class)]
* private ArrayElement $foo;
* }
* </code>
*
* @see ArrayElementBuilder::arrayTransformer() The called method
* @see CallbackTransformer For use custom methods as transformer instead of class
* @see Transformer To add a transformer the item of the array
*
* @api
*/
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::IS_REPEATABLE)]
class ArrayTransformer extends Transformer
{
/**
* @param class-string<TransformerInterface> $transformerClass The transformer class name
* @param array $constructorArguments Arguments to provide on the transformer constructor
*/
public function __construct(string $transformerClass, array $constructorArguments = [])
{
parent::__construct($transformerClass, $constructorArguments, true);
}
}