File tree 1 file changed +49
-0
lines changed
1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+ /*
3
+ * This file is part of the CleverAge/ProcessBundle package.
4
+ *
5
+ * Copyright (C) 2017-2019 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
+ * Unset a key from an array
17
+ */
18
+ class ArrayUnsetTransformer implements ConfigurableTransformerInterface
19
+ {
20
+ /**
21
+ * {@inheritdoc}
22
+ */
23
+ public function transform ($ value , array $ options = [])
24
+ {
25
+ if (!\is_array ($ value )) {
26
+ throw new \UnexpectedValueException ('Given value is not an array ' );
27
+ }
28
+ unset($ value [$ options ['key ' ]]);
29
+
30
+ return $ value ;
31
+ }
32
+
33
+ /**
34
+ * {@inheritdoc}
35
+ */
36
+ public function getCode (): string
37
+ {
38
+ return 'array_unset ' ;
39
+ }
40
+
41
+ /**
42
+ * {@inheritdoc}
43
+ */
44
+ public function configureOptions (OptionsResolver $ resolver ): void
45
+ {
46
+ $ resolver ->setRequired ('key ' );
47
+ $ resolver ->setAllowedTypes ('key ' , ['string ' , 'int ' ]);
48
+ }
49
+ }
You can’t perform that action at this time.
0 commit comments