Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions
BooleanUtils Class Reference

Public Member Functions

 __construct (array $trueValues=[true, 1, 'true', '1'], array $falseValues=[false, 0, 'false', '0'])
 
 toBoolean ($value)
 
 convert ($value)
 

Detailed Description

Utility methods for the boolean data type

@api

Since
100.0.2

Definition at line 14 of file BooleanUtils.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( array  $trueValues = [true,
,
'true'  ,
'1']  ,
array  $falseValues = [false,
,
'false ,
'0']   
)
Parameters
array$trueValues
array$falseValues@codingStandardsIgnoreStart

Definition at line 35 of file BooleanUtils.php.

38  {
39  $this->trueValues = $trueValues;
40  $this->falseValues = $falseValues;
41  }

Member Function Documentation

◆ convert()

convert (   $value)

Try to convert $value to boolean else return non processed $value

Parameters
mixed$value
Returns
mixed
Since
101.0.0

Definition at line 77 of file BooleanUtils.php.

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  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$value
Definition: gender.phtml:16

◆ toBoolean()

toBoolean (   $value)

Retrieve boolean value for an expression

Parameters
mixed$valueBoolean expression
Returns
bool
Exceptions

Built-in function filter_var() is not used, because such values as on/off are irrelevant in some contexts http://www.php.net/manual/en/filter.filters.validate.php

Definition at line 52 of file BooleanUtils.php.

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  }
$value
Definition: gender.phtml:16

The documentation for this class was generated from the following file: