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

Public Member Functions

 __construct ($pattern)
 
 getPattern ()
 
 setPattern ($pattern)
 
 isValid ($value)
 
- Public Member Functions inherited from Zend_Validate_Abstract
 getMessages ()
 
 getMessageVariables ()
 
 getMessageTemplates ()
 
 setMessage ($messageString, $messageKey=null)
 
 setMessages (array $messages)
 
 __get ($property)
 
 getErrors ()
 
 setObscureValue ($flag)
 
 getObscureValue ()
 
 setTranslator ($translator=null)
 
 getTranslator ()
 
 hasTranslator ()
 
 setDisableTranslator ($flag)
 
 translatorIsDisabled ()
 

Data Fields

const INVALID = 'regexInvalid'
 
const NOT_MATCH = 'regexNotMatch'
 
const ERROROUS = 'regexErrorous'
 

Protected Attributes

 $_messageTemplates
 
 $_messageVariables
 
 $_pattern
 
- Protected Attributes inherited from Zend_Validate_Abstract
 $_value
 
 $_messageVariables = array()
 
 $_messageTemplates = array()
 
 $_messages = array()
 
 $_obscureValue = false
 
 $_errors = array()
 
 $_translator
 
 $_translatorDisabled = false
 

Additional Inherited Members

- Static Public Member Functions inherited from Zend_Validate_Abstract
static setDefaultTranslator ($translator=null)
 
static getDefaultTranslator ()
 
static hasDefaultTranslator ()
 
static getMessageLength ()
 
static setMessageLength ($length=-1)
 
- Protected Member Functions inherited from Zend_Validate_Abstract
 _createMessage ($messageKey, $value)
 
 _implodeRecursive (array $pieces)
 
 _error ($messageKey, $value=null)
 
 _setValue ($value)
 
- Static Protected Attributes inherited from Zend_Validate_Abstract
static $_defaultTranslator
 
static $_messageLength = -1
 

Detailed Description

Definition at line 33 of file Regex.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $pattern)

Sets validator options

Parameters
string | Zend_Config$pattern
Exceptions
Zend_Validate_ExceptionOn missing 'pattern' parameter

Definition at line 68 of file Regex.php.

69  {
70  if ($pattern instanceof Zend_Config) {
71  $pattern = $pattern->toArray();
72  }
73 
74  if (is_array($pattern)) {
75  if (array_key_exists('pattern', $pattern)) {
76  $pattern = $pattern['pattern'];
77  } else {
78  #require_once 'Zend/Validate/Exception.php';
79  throw new Zend_Validate_Exception("Missing option 'pattern'");
80  }
81  }
82 
83  $this->setPattern($pattern);
84  }
$pattern
Definition: website.php:22
setPattern($pattern)
Definition: Regex.php:103

Member Function Documentation

◆ getPattern()

getPattern ( )

Returns the pattern option

Returns
string

Definition at line 91 of file Regex.php.

92  {
93  return $this->_pattern;
94  }

◆ isValid()

isValid (   $value)

Defined by Zend_Validate_Interface

Returns true if and only if $value matches against the pattern option

Parameters
string$value
Returns
boolean

Implements Zend_Validate_Interface.

Definition at line 124 of file Regex.php.

125  {
126  if (!is_string($value) && !is_int($value) && !is_float($value)) {
127  $this->_error(self::INVALID);
128  return false;
129  }
130 
131  $this->_setValue($value);
132 
133  $status = @preg_match($this->_pattern, $value);
134  if (false === $status) {
135  $this->_error(self::ERROROUS);
136  return false;
137  }
138 
139  if (!$status) {
140  $this->_error(self::NOT_MATCH);
141  return false;
142  }
143 
144  return true;
145  }
_error($messageKey, $value=null)
Definition: Abstract.php:284
$value
Definition: gender.phtml:16
$status
Definition: order_status.php:8

◆ setPattern()

setPattern (   $pattern)

Sets the pattern option

Parameters
string$pattern
Exceptions
Zend_Validate_Exceptionif there is a fatal error in pattern matching
Returns
Zend_Validate_Regex Provides a fluent interface

Definition at line 103 of file Regex.php.

104  {
105  $this->_pattern = (string) $pattern;
106  $status = @preg_match($this->_pattern, "Test");
107 
108  if (false === $status) {
109  #require_once 'Zend/Validate/Exception.php';
110  throw new Zend_Validate_Exception("Internal error while using the pattern '$this->_pattern'");
111  }
112 
113  return $this;
114  }
$pattern
Definition: website.php:22
$status
Definition: order_status.php:8

Field Documentation

◆ $_messageTemplates

$_messageTemplates
protected
Initial value:
= array(
self::INVALID => "Invalid type given. String, integer or float expected",
self::NOT_MATCH => "'%value%' does not match against pattern '%pattern%'",
self::ERROROUS => "There was an internal error while using the pattern '%pattern%'",
)

Definition at line 42 of file Regex.php.

◆ $_messageVariables

$_messageVariables
protected
Initial value:
= array(
'pattern' => '_pattern'
)

Definition at line 51 of file Regex.php.

◆ $_pattern

$_pattern
protected

Definition at line 60 of file Regex.php.

◆ ERROROUS

const ERROROUS = 'regexErrorous'

Definition at line 37 of file Regex.php.

◆ INVALID

const INVALID = 'regexInvalid'

Definition at line 35 of file Regex.php.

◆ NOT_MATCH

const NOT_MATCH = 'regexNotMatch'

Definition at line 36 of file Regex.php.


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