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

Public Member Functions

 addFilter (Zend_Filter_Interface $filter, $placement=self::CHAIN_APPEND)
 
 appendFilter (Zend_Filter_Interface $filter)
 
 prependFilter (Zend_Filter_Interface $filter)
 
 getFilters ()
 
 filter ($value)
 

Static Public Member Functions

static getDefaultNamespaces ()
 
static setDefaultNamespaces ($namespace)
 
static addDefaultNamespaces ($namespace)
 
static hasDefaultNamespaces ()
 
static get ($value, $classBaseName, array $args=array(), $namespaces=array())
 
static filterStatic ($value, $classBaseName, array $args=array(), $namespaces=array())
 

Data Fields

const CHAIN_APPEND = 'append'
 
const CHAIN_PREPEND = 'prepend'
 

Protected Attributes

 $_filters = array()
 

Static Protected Attributes

static $_defaultNamespaces = array()
 

Detailed Description

Definition at line 33 of file Filter.php.

Member Function Documentation

◆ addDefaultNamespaces()

static addDefaultNamespaces (   $namespace)
static

Adds a new default namespace

Parameters
array | string$namespace
Returns
null

Definition at line 150 of file Filter.php.

151  {
152  if (!is_array($namespace)) {
153  $namespace = array((string) $namespace);
154  }
155 
156  self::$_defaultNamespaces = array_unique(array_merge(self::$_defaultNamespaces, $namespace));
157  }

◆ addFilter()

addFilter ( Zend_Filter_Interface  $filter,
  $placement = self::CHAIN_APPEND 
)

Adds a filter to the chain

Parameters
Zend_Filter_Interface$filter
string$placement
Returns
Zend_Filter Provides a fluent interface

Definition at line 60 of file Filter.php.

61  {
62  if ($placement == self::CHAIN_PREPEND) {
63  array_unshift($this->_filters, $filter);
64  } else {
65  $this->_filters[] = $filter;
66  }
67  return $this;
68  }

◆ appendFilter()

appendFilter ( Zend_Filter_Interface  $filter)

Add a filter to the end of the chain

Parameters
Zend_Filter_Interface$filter
Returns
Zend_Filter Provides a fluent interface

Definition at line 76 of file Filter.php.

77  {
78  return $this->addFilter($filter, self::CHAIN_APPEND);
79  }
addFilter(Zend_Filter_Interface $filter, $placement=self::CHAIN_APPEND)
Definition: Filter.php:60

◆ filter()

filter (   $value)

Returns $value filtered through each filter in the chain

Filters are run in the order in which they were added to the chain (FIFO)

Parameters
mixed$value
Returns
mixed

Implements Zend_Filter_Interface.

Definition at line 110 of file Filter.php.

111  {
112  $valueFiltered = $value;
113  foreach ($this->_filters as $filter) {
114  $valueFiltered = $filter->filter($valueFiltered);
115  }
116  return $valueFiltered;
117  }
$value
Definition: gender.phtml:16

◆ filterStatic()

static filterStatic (   $value,
  $classBaseName,
array  $args = array(),
  $namespaces = array() 
)
static

Returns a value filtered through a specified filter class, without requiring separate instantiation of the filter object.

The first argument of this method is a data input value, that you would have filtered. The second argument is a string, which corresponds to the basename of the filter class, relative to the Zend_Filter namespace. This method automatically loads the class, creates an instance, and applies the filter() method to the data input. You can also pass an array of constructor arguments, if they are needed for the filter class.

Parameters
mixed$value
string$classBaseName
array$argsOPTIONAL
array | string$namespacesOPTIONAL
Returns
mixed
Exceptions
Zend_Filter_Exception

Definition at line 207 of file Filter.php.

208  {
209  #require_once 'Zend/Loader.php';
210  $namespaces = array_merge((array) $namespaces, self::$_defaultNamespaces, array('Zend_Filter'));
211  foreach ($namespaces as $namespace) {
212  $className = $namespace . '_' . ucfirst($classBaseName);
213  if (!class_exists($className, false)) {
214  try {
215  $file = str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';
216  if (Zend_Loader::isReadable($file)) {
218  } else {
219  continue;
220  }
221  } catch (Zend_Exception $ze) {
222  continue;
223  }
224  }
225 
226  $class = new ReflectionClass($className);
227  if ($class->implementsInterface('Zend_Filter_Interface')) {
228  if ($class->hasMethod('__construct')) {
229  $object = $class->newInstanceArgs($args);
230  } else {
231  $object = $class->newInstance();
232  }
233  return $object->filter($value);
234  }
235  }
236  #require_once 'Zend/Filter/Exception.php';
237  throw new Zend_Filter_Exception("Filter class not found from basename '$classBaseName'");
238  }
static loadClass($class, $dirs=null)
Definition: Loader.php:52
static isReadable($filename)
Definition: Loader.php:162
$_option $_optionId $class
Definition: date.phtml:13
$value
Definition: gender.phtml:16
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31

◆ get()

static get (   $value,
  $classBaseName,
array  $args = array(),
  $namespaces = array() 
)
static
Deprecated:
See also
Zend_Filter::filterStatic()
Parameters
mixed$value
string$classBaseName
array$argsOPTIONAL
array | string$namespacesOPTIONAL
Returns
mixed
Exceptions
Zend_Filter_Exception

Definition at line 180 of file Filter.php.

181  {
182  trigger_error(
183  'Zend_Filter::get() is deprecated as of 1.9.0; please update your code to utilize Zend_Filter::filterStatic()',
184  E_USER_NOTICE
185  );
186 
187  return self::filterStatic($value, $classBaseName, $args, $namespaces);
188  }
$value
Definition: gender.phtml:16
static filterStatic($value, $classBaseName, array $args=array(), $namespaces=array())
Definition: Filter.php:207

◆ getDefaultNamespaces()

static getDefaultNamespaces ( )
static

Returns the set default namespaces

Returns
array

Definition at line 124 of file Filter.php.

125  {
127  }
static $_defaultNamespaces
Definition: Filter.php:51

◆ getFilters()

getFilters ( )

Get all the filters

Returns
array

Definition at line 97 of file Filter.php.

98  {
99  return $this->_filters;
100  }

◆ hasDefaultNamespaces()

static hasDefaultNamespaces ( )
static

Returns true when defaultNamespaces are set

Returns
boolean

Definition at line 164 of file Filter.php.

165  {
166  return (!empty(self::$_defaultNamespaces));
167  }

◆ prependFilter()

prependFilter ( Zend_Filter_Interface  $filter)

Add a filter to the start of the chain

Parameters
Zend_Filter_Interface$filter
Returns
Zend_Filter Provides a fluent interface

Definition at line 87 of file Filter.php.

88  {
89  return $this->addFilter($filter, self::CHAIN_PREPEND);
90  }
addFilter(Zend_Filter_Interface $filter, $placement=self::CHAIN_APPEND)
Definition: Filter.php:60

◆ setDefaultNamespaces()

static setDefaultNamespaces (   $namespace)
static

Sets new default namespaces

Parameters
array | string$namespace
Returns
null

Definition at line 135 of file Filter.php.

136  {
137  if (!is_array($namespace)) {
138  $namespace = array((string) $namespace);
139  }
140 
141  self::$_defaultNamespaces = $namespace;
142  }

Field Documentation

◆ $_defaultNamespaces

$_defaultNamespaces = array()
staticprotected

Definition at line 51 of file Filter.php.

◆ $_filters

$_filters = array()
protected

Definition at line 44 of file Filter.php.

◆ CHAIN_APPEND

const CHAIN_APPEND = 'append'

Definition at line 36 of file Filter.php.

◆ CHAIN_PREPEND

const CHAIN_PREPEND = 'prepend'

Definition at line 37 of file Filter.php.


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