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

Public Member Functions

 __construct ($options=null)
 
 getType ()
 
 setType ($type=null)
 
 filter ($value)
 

Data Fields

const BOOLEAN = 1
 
const INTEGER = 2
 
const EMPTY_ARRAY = 4
 
const STRING = 8
 
const ZERO = 16
 
const ALL = 31
 

Protected Attributes

 $_constants
 
 $_type = self::ALL
 

Detailed Description

Definition at line 33 of file Null.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = null)

Constructor

Parameters
string | array | Zend_Config$optionsOPTIONAL

Definition at line 63 of file Null.php.

64  {
65  if ($options instanceof Zend_Config) {
66  $options = $options->toArray();
67  } else if (!is_array($options)) {
68  $options = func_get_args();
69  $temp = array();
70  if (!empty($options)) {
71  $temp = array_shift($options);
72  }
73  $options = $temp;
74  } else if (is_array($options) && array_key_exists('type', $options)) {
75  $options = $options['type'];
76  }
77 
78  if (!empty($options)) {
79  $this->setType($options);
80  }
81  }
setType($type=null)
Definition: Null.php:100

Member Function Documentation

◆ filter()

filter (   $value)

Defined by Zend_Filter_Interface

Returns null representation of $value, if value is empty and matches types that should be considered null.

Parameters
string$value
Returns
string

Implements Zend_Filter_Interface.

Definition at line 137 of file Null.php.

138  {
139  $type = $this->getType();
140 
141  // STRING ZERO ('0')
142  if ($type >= self::ZERO) {
143  $type -= self::ZERO;
144  if (is_string($value) && ($value == '0')) {
145  return null;
146  }
147  }
148 
149  // STRING ('')
150  if ($type >= self::STRING) {
151  $type -= self::STRING;
152  if (is_string($value) && ($value == '')) {
153  return null;
154  }
155  }
156 
157  // EMPTY_ARRAY (array())
158  if ($type >= self::EMPTY_ARRAY) {
160  if (is_array($value) && ($value == array())) {
161  return null;
162  }
163  }
164 
165  // INTEGER (0)
166  if ($type >= self::INTEGER) {
167  $type -= self::INTEGER;
168  if (is_int($value) && ($value == 0)) {
169  return null;
170  }
171  }
172 
173  // BOOLEAN (false)
174  if ($type >= self::BOOLEAN) {
175  $type -= self::BOOLEAN;
176  if (is_bool($value) && ($value == false)) {
177  return null;
178  }
179  }
180 
181  return $value;
182  }
const STRING
Definition: Null.php:38
const BOOLEAN
Definition: Null.php:35
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16
const ZERO
Definition: Null.php:39
const INTEGER
Definition: Null.php:36
const EMPTY_ARRAY
Definition: Null.php:37

◆ getType()

getType ( )

Returns the set null types

Returns
array

Definition at line 88 of file Null.php.

89  {
90  return $this->_type;
91  }

◆ setType()

setType (   $type = null)

Set the null types

Parameters
integer | array$type
Exceptions
Zend_Filter_Exception
Returns
Zend_Filter_Null

Definition at line 100 of file Null.php.

101  {
102  if (is_array($type)) {
103  $detected = 0;
104  foreach($type as $value) {
105  if (is_int($value)) {
106  $detected += $value;
107  } else if (in_array($value, $this->_constants)) {
108  $detected += array_search($value, $this->_constants);
109  }
110  }
111 
112  $type = $detected;
113  } else if (is_string($type)) {
114  if (in_array($type, $this->_constants)) {
115  $type = array_search($type, $this->_constants);
116  }
117  }
118 
119  if (!is_int($type) || ($type < 0) || ($type > self::ALL)) {
120  #require_once 'Zend/Filter/Exception.php';
121  throw new Zend_Filter_Exception('Unknown type');
122  }
123 
124  $this->_type = $type;
125  return $this;
126  }
$type
Definition: item.phtml:13
$value
Definition: gender.phtml:16

Field Documentation

◆ $_constants

$_constants
protected
Initial value:
= array(
self::BOOLEAN => 'boolean',
self::INTEGER => 'integer',
self::EMPTY_ARRAY => 'array',
self::STRING => 'string',
self::ZERO => 'zero',
self::ALL => 'all'
)

Definition at line 42 of file Null.php.

◆ $_type

$_type = self::ALL
protected

Definition at line 56 of file Null.php.

◆ ALL

const ALL = 31

Definition at line 40 of file Null.php.

◆ BOOLEAN

const BOOLEAN = 1

Definition at line 35 of file Null.php.

◆ EMPTY_ARRAY

const EMPTY_ARRAY = 4

Definition at line 37 of file Null.php.

◆ INTEGER

const INTEGER = 2

Definition at line 36 of file Null.php.

◆ STRING

const STRING = 8

Definition at line 38 of file Null.php.

◆ ZERO

const ZERO = 16

Definition at line 39 of file Null.php.


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