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

Public Member Functions

 __construct ($adapter)
 
 getAdapter ()
 
 setAdapter ($adapter, $options=null)
 
 getChecksum ()
 
 setChecksum ($checksum)
 
 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 = 'barcodeInvalid'
 
const FAILED = 'barcodeFailed'
 
const INVALID_CHARS = 'barcodeInvalidChars'
 
const INVALID_LENGTH = 'barcodeInvalidLength'
 

Protected Attributes

 $_messageTemplates
 
 $_messageVariables
 
 $_length
 
 $_adapter
 
- 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 38 of file Barcode.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $adapter)

Generates the standard validator object

Parameters
string|Zend_Config|Zend_Validate_Barcode_BarcodeAdapter $adapter Barcode adapter to use
Exceptions
Zend_Validate_Exception

Definition at line 82 of file Barcode.php.

83  {
84  if ($adapter instanceof Zend_Config) {
85  $adapter = $adapter->toArray();
86  }
87 
88  $options = null;
89  $checksum = null;
90  if (is_array($adapter)) {
91  if (array_key_exists('options', $adapter)) {
92  $options = $adapter['options'];
93  }
94 
95  if (array_key_exists('checksum', $adapter)) {
96  $checksum = $adapter['checksum'];
97  }
98 
99  if (array_key_exists('adapter', $adapter)) {
100  $adapter = $adapter['adapter'];
101  } else {
102  #require_once 'Zend/Validate/Exception.php';
103  throw new Zend_Validate_Exception("Missing option 'adapter'");
104  }
105  }
106 
107  $this->setAdapter($adapter, $options);
108  if ($checksum !== null) {
109  $this->setChecksum($checksum);
110  }
111  }
setAdapter($adapter, $options=null)
Definition: Barcode.php:131
$adapter
Definition: webapi_user.php:16
setChecksum($checksum)
Definition: Barcode.php:170

Member Function Documentation

◆ getAdapter()

getAdapter ( )

Returns the set adapter

Returns
Zend_Validate_Barcode_BarcodeAdapter

Definition at line 118 of file Barcode.php.

119  {
120  return $this->_adapter;
121  }

◆ getChecksum()

getChecksum ( )

Returns the checksum option

Returns
boolean

Definition at line 159 of file Barcode.php.

160  {
161  return $this->getAdapter()->getCheck();
162  }

◆ isValid()

isValid (   $value)

Defined by Zend_Validate_Interface

Returns true if and only if $value contains a valid barcode

Parameters
string$value
Returns
boolean

Implements Zend_Validate_Interface.

Definition at line 184 of file Barcode.php.

185  {
186  if (!is_string($value)) {
187  $this->_error(self::INVALID);
188  return false;
189  }
190 
191  $this->_setValue($value);
192  $adapter = $this->getAdapter();
193  $this->_length = $adapter->getLength();
194  $result = $adapter->checkLength($value);
195  if (!$result) {
196  if (is_array($this->_length)) {
197  $temp = $this->_length;
198  $this->_length = "";
199  foreach($temp as $length) {
200  $this->_length .= "/";
201  $this->_length .= $length;
202  }
203 
204  $this->_length = substr($this->_length, 1);
205  }
206 
207  $this->_error(self::INVALID_LENGTH);
208  return false;
209  }
210 
211  $result = $adapter->checkChars($value);
212  if (!$result) {
213  $this->_error(self::INVALID_CHARS);
214  return false;
215  }
216 
217  if ($this->getChecksum()) {
218  $result = $adapter->checksum($value);
219  if (!$result) {
220  $this->_error(self::FAILED);
221  return false;
222  }
223  }
224 
225  return true;
226  }
$adapter
Definition: webapi_user.php:16
_error($messageKey, $value=null)
Definition: Abstract.php:284
$value
Definition: gender.phtml:16

◆ setAdapter()

setAdapter (   $adapter,
  $options = null 
)

Sets a new barcode adapter

Parameters
string | Zend_Validate_Barcode$adapterBarcode adapter to use
array$optionsOptions for this adapter
Returns
$this
Exceptions
Zend_Validate_Exception

Definition at line 131 of file Barcode.php.

132  {
133  $adapter = ucfirst(strtolower($adapter));
134  #require_once 'Zend/Loader.php';
135  if (Zend_Loader::isReadable('Zend/Validate/Barcode/' . $adapter. '.php')) {
136  $adapter = 'Zend_Validate_Barcode_' . $adapter;
137  }
138 
139  if (!class_exists($adapter)) {
141  }
142 
143  $this->_adapter = new $adapter($options);
144  if (!$this->_adapter instanceof Zend_Validate_Barcode_AdapterInterface) {
145  #require_once 'Zend/Validate/Exception.php';
146  throw new Zend_Validate_Exception(
147  "Adapter " . $adapter . " does not implement Zend_Validate_Barcode_AdapterInterface"
148  );
149  }
150 
151  return $this;
152  }
static loadClass($class, $dirs=null)
Definition: Loader.php:52
$adapter
Definition: webapi_user.php:16
static isReadable($filename)
Definition: Loader.php:162

◆ setChecksum()

setChecksum (   $checksum)

Sets the checksum option

Parameters
boolean$checksum
Returns
Zend_Validate_Barcode

Definition at line 170 of file Barcode.php.

171  {
172  $this->getAdapter()->setCheck($checksum);
173  return $this;
174  }

Field Documentation

◆ $_adapter

$_adapter
protected

Definition at line 73 of file Barcode.php.

◆ $_length

$_length
protected

Definition at line 66 of file Barcode.php.

◆ $_messageTemplates

$_messageTemplates
protected
Initial value:
= array(
self::FAILED => "'%value%' failed checksum validation",
self::INVALID_CHARS => "'%value%' contains invalid characters",
self::INVALID_LENGTH => "'%value%' should have a length of %length% characters",
self::INVALID => "Invalid type given. String expected",
)

Definition at line 45 of file Barcode.php.

◆ $_messageVariables

$_messageVariables
protected
Initial value:
= array(
'length' => '_length'
)

Definition at line 57 of file Barcode.php.

◆ FAILED

const FAILED = 'barcodeFailed'

Definition at line 41 of file Barcode.php.

◆ INVALID

const INVALID = 'barcodeInvalid'

Definition at line 40 of file Barcode.php.

◆ INVALID_CHARS

const INVALID_CHARS = 'barcodeInvalidChars'

Definition at line 42 of file Barcode.php.

◆ INVALID_LENGTH

const INVALID_LENGTH = 'barcodeInvalidLength'

Definition at line 43 of file Barcode.php.


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