Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Zend_Validate_Barcode_AdapterAbstract Class Reference
Inheritance diagram for Zend_Validate_Barcode_AdapterAbstract:
Zend_Validate_Barcode_AdapterInterface Zend_Validate_Barcode_Code25 Zend_Validate_Barcode_Code25interleaved Zend_Validate_Barcode_Code39 Zend_Validate_Barcode_Code39ext Zend_Validate_Barcode_Code93 Zend_Validate_Barcode_Code93ext Zend_Validate_Barcode_Ean12 Zend_Validate_Barcode_Ean13 Zend_Validate_Barcode_Ean14 Zend_Validate_Barcode_Ean18 Zend_Validate_Barcode_Ean2 Zend_Validate_Barcode_Ean5 Zend_Validate_Barcode_Ean8 Zend_Validate_Barcode_Gtin12 Zend_Validate_Barcode_Gtin13 Zend_Validate_Barcode_Gtin14 Zend_Validate_Barcode_Identcode Zend_Validate_Barcode_IntelligentMail Zend_Validate_Barcode_Issn Zend_Validate_Barcode_Itf14 Zend_Validate_Barcode_Leitcode Zend_Validate_Barcode_Planet Zend_Validate_Barcode_Postnet Zend_Validate_Barcode_Royalmail Zend_Validate_Barcode_Sscc Zend_Validate_Barcode_Upca Zend_Validate_Barcode_Upce

Public Member Functions

 checkLength ($value)
 
 checkChars ($value)
 
 checksum ($value)
 
 getLength ()
 
 getCharacters ()
 
 getChecksum ()
 
 getCheck ()
 
 setCheck ($check)
 

Protected Member Functions

 _gtin ($value)
 
 _identcode ($value)
 
 _code25 ($value)
 
 _postnet ($value)
 

Protected Attributes

 $_length
 
 $_characters
 
 $_checksum
 
 $_hasChecksum = true
 

Detailed Description

Definition at line 33 of file AdapterAbstract.php.

Member Function Documentation

◆ _code25()

_code25 (   $value)
protected

Validates the checksum (Modulo 10) CODE25 implementation factor 3

Parameters
string$valueThe barcode to validate
Returns
boolean

Definition at line 267 of file AdapterAbstract.php.

268  {
269  $barcode = substr($value, 0, -1);
270  $sum = 0;
271  $length = strlen($barcode) - 1;
272 
273  for ($i = 0; $i <= $length; $i++) {
274  if (($i % 2) === 0) {
275  $sum += $barcode[$i] * 3;
276  } else {
277  $sum += $barcode[$i];
278  }
279  }
280 
281  $calc = $sum % 10;
282  $checksum = ($calc === 0) ? 0 : (10 - $calc);
283  if ($value[$length + 1] != $checksum) {
284  return false;
285  }
286 
287  return true;
288  }
$value
Definition: gender.phtml:16
$i
Definition: gallery.phtml:31

◆ _gtin()

_gtin (   $value)
protected

Validates the checksum (Modulo 10) GTIN implementation factor 3

Parameters
string$valueThe barcode to validate
Returns
boolean

Definition at line 207 of file AdapterAbstract.php.

208  {
209  $barcode = substr($value, 0, -1);
210  $sum = 0;
211  $length = strlen($barcode) - 1;
212 
213  for ($i = 0; $i <= $length; $i++) {
214  if (($i % 2) === 0) {
215  $sum += $barcode[$length - $i] * 3;
216  } else {
217  $sum += $barcode[$length - $i];
218  }
219  }
220 
221  $calc = $sum % 10;
222  $checksum = ($calc === 0) ? 0 : (10 - $calc);
223  if ($value[$length + 1] != $checksum) {
224  return false;
225  }
226 
227  return true;
228  }
$value
Definition: gender.phtml:16
$i
Definition: gallery.phtml:31

◆ _identcode()

_identcode (   $value)
protected

Validates the checksum (Modulo 10) IDENTCODE implementation factors 9 and 4

Parameters
string$valueThe barcode to validate
Returns
boolean

Definition at line 237 of file AdapterAbstract.php.

238  {
239  $barcode = substr($value, 0, -1);
240  $sum = 0;
241  $length = strlen($value) - 2;
242 
243  for ($i = 0; $i <= $length; $i++) {
244  if (($i % 2) === 0) {
245  $sum += $barcode[$length - $i] * 4;
246  } else {
247  $sum += $barcode[$length - $i] * 9;
248  }
249  }
250 
251  $calc = $sum % 10;
252  $checksum = ($calc === 0) ? 0 : (10 - $calc);
253  if ($value[$length + 1] != $checksum) {
254  return false;
255  }
256 
257  return true;
258  }
$value
Definition: gender.phtml:16
$i
Definition: gallery.phtml:31

◆ _postnet()

_postnet (   $value)
protected

Validates the checksum () POSTNET implementation

Parameters
string$valueThe barcode to validate
Returns
boolean

Definition at line 297 of file AdapterAbstract.php.

298  {
299  $checksum = substr($value, -1, 1);
300  $values = str_split(substr($value, 0, -1));
301 
302  $check = 0;
303  foreach($values as $row) {
304  $check += $row;
305  }
306 
307  $check %= 10;
308  $check = 10 - $check;
309  if ($check == $checksum) {
310  return true;
311  }
312 
313  return false;
314  }
$values
Definition: options.phtml:88
$value
Definition: gender.phtml:16

◆ checkChars()

checkChars (   $value)

Checks for allowed characters within the barcode

Parameters
string$valueThe barcode to check for allowed characters
Returns
boolean

Implements Zend_Validate_Barcode_AdapterInterface.

Definition at line 106 of file AdapterAbstract.php.

107  {
108  if (!is_string($value)) {
109  return false;
110  }
111 
112  $characters = $this->getCharacters();
113  if ($characters == 128) {
114  for ($x = 0; $x < 128; ++$x) {
115  $value = str_replace(chr($x), '', $value);
116  }
117  } else {
118  $chars = str_split($characters);
119  foreach ($chars as $char) {
120  $value = str_replace($char, '', $value);
121  }
122  }
123 
124  if (strlen($value) > 0) {
125  return false;
126  }
127 
128  return true;
129  }
$value
Definition: gender.phtml:16

◆ checkLength()

checkLength (   $value)

Checks the length of a barcode

Parameters
string$valueThe barcode to check for proper length
Returns
boolean

Implements Zend_Validate_Barcode_AdapterInterface.

Definition at line 66 of file AdapterAbstract.php.

67  {
68  if (!is_string($value)) {
69  return false;
70  }
71 
72  $fixum = strlen($value);
73  $found = false;
74  $length = $this->getLength();
75  if (is_array($length)) {
76  foreach ($length as $value) {
77  if ($fixum == $value) {
78  $found = true;
79  }
80 
81  if ($value == -1) {
82  $found = true;
83  }
84  }
85  } elseif ($fixum == $length) {
86  $found = true;
87  } elseif ($length == -1) {
88  $found = true;
89  } elseif ($length == 'even') {
90  $count = $fixum % 2;
91  $found = ($count == 0) ? true : false;
92  } elseif ($length == 'odd') {
93  $count = $fixum % 2;
94  $found = ($count == 1) ? true : false;
95  }
96 
97  return $found;
98  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$count
Definition: recent.phtml:13
$value
Definition: gender.phtml:16

◆ checksum()

checksum (   $value)

Validates the checksum

Parameters
string$valueThe barcode to check the checksum for
Returns
boolean

Implements Zend_Validate_Barcode_AdapterInterface.

Definition at line 137 of file AdapterAbstract.php.

138  {
139  $checksum = $this->getChecksum();
140  if (!empty($checksum)) {
141  if (method_exists($this, $checksum)) {
142  return call_user_func(array($this, $checksum), $value);
143  }
144  }
145 
146  return false;
147  }
$value
Definition: gender.phtml:16

◆ getCharacters()

getCharacters ( )

Returns the allowed characters

Returns
integer|string

Definition at line 164 of file AdapterAbstract.php.

◆ getCheck()

getCheck ( )

Returns if barcode uses checksum

Returns
boolean

Implements Zend_Validate_Barcode_AdapterInterface.

Definition at line 183 of file AdapterAbstract.php.

◆ getChecksum()

getChecksum ( )

Returns the checksum function name

Definition at line 173 of file AdapterAbstract.php.

◆ getLength()

getLength ( )

Returns the allowed barcode length

Returns
string

Definition at line 154 of file AdapterAbstract.php.

◆ setCheck()

setCheck (   $check)

Sets the checksum validation

Parameters
boolean$check
Returns
Zend_Validate_Barcode_AdapterAbstract

Implements Zend_Validate_Barcode_AdapterInterface.

Definition at line 194 of file AdapterAbstract.php.

195  {
196  $this->_hasChecksum = (boolean) $check;
197  return $this;
198  }

Field Documentation

◆ $_characters

$_characters
protected

Definition at line 46 of file AdapterAbstract.php.

◆ $_checksum

$_checksum
protected

Definition at line 52 of file AdapterAbstract.php.

◆ $_hasChecksum

$_hasChecksum = true
protected

Definition at line 58 of file AdapterAbstract.php.

◆ $_length

$_length
protected

Definition at line 40 of file AdapterAbstract.php.


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