Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Zend_Filter_Boolean Class Reference
Inheritance diagram for Zend_Filter_Boolean:
Zend_Filter_Interface

Public Member Functions

 __construct ($options=null)
 
 getType ()
 
 setType ($type=null)
 
 getLocale ()
 
 setLocale ($locale=null)
 
 getCasting ()
 
 setCasting ($casting=true)
 
 filter ($value)
 

Data Fields

const BOOLEAN = 1
 
const INTEGER = 2
 
const FLOAT = 4
 
const STRING = 8
 
const ZERO = 16
 
const EMPTY_ARRAY = 32
 
const NULL = 64
 
const PHP = 127
 
const FALSE_STRING = 128
 
const YES = 256
 
const ALL = 511
 

Protected Member Functions

 _getLocalizedQuestion ($value, $yes, $locale)
 

Protected Attributes

 $_constants
 
 $_type = self::PHP
 
 $_locale = array('auto')
 
 $_casting = true
 

Detailed Description

Definition at line 33 of file Boolean.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = null)

Constructor

Parameters
string | array | Zend_Config$optionsOPTIONAL

Definition at line 87 of file Boolean.php.

88  {
89  if ($options instanceof Zend_Config) {
90  $options = $options->toArray();
91  } elseif (!is_array($options)) {
92  $options = func_get_args();
93  $temp = array();
94  if (!empty($options)) {
95  $temp['type'] = array_shift($options);
96  }
97 
98  if (!empty($options)) {
99  $temp['casting'] = array_shift($options);
100  }
101 
102  if (!empty($options)) {
103  $temp['locale'] = array_shift($options);
104  }
105 
106  $options = $temp;
107  }
108 
109  if (array_key_exists('type', $options)) {
110  $this->setType($options['type']);
111  }
112 
113  if (array_key_exists('casting', $options)) {
114  $this->setCasting($options['casting']);
115  }
116 
117  if (array_key_exists('locale', $options)) {
118  $this->setLocale($options['locale']);
119  }
120  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
setCasting($casting=true)
Definition: Boolean.php:224
setType($type=null)
Definition: Boolean.php:139
setLocale($locale=null)
Definition: Boolean.php:182

Member Function Documentation

◆ _getLocalizedQuestion()

_getLocalizedQuestion (   $value,
  $yes,
  $locale 
)
protected

Determine the value of a localized string, and compare it to a given value

Parameters
string$value
boolean$yes
array$locale
Returns
boolean

Definition at line 356 of file Boolean.php.

357  {
358  if ($yes == true) {
359  $question = 'yes';
360  $return = true;
361  } else {
362  $question = 'no';
363  $return = false;
364  }
365  $str = Zend_Locale::getTranslation($question, 'question', $locale);
366  $str = explode(':', $str);
367  if (!empty($str)) {
368  foreach($str as $no) {
369  if (($no == $value) || (strtolower($no) == strtolower($value))) {
370  return $return;
371  }
372  }
373  }
374  }
static getTranslation($value=null, $path=null, $locale=null)
Definition: Locale.php:1536
$value
Definition: gender.phtml:16

◆ filter()

filter (   $value)

Defined by Zend_Filter_Interface

Returns a boolean representation of $value

Parameters
string$value
Returns
string

Implements Zend_Filter_Interface.

Definition at line 238 of file Boolean.php.

239  {
240  $type = $this->getType();
241  $casting = $this->getCasting();
242 
243  // STRING YES (Localized)
244  if ($type >= self::YES) {
245  $type -= self::YES;
246  if (is_string($value)) {
247  #require_once 'Zend/Locale.php';
248  $locales = $this->getLocale();
249  foreach ($locales as $locale) {
250  if ($this->_getLocalizedQuestion($value, false, $locale) === false) {
251  return false;
252  }
253 
254  if (!$casting && ($this->_getLocalizedQuestion($value, true, $locale) === true)) {
255  return true;
256  }
257  }
258  }
259  }
260 
261  // STRING FALSE ('false')
262  if ($type >= self::FALSE_STRING) {
264  if (is_string($value) && (strtolower($value) == 'false')) {
265  return false;
266  }
267 
268  if ((!$casting) && is_string($value) && (strtolower($value) == 'true')) {
269  return true;
270  }
271  }
272 
273  // NULL (null)
274  if ($type >= self::NULL) {
275  $type -= self::NULL;
276  if ($value === null) {
277  return false;
278  }
279  }
280 
281  // EMPTY_ARRAY (array())
282  if ($type >= self::EMPTY_ARRAY) {
284  if (is_array($value) && ($value == array())) {
285  return false;
286  }
287  }
288 
289  // ZERO ('0')
290  if ($type >= self::ZERO) {
291  $type -= self::ZERO;
292  if (is_string($value) && ($value == '0')) {
293  return false;
294  }
295 
296  if ((!$casting) && (is_string($value)) && ($value == '1')) {
297  return true;
298  }
299  }
300 
301  // STRING ('')
302  if ($type >= self::STRING) {
303  $type -= self::STRING;
304  if (is_string($value) && ($value == '')) {
305  return false;
306  }
307  }
308 
309  // FLOAT (0.0)
310  if ($type >= self::FLOAT) {
311  $type -= self::FLOAT;
312  if (is_float($value) && ($value == 0.0)) {
313  return false;
314  }
315 
316  if ((!$casting) && is_float($value) && ($value == 1.0)) {
317  return true;
318  }
319  }
320 
321  // INTEGER (0)
322  if ($type >= self::INTEGER) {
323  $type -= self::INTEGER;
324  if (is_int($value) && ($value == 0)) {
325  return false;
326  }
327 
328  if ((!$casting) && is_int($value) && ($value == 1)) {
329  return true;
330  }
331  }
332 
333  // BOOLEAN (false)
334  if ($type >= self::BOOLEAN) {
335  $type -= self::BOOLEAN;
336  if (is_bool($value)) {
337  return $value;
338  }
339  }
340 
341  if ($casting) {
342  return true;
343  }
344 
345  return $value;
346  }
_getLocalizedQuestion($value, $yes, $locale)
Definition: Boolean.php:356
$type
Definition: item.phtml:13
$locales
Definition: locales.php:14
$value
Definition: gender.phtml:16

◆ getCasting()

getCasting ( )

Returns the casting option

Returns
boolean

Definition at line 210 of file Boolean.php.

211  {
212  return $this->_casting;
213  }

◆ getLocale()

getLocale ( )

Returns the set locale

Returns
array

Definition at line 170 of file Boolean.php.

171  {
172  return $this->_locale;
173  }

◆ getType()

getType ( )

Returns the set null types

Returns
int

Definition at line 127 of file Boolean.php.

128  {
129  return $this->_type;
130  }

◆ setCasting()

setCasting (   $casting = true)

Set the working mode

Parameters
boolean$localeWhen true this filter works like cast When false it recognises only true and false and all other values are returned as is
Exceptions
Zend_Filter_Exception
Returns
Zend_Filter_Boolean

Definition at line 224 of file Boolean.php.

225  {
226  $this->_casting = (boolean) $casting;
227  return $this;
228  }

◆ setLocale()

setLocale (   $locale = null)

Set the locales which are accepted

Parameters
string | array | Zend_Locale$locale
Exceptions
Zend_Filter_Exception
Returns
Zend_Filter_Boolean

Definition at line 182 of file Boolean.php.

183  {
184  if (is_string($locale)) {
185  $locale = array($locale);
186  } elseif ($locale instanceof Zend_Locale) {
187  $locale = array($locale->toString());
188  } elseif (!is_array($locale)) {
189  #require_once 'Zend/Filter/Exception.php';
190  throw new Zend_Filter_Exception('Locale has to be string, array or an instance of Zend_Locale');
191  }
192 
193  #require_once 'Zend/Locale.php';
194  foreach ($locale as $single) {
195  if (!Zend_Locale::isLocale($single)) {
196  #require_once 'Zend/Filter/Exception.php';
197  throw new Zend_Filter_Exception("Unknown locale '$single'");
198  }
199  }
200 
201  $this->_locale = $locale;
202  return $this;
203  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
static isLocale($locale, $strict=false, $compatible=true)
Definition: Locale.php:1683

◆ setType()

setType (   $type = null)

Set the null types

Parameters
integer | array$type
Exceptions
Zend_Filter_Exception
Returns
Zend_Filter_Boolean

Definition at line 139 of file Boolean.php.

140  {
141  if (is_array($type)) {
142  $detected = 0;
143  foreach($type as $value) {
144  if (is_int($value)) {
145  $detected += $value;
146  } elseif (in_array($value, $this->_constants)) {
147  $detected += array_search($value, $this->_constants);
148  }
149  }
150 
151  $type = $detected;
152  } elseif (is_string($type) && in_array($type, $this->_constants)) {
153  $type = array_search($type, $this->_constants);
154  }
155 
156  if (!is_int($type) || ($type < 0) || ($type > self::ALL)) {
157  #require_once 'Zend/Filter/Exception.php';
158  throw new Zend_Filter_Exception('Unknown type');
159  }
160 
161  $this->_type = $type;
162  return $this;
163  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16

Field Documentation

◆ $_casting

$_casting = true
protected

Definition at line 80 of file Boolean.php.

◆ $_constants

$_constants
protected
Initial value:
= array(
self::BOOLEAN => 'boolean',
self::INTEGER => 'integer',
self::FLOAT => 'float',
self::STRING => 'string',
self::ZERO => 'zero',
self::EMPTY_ARRAY => 'array',
self::NULL => 'null',
self::PHP => 'php',
self::FALSE_STRING => 'false',
self::YES => 'yes',
self::ALL => 'all',
)

Definition at line 47 of file Boolean.php.

◆ $_locale

$_locale = array('auto')
protected

Definition at line 73 of file Boolean.php.

◆ $_type

$_type = self::PHP
protected

Definition at line 66 of file Boolean.php.

◆ ALL

const ALL = 511

Definition at line 45 of file Boolean.php.

◆ BOOLEAN

const BOOLEAN = 1

Definition at line 35 of file Boolean.php.

◆ EMPTY_ARRAY

const EMPTY_ARRAY = 32

Definition at line 40 of file Boolean.php.

◆ FALSE_STRING

const FALSE_STRING = 128

Definition at line 43 of file Boolean.php.

◆ FLOAT

const FLOAT = 4

Definition at line 37 of file Boolean.php.

◆ INTEGER

const INTEGER = 2

Definition at line 36 of file Boolean.php.

◆ NULL

const NULL = 64

Definition at line 41 of file Boolean.php.

◆ PHP

const PHP = 127

Definition at line 42 of file Boolean.php.

◆ STRING

const STRING = 8

Definition at line 38 of file Boolean.php.

◆ YES

const YES = 256

Definition at line 44 of file Boolean.php.

◆ ZERO

const ZERO = 16

Definition at line 39 of file Boolean.php.


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