Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
BooleanUtils.php
Go to the documentation of this file.
1 <?php
7 
15 {
21  private $trueValues;
22 
28  private $falseValues;
29 
35  public function __construct(
36  array $trueValues = [true, 1, 'true', '1'],
37  array $falseValues = [false, 0, 'false', '0']
38  ) {
39  $this->trueValues = $trueValues;
40  $this->falseValues = $falseValues;
41  }
42 
43  // @codingStandardsIgnoreEnd
44 
52  public function toBoolean($value)
53  {
58  if (in_array($value, $this->trueValues, true)) {
59  return true;
60  }
61  if (in_array($value, $this->falseValues, true)) {
62  return false;
63  }
64  $allowedValues = array_merge($this->trueValues, $this->falseValues);
65  throw new \InvalidArgumentException(
66  'Boolean value is expected, supported values: ' . var_export($allowedValues, true)
67  );
68  }
69 
77  public function convert($value)
78  {
79  if (in_array($value, $this->trueValues, true)) {
80  return true;
81  } elseif (in_array($value, $this->falseValues, true)) {
82  return false;
83  } else {
84  return $value;
85  }
86  }
87 }
__construct(array $trueValues=[true, 1, 'true', '1'], array $falseValues=[false, 0, 'false', '0'])
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$value
Definition: gender.phtml:16