PluginProbe
WooCommerce / 11.1.0
WooCommerce v11.1.0
11.1.0 11.1.0-rc.2 11.1.0-rc.1 11.1.0-beta.2 11.1.0-beta.1 11.0.1 11.0.0 11.0.0-rc.3 11.0.0-rc.2 11.0.0-rc.1 11.0.0-beta.2 11.0.0-beta.1 10.9.4 10.9.3 10.9.2 10.9.1 10.9.0 10.9.0-rc.1 10.9.0-beta.2 10.9.0-beta.1 10.8.1 10.8.0 10.8.0-rc.1 10.8.0-beta.2 10.8.0-beta.1 All 648 releases
woocommerce / src / Admin / RemoteSpecs / RuleProcessors / Transformers / ArraySearch.php
ArraySearch.php
54 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers;
4
5 use Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers\TransformerInterface;
6 use InvalidArgumentException;
7 use stdClass;
8
9 /**
10 * Searches a given a given value in the array.
11 *
12 * @package Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors\Transformers
13 */
14 class ArraySearch implements TransformerInterface {
15 /**
16 * Search a given value in the array.
17 *
18 * @param mixed $value a value to transform.
19 * @param stdClass|null $arguments required argument 'value'.
20 * @param string|null $default_value default value.
21 *
22 * @throws InvalidArgumentException Throws when the required 'value' is missing.
23 *
24 * @return mixed|null
25 */
26 public function transform( $value, ?stdClass $arguments = null, $default_value = null ) {
27 if ( ! is_array( $value ) ) {
28 return $default_value;
29 }
30
31 $key = array_search( $arguments->value, $value, true );
32 if ( false !== $key ) {
33 return $value[ $key ];
34 }
35
36 return null;
37 }
38
39 /**
40 * Validate Transformer arguments.
41 *
42 * @param stdClass|null $arguments arguments to validate.
43 *
44 * @return mixed
45 */
46 public function validate( ?stdClass $arguments = null ) {
47 if ( ! isset( $arguments->value ) ) {
48 return false;
49 }
50
51 return true;
52 }
53 }
54