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

Public Member Functions

 __construct ($options=null)
 
 getPluginLoader ()
 
 setPluginLoader (Zend_Loader_PluginLoader_Interface $pluginLoader)
 
 setConfig (Zend_Config $config)
 
 setOptions ($options)
 
 addFilterPrefixPath ($prefix, $path)
 
 setThrowTargetExceptionsOn ($throwTargetExceptionsOn)
 
 isThrowTargetExceptionsOn ()
 
 setTargetReplacementIdentifier ($targetReplacementIdentifier)
 
 getTargetReplacementIdentifier ()
 
 setTarget ($target)
 
 getTarget ()
 
 setTargetReference (&$target)
 
 setRules (Array $rules)
 
 addRules (Array $rules)
 
 getRules ($spec=null)
 
 getRule ($spec, $index)
 
 clearRules ()
 
 setFilterRule ($spec, $ruleSet)
 
 addFilterRule ($spec, $ruleSet)
 
 setStaticRule ($name, $value)
 
 setStaticRuleReference ($name, &$reference)
 
 filter ($source)
 

Protected Member Functions

 _normalizeSpec ($spec)
 
 _getRule ($rule)
 

Protected Attributes

 $_pluginLoader = null
 
 $_target = null
 
 $_throwTargetExceptionsOn = true
 
 $_targetReplacementIdentifier = ':'
 
 $_rules = array()
 

Detailed Description

Definition at line 41 of file Inflector.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = null)

Constructor

Parameters
string | array$optionsOptions to set

Definition at line 73 of file Inflector.php.

74  {
75  if ($options instanceof Zend_Config) {
76  $options = $options->toArray();
77  } else if (!is_array($options)) {
78  $options = func_get_args();
79  $temp = array();
80 
81  if (!empty($options)) {
82  $temp['target'] = array_shift($options);
83  }
84 
85  if (!empty($options)) {
86  $temp['rules'] = array_shift($options);
87  }
88 
89  if (!empty($options)) {
90  $temp['throwTargetExceptionsOn'] = array_shift($options);
91  }
92 
93  if (!empty($options)) {
94  $temp['targetReplacementIdentifier'] = array_shift($options);
95  }
96 
97  $options = $temp;
98  }
99 
100  $this->setOptions($options);
101  }

Member Function Documentation

◆ _getRule()

_getRule (   $rule)
protected

Resolve named filters and convert them to filter objects.

Parameters
string$rule
Returns
Zend_Filter_Interface

Definition at line 510 of file Inflector.php.

511  {
512  if ($rule instanceof Zend_Filter_Interface) {
513  return $rule;
514  }
515 
516  $rule = (string) $rule;
517 
518  $className = $this->getPluginLoader()->load($rule);
519  $ruleObject = new $className();
520  if (!$ruleObject instanceof Zend_Filter_Interface) {
521  #require_once 'Zend/Filter/Exception.php';
522  throw new Zend_Filter_Exception('No class named ' . $rule . ' implementing Zend_Filter_Interface could be found');
523  }
524 
525  return $ruleObject;
526  }
if($currentSelectedMethod==$_code) $className
Definition: form.phtml:31

◆ _normalizeSpec()

_normalizeSpec (   $spec)
protected

Normalize spec string

Parameters
string$spec
Returns
string

Definition at line 499 of file Inflector.php.

500  {
501  return ltrim((string) $spec, ':&');
502  }

◆ addFilterPrefixPath()

addFilterPrefixPath (   $prefix,
  $path 
)

Convienence method to add prefix and path to PluginLoader

Parameters
string$prefix
string$path
Returns
Zend_Filter_Inflector

Definition at line 187 of file Inflector.php.

188  {
189  $this->getPluginLoader()->addPrefixPath($prefix, $path);
190  return $this;
191  }
$prefix
Definition: name.phtml:25

◆ addFilterRule()

addFilterRule (   $spec,
  $ruleSet 
)

Add a filter rule for a spec

Parameters
mixed$spec
mixed$ruleSet
Returns
void

Definition at line 393 of file Inflector.php.

394  {
395  $spec = $this->_normalizeSpec($spec);
396  if (!isset($this->_rules[$spec])) {
397  $this->_rules[$spec] = array();
398  }
399 
400  if (!is_array($ruleSet)) {
401  $ruleSet = array($ruleSet);
402  }
403 
404  if (is_string($this->_rules[$spec])) {
405  $temp = $this->_rules[$spec];
406  $this->_rules[$spec] = array();
407  $this->_rules[$spec][] = $temp;
408  }
409 
410  foreach ($ruleSet as $rule) {
411  $this->_rules[$spec][] = $this->_getRule($rule);
412  }
413 
414  return $this;
415  }

◆ addRules()

addRules ( Array  $rules)

AddRules(): multi-call to setting filter rules.

If prefixed with a ":" (colon), a filter rule will be added. If not prefixed, a static replacement will be added.

ex: array( ':controller' => array('CamelCaseToUnderscore','StringToLower'), ':action' => array('CamelCaseToUnderscore','StringToLower'), 'suffix' => 'phtml' );

Parameters
array
Returns
Zend_Filter_Inflector

Definition at line 306 of file Inflector.php.

307  {
308  $keys = array_keys($rules);
309  foreach ($keys as $spec) {
310  if ($spec[0] == ':') {
311  $this->addFilterRule($spec, $rules[$spec]);
312  } else {
313  $this->setStaticRule($spec, $rules[$spec]);
314  }
315  }
316 
317  return $this;
318  }
setStaticRule($name, $value)
Definition: Inflector.php:424
addFilterRule($spec, $ruleSet)
Definition: Inflector.php:393

◆ clearRules()

clearRules ( )

ClearRules() clears the rules currently in the inflector

Returns
Zend_Filter_Inflector

Definition at line 365 of file Inflector.php.

366  {
367  $this->_rules = array();
368  return $this;
369  }

◆ filter()

filter (   $source)

Inflect

Parameters
string | array$source
Returns
string

Implements Zend_Filter_Interface.

Definition at line 455 of file Inflector.php.

456  {
457  // clean source
458  foreach ( (array) $source as $sourceName => $sourceValue) {
459  $source[ltrim($sourceName, ':')] = $sourceValue;
460  }
461 
462  $pregQuotedTargetReplacementIdentifier = preg_quote($this->_targetReplacementIdentifier, '#');
463  $processedParts = array();
464 
465  foreach ($this->_rules as $ruleName => $ruleValue) {
466  if (isset($source[$ruleName])) {
467  if (is_string($ruleValue)) {
468  // overriding the set rule
469  $processedParts['#'.$pregQuotedTargetReplacementIdentifier.$ruleName.'#'] = str_replace('\\', '\\\\', $source[$ruleName]);
470  } elseif (is_array($ruleValue)) {
471  $processedPart = $source[$ruleName];
472  foreach ($ruleValue as $ruleFilter) {
473  $processedPart = $ruleFilter->filter($processedPart);
474  }
475  $processedParts['#'.$pregQuotedTargetReplacementIdentifier.$ruleName.'#'] = str_replace('\\', '\\\\', $processedPart);
476  }
477  } elseif (is_string($ruleValue)) {
478  $processedParts['#'.$pregQuotedTargetReplacementIdentifier.$ruleName.'#'] = str_replace('\\', '\\\\', $ruleValue);
479  }
480  }
481 
482  // all of the values of processedParts would have been str_replace('\\', '\\\\', ..)'d to disable preg_replace backreferences
483  $inflectedTarget = preg_replace(array_keys($processedParts), array_values($processedParts), $this->_target);
484 
485  if ($this->_throwTargetExceptionsOn && (preg_match('#(?='.$pregQuotedTargetReplacementIdentifier.'[A-Za-z]{1})#', $inflectedTarget) == true)) {
486  #require_once 'Zend/Filter/Exception.php';
487  throw new Zend_Filter_Exception('A replacement identifier ' . $this->_targetReplacementIdentifier . ' was found inside the inflected target, perhaps a rule was not satisfied with a target source? Unsatisfied inflected target: ' . $inflectedTarget);
488  }
489 
490  return $inflectedTarget;
491  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$source
Definition: source.php:23

◆ getPluginLoader()

getPluginLoader ( )

Retreive PluginLoader

Returns
Zend_Loader_PluginLoader_Interface

Definition at line 108 of file Inflector.php.

109  {
110  if (!$this->_pluginLoader instanceof Zend_Loader_PluginLoader_Interface) {
111  $this->_pluginLoader = new Zend_Loader_PluginLoader(array('Zend_Filter_' => 'Zend/Filter/'), __CLASS__);
112  }
113 
114  return $this->_pluginLoader;
115  }

◆ getRule()

getRule (   $spec,
  $index 
)

getRule() returns a rule set by setFilterRule(), a numeric index must be provided

Parameters
string$spec
int$index
Returns
Zend_Filter_Interface|false

Definition at line 349 of file Inflector.php.

350  {
351  $spec = $this->_normalizeSpec($spec);
352  if (isset($this->_rules[$spec]) && is_array($this->_rules[$spec])) {
353  if (isset($this->_rules[$spec][$index])) {
354  return $this->_rules[$spec][$index];
355  }
356  }
357  return false;
358  }
$index
Definition: list.phtml:44

◆ getRules()

getRules (   $spec = null)

Get rules

By default, returns all rules. If a $spec is provided, will return those rules if found, false otherwise.

Parameters
string$spec
Returns
array|false

Definition at line 329 of file Inflector.php.

330  {
331  if (null !== $spec) {
332  $spec = $this->_normalizeSpec($spec);
333  if (isset($this->_rules[$spec])) {
334  return $this->_rules[$spec];
335  }
336  return false;
337  }
338 
339  return $this->_rules;
340  }

◆ getTarget()

getTarget ( )

Retrieve target

Returns
string

Definition at line 259 of file Inflector.php.

260  {
261  return $this->_target;
262  }

◆ getTargetReplacementIdentifier()

getTargetReplacementIdentifier ( )

Get Target Replacement Identifier

Returns
string

Definition at line 236 of file Inflector.php.

237  {
239  }

◆ isThrowTargetExceptionsOn()

isThrowTargetExceptionsOn ( )

Will exceptions be thrown?

Returns
bool

Definition at line 211 of file Inflector.php.

212  {
214  }

◆ setConfig()

setConfig ( Zend_Config  $config)

Use Zend_Config object to set object state

Deprecated:
Use setOptions() instead
Parameters
Zend_Config$config
Returns
Zend_Filter_Inflector

Definition at line 136 of file Inflector.php.

137  {
138  return $this->setOptions($config);
139  }

◆ setFilterRule()

setFilterRule (   $spec,
  $ruleSet 
)

Set a filtering rule for a spec. $ruleSet can be a string, Filter object or an array of strings or filter objects.

Parameters
string$spec
array | string | Zend_Filter_Interface$ruleSet
Returns
Zend_Filter_Inflector

Definition at line 379 of file Inflector.php.

380  {
381  $spec = $this->_normalizeSpec($spec);
382  $this->_rules[$spec] = array();
383  return $this->addFilterRule($spec, $ruleSet);
384  }
addFilterRule($spec, $ruleSet)
Definition: Inflector.php:393

◆ setOptions()

setOptions (   $options)

Set options

Parameters
array$options
Returns
Zend_Filter_Inflector

Definition at line 147 of file Inflector.php.

147  {
148  if ($options instanceof Zend_Config) {
149  $options = $options->toArray();
150  }
151 
152  // Set Präfix Path
153  if (array_key_exists('filterPrefixPath', $options)) {
154  if (!is_scalar($options['filterPrefixPath'])) {
155  foreach ($options['filterPrefixPath'] as $prefix => $path) {
157  }
158  }
159  }
160 
161  if (array_key_exists('throwTargetExceptionsOn', $options)) {
162  $this->setThrowTargetExceptionsOn($options['throwTargetExceptionsOn']);
163  }
164 
165  if (array_key_exists('targetReplacementIdentifier', $options)) {
166  $this->setTargetReplacementIdentifier($options['targetReplacementIdentifier']);
167  }
168 
169  if (array_key_exists('target', $options)) {
170  $this->setTarget($options['target']);
171  }
172 
173  if (array_key_exists('rules', $options)) {
174  $this->addRules($options['rules']);
175  }
176 
177  return $this;
178  }
addRules(Array $rules)
Definition: Inflector.php:306
addFilterPrefixPath($prefix, $path)
Definition: Inflector.php:187
$prefix
Definition: name.phtml:25
setTargetReplacementIdentifier($targetReplacementIdentifier)
Definition: Inflector.php:222
setThrowTargetExceptionsOn($throwTargetExceptionsOn)
Definition: Inflector.php:200

◆ setPluginLoader()

setPluginLoader ( Zend_Loader_PluginLoader_Interface  $pluginLoader)

Set PluginLoader

Parameters
Zend_Loader_PluginLoader_Interface$pluginLoader
Returns
Zend_Filter_Inflector

Definition at line 123 of file Inflector.php.

124  {
125  $this->_pluginLoader = $pluginLoader;
126  return $this;
127  }

◆ setRules()

setRules ( Array  $rules)

SetRules() is the same as calling addRules() with the exception that it clears the rules before adding them.

Parameters
array$rules
Returns
Zend_Filter_Inflector

Definition at line 283 of file Inflector.php.

284  {
285  $this->clearRules();
286  $this->addRules($rules);
287  return $this;
288  }
addRules(Array $rules)
Definition: Inflector.php:306

◆ setStaticRule()

setStaticRule (   $name,
  $value 
)

Set a static rule for a spec. This is a single string value

Parameters
string$name
string$value
Returns
Zend_Filter_Inflector

Definition at line 424 of file Inflector.php.

425  {
426  $name = $this->_normalizeSpec($name);
427  $this->_rules[$name] = (string) $value;
428  return $this;
429  }
$value
Definition: gender.phtml:16
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setStaticRuleReference()

setStaticRuleReference (   $name,
$reference 
)

Set Static Rule Reference.

This allows a consuming class to pass a property or variable in to be referenced when its time to build the output string from the target.

Parameters
string$name
mixed$reference
Returns
Zend_Filter_Inflector

Definition at line 442 of file Inflector.php.

443  {
444  $name = $this->_normalizeSpec($name);
445  $this->_rules[$name] =& $reference;
446  return $this;
447  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ setTarget()

setTarget (   $target)

Set a Target ex: 'scripts/:controller/:action.:suffix'

Parameters
string
Returns
Zend_Filter_Inflector

Definition at line 248 of file Inflector.php.

249  {
250  $this->_target = (string) $target;
251  return $this;
252  }
$target
Definition: skip.phtml:8

◆ setTargetReference()

setTargetReference ( $target)

Set Target Reference

Parameters
reference$target
Returns
Zend_Filter_Inflector

Definition at line 270 of file Inflector.php.

271  {
272  $this->_target =& $target;
273  return $this;
274  }
$target
Definition: skip.phtml:8

◆ setTargetReplacementIdentifier()

setTargetReplacementIdentifier (   $targetReplacementIdentifier)

Set the Target Replacement Identifier, by default ':'

Parameters
string$targetReplacementIdentifier
Returns
Zend_Filter_Inflector

Definition at line 222 of file Inflector.php.

223  {
224  if ($targetReplacementIdentifier) {
225  $this->_targetReplacementIdentifier = (string) $targetReplacementIdentifier;
226  }
227 
228  return $this;
229  }

◆ setThrowTargetExceptionsOn()

setThrowTargetExceptionsOn (   $throwTargetExceptionsOn)

Set Whether or not the inflector should throw an exception when a replacement identifier is still found within an inflected target.

Parameters
bool$throwTargetExceptions
Returns
Zend_Filter_Inflector

Definition at line 200 of file Inflector.php.

201  {
202  $this->_throwTargetExceptionsOn = ($throwTargetExceptionsOn == true) ? true : false;
203  return $this;
204  }

Field Documentation

◆ $_pluginLoader

$_pluginLoader = null
protected

Definition at line 46 of file Inflector.php.

◆ $_rules

$_rules = array()
protected

Definition at line 66 of file Inflector.php.

◆ $_target

$_target = null
protected

Definition at line 51 of file Inflector.php.

◆ $_targetReplacementIdentifier

$_targetReplacementIdentifier = ':'
protected

Definition at line 61 of file Inflector.php.

◆ $_throwTargetExceptionsOn

$_throwTargetExceptionsOn = true
protected

Definition at line 56 of file Inflector.php.


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