Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'libs/Zend/Validate/Barcode')
-rw-r--r--libs/Zend/Validate/Barcode/AdapterAbstract.php315
-rw-r--r--libs/Zend/Validate/Barcode/AdapterInterface.php68
-rw-r--r--libs/Zend/Validate/Barcode/Code25.php64
-rw-r--r--libs/Zend/Validate/Barcode/Code25interleaved.php64
-rw-r--r--libs/Zend/Validate/Barcode/Code39.php100
-rw-r--r--libs/Zend/Validate/Barcode/Code39ext.php58
-rw-r--r--libs/Zend/Validate/Barcode/Code93.php120
-rw-r--r--libs/Zend/Validate/Barcode/Code93ext.php58
-rw-r--r--libs/Zend/Validate/Barcode/Ean12.php52
-rw-r--r--libs/Zend/Validate/Barcode/Ean13.php88
-rw-r--r--libs/Zend/Validate/Barcode/Ean14.php52
-rw-r--r--libs/Zend/Validate/Barcode/Ean18.php52
-rw-r--r--libs/Zend/Validate/Barcode/Ean2.php58
-rw-r--r--libs/Zend/Validate/Barcode/Ean5.php58
-rw-r--r--libs/Zend/Validate/Barcode/Ean8.php69
-rw-r--r--libs/Zend/Validate/Barcode/Gtin12.php52
-rw-r--r--libs/Zend/Validate/Barcode/Gtin13.php52
-rw-r--r--libs/Zend/Validate/Barcode/Gtin14.php52
-rw-r--r--libs/Zend/Validate/Barcode/Identcode.php52
-rw-r--r--libs/Zend/Validate/Barcode/Intelligentmail.php58
-rw-r--r--libs/Zend/Validate/Barcode/Issn.php119
-rw-r--r--libs/Zend/Validate/Barcode/Itf14.php52
-rw-r--r--libs/Zend/Validate/Barcode/Leitcode.php52
-rw-r--r--libs/Zend/Validate/Barcode/Planet.php52
-rw-r--r--libs/Zend/Validate/Barcode/Postnet.php52
-rw-r--r--libs/Zend/Validate/Barcode/Royalmail.php121
-rw-r--r--libs/Zend/Validate/Barcode/Sscc.php52
-rw-r--r--libs/Zend/Validate/Barcode/UpcA.php103
-rw-r--r--libs/Zend/Validate/Barcode/Upca.php52
-rw-r--r--libs/Zend/Validate/Barcode/Upce.php69
30 files changed, 2090 insertions, 176 deletions
diff --git a/libs/Zend/Validate/Barcode/AdapterAbstract.php b/libs/Zend/Validate/Barcode/AdapterAbstract.php
new file mode 100644
index 0000000000..043189e6c2
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/AdapterAbstract.php
@@ -0,0 +1,315 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterInterface
+ */
+require_once 'Zend/Validate/Barcode/AdapterInterface.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+abstract class Zend_Validate_Barcode_AdapterAbstract
+ implements Zend_Validate_Barcode_AdapterInterface
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer|array|string
+ */
+ protected $_length;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters;
+
+ /**
+ * Callback to checksum function
+ * @var string|array
+ */
+ protected $_checksum;
+
+ /**
+ * Is a checksum value included?
+ * @var boolean
+ */
+ protected $_hasChecksum = true;
+
+ /**
+ * Checks the length of a barcode
+ *
+ * @param string $value The barcode to check for proper length
+ * @return boolean
+ */
+ public function checkLength($value)
+ {
+ if (!is_string($value)) {
+ return false;
+ }
+
+ $fixum = strlen($value);
+ $found = false;
+ $length = $this->getLength();
+ if (is_array($length)) {
+ foreach ($length as $value) {
+ if ($fixum == $value) {
+ $found = true;
+ }
+
+ if ($value == -1) {
+ $found = true;
+ }
+ }
+ } elseif ($fixum == $length) {
+ $found = true;
+ } elseif ($length == -1) {
+ $found = true;
+ } elseif ($length == 'even') {
+ $count = $fixum % 2;
+ $found = ($count == 0) ? true : false;
+ } elseif ($length == 'odd') {
+ $count = $fixum % 2;
+ $found = ($count == 1) ? true : false;
+ }
+
+ return $found;
+ }
+
+ /**
+ * Checks for allowed characters within the barcode
+ *
+ * @param string $value The barcode to check for allowed characters
+ * @return boolean
+ */
+ public function checkChars($value)
+ {
+ if (!is_string($value)) {
+ return false;
+ }
+
+ $characters = $this->getCharacters();
+ if ($characters == 128) {
+ for ($x = 0; $x < 128; ++$x) {
+ $value = str_replace(chr($x), '', $value);
+ }
+ } else {
+ $chars = str_split($characters);
+ foreach ($chars as $char) {
+ $value = str_replace($char, '', $value);
+ }
+ }
+
+ if (strlen($value) > 0) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Validates the checksum
+ *
+ * @param string $value The barcode to check the checksum for
+ * @return boolean
+ */
+ public function checksum($value)
+ {
+ $checksum = $this->getChecksum();
+ if (!empty($checksum)) {
+ if (method_exists($this, $checksum)) {
+ return call_user_func(array($this, $checksum), $value);
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns the allowed barcode length
+ *
+ * @return string
+ */
+ public function getLength()
+ {
+ return $this->_length;
+ }
+
+ /**
+ * Returns the allowed characters
+ *
+ * @return integer|string
+ */
+ public function getCharacters()
+ {
+ return $this->_characters;
+ }
+
+ /**
+ * Returns the checksum function name
+ *
+ */
+ public function getChecksum()
+ {
+ return $this->_checksum;
+ }
+
+ /**
+ * Returns if barcode uses checksum
+ *
+ * @return boolean
+ */
+ public function getCheck()
+ {
+ return $this->_hasChecksum;
+ }
+
+ /**
+ * Sets the checksum validation
+ *
+ * @param boolean $check
+ * @return Zend_Validate_Barcode_AdapterAbstract
+ */
+ public function setCheck($check)
+ {
+ $this->_hasChecksum = (boolean) $check;
+ return $this;
+ }
+
+ /**
+ * Validates the checksum (Modulo 10)
+ * GTIN implementation factor 3
+ *
+ * @param string $value The barcode to validate
+ * @return boolean
+ */
+ protected function _gtin($value)
+ {
+ $barcode = substr($value, 0, -1);
+ $sum = 0;
+ $length = strlen($barcode) - 1;
+
+ for ($i = 0; $i <= $length; $i++) {
+ if (($i % 2) === 0) {
+ $sum += $barcode[$length - $i] * 3;
+ } else {
+ $sum += $barcode[$length - $i];
+ }
+ }
+
+ $calc = $sum % 10;
+ $checksum = ($calc === 0) ? 0 : (10 - $calc);
+ if ($value[$length + 1] != $checksum) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Validates the checksum (Modulo 10)
+ * IDENTCODE implementation factors 9 and 4
+ *
+ * @param string $value The barcode to validate
+ * @return boolean
+ */
+ protected function _identcode($value)
+ {
+ $barcode = substr($value, 0, -1);
+ $sum = 0;
+ $length = strlen($value) - 2;
+
+ for ($i = 0; $i <= $length; $i++) {
+ if (($i % 2) === 0) {
+ $sum += $barcode[$length - $i] * 4;
+ } else {
+ $sum += $barcode[$length - $i] * 9;
+ }
+ }
+
+ $calc = $sum % 10;
+ $checksum = ($calc === 0) ? 0 : (10 - $calc);
+ if ($value[$length + 1] != $checksum) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Validates the checksum (Modulo 10)
+ * CODE25 implementation factor 3
+ *
+ * @param string $value The barcode to validate
+ * @return boolean
+ */
+ protected function _code25($value)
+ {
+ $barcode = substr($value, 0, -1);
+ $sum = 0;
+ $length = strlen($barcode) - 1;
+
+ for ($i = 0; $i <= $length; $i++) {
+ if (($i % 2) === 0) {
+ $sum += $barcode[$i] * 3;
+ } else {
+ $sum += $barcode[$i];
+ }
+ }
+
+ $calc = $sum % 10;
+ $checksum = ($calc === 0) ? 0 : (10 - $calc);
+ if ($value[$length + 1] != $checksum) {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Validates the checksum ()
+ * POSTNET implementation
+ *
+ * @param string $value The barcode to validate
+ * @return boolean
+ */
+ protected function _postnet($value)
+ {
+ $checksum = substr($value, -1, 1);
+ $values = str_split(substr($value, 0, -1));
+
+ $check = 0;
+ foreach($values as $row) {
+ $check += $row;
+ }
+
+ $check %= 10;
+ $check = 10 - $check;
+ if ($check == $checksum) {
+ return true;
+ }
+
+ return false;
+ }
+}
diff --git a/libs/Zend/Validate/Barcode/AdapterInterface.php b/libs/Zend/Validate/Barcode/AdapterInterface.php
new file mode 100644
index 0000000000..325c6048f3
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/AdapterInterface.php
@@ -0,0 +1,68 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $
+ */
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+interface Zend_Validate_Barcode_AdapterInterface
+{
+ /**
+ * Checks the length of a barcode
+ *
+ * @param string $value The barcode to check for proper length
+ * @return boolean
+ */
+ public function checkLength($value);
+
+ /**
+ * Checks for allowed characters within the barcode
+ *
+ * @param string $value The barcode to check for allowed characters
+ * @return boolean
+ */
+ public function checkChars($value);
+
+ /**
+ * Validates the checksum
+ *
+ * @param string $value The barcode to check the checksum for
+ * @return boolean
+ */
+ public function checksum($value);
+
+ /**
+ * Returns if barcode uses a checksum
+ *
+ * @return boolean
+ */
+ public function getCheck();
+
+ /**
+ * Sets the checksum validation
+ *
+ * @param boolean $check
+ * @return Zend_Validate_Barcode_Adapter Provides fluid interface
+ */
+ public function setCheck($check);
+}
diff --git a/libs/Zend/Validate/Barcode/Code25.php b/libs/Zend/Validate/Barcode/Code25.php
new file mode 100644
index 0000000000..efb5a395c7
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Code25.php
@@ -0,0 +1,64 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id:$
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Code25 extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = -1;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_code25';
+
+ /**
+ * Constructor
+ *
+ * Sets check flag to false.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ $this->setCheck(false);
+ }
+}
diff --git a/libs/Zend/Validate/Barcode/Code25interleaved.php b/libs/Zend/Validate/Barcode/Code25interleaved.php
new file mode 100644
index 0000000000..7e5a8d919b
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Code25interleaved.php
@@ -0,0 +1,64 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id:$
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Code25interleaved extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = 'even';
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_code25';
+
+ /**
+ * Constructor
+ *
+ * Sets check flag to false.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ $this->setCheck(false);
+ }
+}
diff --git a/libs/Zend/Validate/Barcode/Code39.php b/libs/Zend/Validate/Barcode/Code39.php
new file mode 100644
index 0000000000..858084fe25
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Code39.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id:$
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Code39 extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = -1;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ -.$/+%';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_code39';
+
+ /**
+ * @var array
+ */
+ protected $_check = array(
+ '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6,
+ '7' => 7, '8' => 8, '9' => 9, 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13,
+ 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20,
+ 'L' => 21, 'M' => 22, 'N' => 23, 'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27,
+ 'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31, 'W' => 32, 'X' => 33, 'Y' => 34,
+ 'Z' => 35, '-' => 36, '.' => 37, ' ' => 38, '$' => 39, '/' => 40, '+' => 41,
+ '%' => 42,
+ );
+
+ /**
+ * Constructor
+ *
+ * Sets check flag to false.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ $this->setCheck(false);
+ }
+
+ /**
+ * Validates the checksum (Modulo 43)
+ *
+ * @param string $value The barcode to validate
+ * @return boolean
+ */
+ protected function _code39($value)
+ {
+ $checksum = substr($value, -1, 1);
+ $value = str_split(substr($value, 0, -1));
+ $count = 0;
+ foreach($value as $char) {
+ $count += $this->_check[$char];
+ }
+
+ $mod = $count % 43;
+ if ($mod == $this->_check[$checksum]) {
+ return true;
+ }
+
+ return false;
+ }
+}
diff --git a/libs/Zend/Validate/Barcode/Code39ext.php b/libs/Zend/Validate/Barcode/Code39ext.php
new file mode 100644
index 0000000000..5c1d65ee64
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Code39ext.php
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id:$
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Code39ext extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = -1;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = 128;
+
+ /**
+ * Constructor
+ *
+ * Sets check flag to false.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ $this->setCheck(false);
+ }
+}
diff --git a/libs/Zend/Validate/Barcode/Code93.php b/libs/Zend/Validate/Barcode/Code93.php
new file mode 100644
index 0000000000..deb5183d43
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Code93.php
@@ -0,0 +1,120 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id:$
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Code93 extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = -1;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ -.$/+%';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_code93';
+
+ /**
+ * Note that the characters !"§& are only synonyms
+ * @var array
+ */
+ protected $_check = array(
+ '0' => 0, '1' => 1, '2' => 2, '3' => 3, '4' => 4, '5' => 5, '6' => 6,
+ '7' => 7, '8' => 8, '9' => 9, 'A' => 10, 'B' => 11, 'C' => 12, 'D' => 13,
+ 'E' => 14, 'F' => 15, 'G' => 16, 'H' => 17, 'I' => 18, 'J' => 19, 'K' => 20,
+ 'L' => 21, 'M' => 22, 'N' => 23, 'O' => 24, 'P' => 25, 'Q' => 26, 'R' => 27,
+ 'S' => 28, 'T' => 29, 'U' => 30, 'V' => 31, 'W' => 32, 'X' => 33, 'Y' => 34,
+ 'Z' => 35, '-' => 36, '.' => 37, ' ' => 38, '$' => 39, '/' => 40, '+' => 41,
+ '%' => 42, '!' => 43, '"' => 44, '§' => 45, '&' => 46,
+ );
+
+ /**
+ * Constructor
+ *
+ * Sets check flag to false.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ $this->setCheck(false);
+ }
+
+ /**
+ * Validates the checksum (Modulo CK)
+ *
+ * @param string $value The barcode to validate
+ * @return boolean
+ */
+ protected function _code93($value)
+ {
+ $checksum = substr($value, -2, 2);
+ $value = str_split(substr($value, 0, -2));
+ $count = 0;
+ $length = count($value) % 20;
+ foreach($value as $char) {
+ if ($length == 0) {
+ $length = 20;
+ }
+
+ $count += $this->_check[$char] * $length;
+ --$length;
+ }
+
+ $check = array_search(($count % 47), $this->_check);
+ $value[] = $check;
+ $count = 0;
+ $length = count($value) % 15;
+ foreach($value as $char) {
+ if ($length == 0) {
+ $length = 15;
+ }
+
+ $count += $this->_check[$char] * $length;
+ --$length;
+ }
+ $check .= array_search(($count % 47), $this->_check);
+
+ if ($check == $checksum) {
+ return true;
+ }
+
+ return false;
+ }
+}
diff --git a/libs/Zend/Validate/Barcode/Code93ext.php b/libs/Zend/Validate/Barcode/Code93ext.php
new file mode 100644
index 0000000000..740d485c4a
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Code93ext.php
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id:$
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Code93ext extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = -1;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = 128;
+
+ /**
+ * Constructor
+ *
+ * Sets check flag to false.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ $this->setCheck(false);
+ }
+}
diff --git a/libs/Zend/Validate/Barcode/Ean12.php b/libs/Zend/Validate/Barcode/Ean12.php
new file mode 100644
index 0000000000..56a2384be2
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Ean12.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Ean12 extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = 12;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_gtin';
+}
diff --git a/libs/Zend/Validate/Barcode/Ean13.php b/libs/Zend/Validate/Barcode/Ean13.php
index 068809248c..b7e52f4c13 100644
--- a/libs/Zend/Validate/Barcode/Ean13.php
+++ b/libs/Zend/Validate/Barcode/Ean13.php
@@ -1,5 +1,4 @@
<?php
-
/**
* Zend Framework
*
@@ -15,96 +14,39 @@
*
* @category Zend
* @package Zend_Validate
- * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id: Ean13.php 16223 2009-06-21 20:04:53Z thomas $
+ * @version $Id: Ean13.php 20096 2010-01-06 02:05:09Z bkarwin $
*/
-
/**
- * @see Zend_Validate_Abstract
+ * @see Zend_Validate_Barcode_AdapterAbstract
*/
-require_once 'Zend/Validate/Abstract.php';
-
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
/**
* @category Zend
* @package Zend_Validate
- * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
-class Zend_Validate_Barcode_Ean13 extends Zend_Validate_Abstract
+class Zend_Validate_Barcode_Ean13 extends Zend_Validate_Barcode_AdapterAbstract
{
/**
- * Validation failure message key for when the value is
- * an invalid barcode
- */
- const INVALID = 'invalid';
-
- /**
- * Validation failure message key for when the value is
- * not 13 characters long
+ * Allowed barcode lengths
+ * @var integer
*/
- const INVALID_LENGTH = 'invalidLength';
+ protected $_length = 13;
/**
- * Validation failure message key for when the value
- * does not only contain numeric characters
+ * Allowed barcode characters
+ * @var string
*/
- const NOT_NUMERIC = 'ean13NotNumeric';
+ protected $_characters = '0123456789';
/**
- * Validation failure message template definitions
- *
- * @var array
+ * Checksum function
+ * @var string
*/
- protected $_messageTemplates = array(
- self::INVALID => "'%value%' is an invalid EAN-13 barcode",
- self::INVALID_LENGTH => "'%value%' should be 13 characters",
- self::NOT_NUMERIC => "'%value%' should contain only numeric characters",
- );
-
- /**
- * Defined by Zend_Validate_Interface
- *
- * Returns true if and only if $value contains a valid barcode
- *
- * @param string $value
- * @return boolean
- */
- public function isValid($value)
- {
- if (!is_string($value) || !ctype_digit($value)) {
- $this->_error(self::NOT_NUMERIC);
- return false;
- }
-
- $this->_setValue($value);
- if (strlen($value) !== 13) {
- $this->_error(self::INVALID_LENGTH);
- return false;
- }
-
- $barcode = strrev(substr($value, 0, -1));
- $oddSum = 0;
- $evenSum = 0;
-
- for ($i = 0; $i < 12; $i++) {
- if ($i % 2 === 0) {
- $oddSum += $barcode[$i] * 3;
- } elseif ($i % 2 === 1) {
- $evenSum += $barcode[$i];
- }
- }
-
- $calculation = ($oddSum + $evenSum) % 10;
- $checksum = ($calculation === 0) ? 0 : 10 - $calculation;
-
- if ($value[12] != $checksum) {
- $this->_error(self::INVALID);
- return false;
- }
-
- return true;
- }
+ protected $_checksum = '_gtin';
}
diff --git a/libs/Zend/Validate/Barcode/Ean14.php b/libs/Zend/Validate/Barcode/Ean14.php
new file mode 100644
index 0000000000..93d46d8c4f
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Ean14.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Ean14 extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = 14;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_gtin';
+}
diff --git a/libs/Zend/Validate/Barcode/Ean18.php b/libs/Zend/Validate/Barcode/Ean18.php
new file mode 100644
index 0000000000..93398dd916
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Ean18.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Ean18 extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = 18;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_gtin';
+}
diff --git a/libs/Zend/Validate/Barcode/Ean2.php b/libs/Zend/Validate/Barcode/Ean2.php
new file mode 100644
index 0000000000..deab558ea4
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Ean2.php
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id:$
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Ean2 extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = 2;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Constructor
+ *
+ * Sets check flag to false.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ $this->setCheck(false);
+ }
+}
diff --git a/libs/Zend/Validate/Barcode/Ean5.php b/libs/Zend/Validate/Barcode/Ean5.php
new file mode 100644
index 0000000000..af6e493241
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Ean5.php
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id:$
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Ean5 extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = 5;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Constructor
+ *
+ * Sets check flag to false.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ $this->setCheck(false);
+ }
+}
diff --git a/libs/Zend/Validate/Barcode/Ean8.php b/libs/Zend/Validate/Barcode/Ean8.php
new file mode 100644
index 0000000000..c87af039fd
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Ean8.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id:$
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Ean8 extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = array(7, 8);
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_gtin';
+
+ /**
+ * Overrides parent checkLength
+ *
+ * @param string $value Value
+ * @return boolean
+ */
+ public function checkLength($value)
+ {
+ if (strlen($value) == 7) {
+ $this->setCheck(false);
+ } else {
+ $this->setCheck(true);
+ }
+
+ return parent::checkLength($value);
+ }
+}
diff --git a/libs/Zend/Validate/Barcode/Gtin12.php b/libs/Zend/Validate/Barcode/Gtin12.php
new file mode 100644
index 0000000000..8915c4ec4c
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Gtin12.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Gtin12 extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = 12;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_gtin';
+}
diff --git a/libs/Zend/Validate/Barcode/Gtin13.php b/libs/Zend/Validate/Barcode/Gtin13.php
new file mode 100644
index 0000000000..0719b31eb6
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Gtin13.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Gtin13 extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = 13;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_gtin';
+}
diff --git a/libs/Zend/Validate/Barcode/Gtin14.php b/libs/Zend/Validate/Barcode/Gtin14.php
new file mode 100644
index 0000000000..d1dad51069
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Gtin14.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Gtin14 extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = 14;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_gtin';
+}
diff --git a/libs/Zend/Validate/Barcode/Identcode.php b/libs/Zend/Validate/Barcode/Identcode.php
new file mode 100644
index 0000000000..c0119a5cd9
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Identcode.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id:$
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Identcode extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = 12;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_identcode';
+}
diff --git a/libs/Zend/Validate/Barcode/Intelligentmail.php b/libs/Zend/Validate/Barcode/Intelligentmail.php
new file mode 100644
index 0000000000..4c266db8a4
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Intelligentmail.php
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id:$
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_IntelligentMail extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = array(20, 25, 29, 31);
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Constructor
+ *
+ * Sets check flag to false.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ $this->setCheck(false);
+ }
+}
diff --git a/libs/Zend/Validate/Barcode/Issn.php b/libs/Zend/Validate/Barcode/Issn.php
new file mode 100644
index 0000000000..be629920e7
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Issn.php
@@ -0,0 +1,119 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id:$
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Issn extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = array(8, 13);
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789X';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_gtin';
+
+ /**
+ * Allows X on length of 8 chars
+ *
+ * @param string $value The barcode to check for allowed characters
+ * @return boolean
+ */
+ public function checkChars($value)
+ {
+ if (strlen($value) != 8) {
+ if (strpos($value, 'X') !== false) {
+ return false;
+ }
+ }
+
+ return parent::checkChars($value);
+ }
+
+ /**
+ * Validates the checksum
+ *
+ * @param string $value The barcode to check the checksum for
+ * @return boolean
+ */
+ public function checksum($value)
+ {
+ if (strlen($value) == 8) {
+ $this->_checksum = '_issn';
+ } else {
+ $this->_checksum = '_gtin';
+ }
+
+ return parent::checksum($value);
+ }
+
+ /**
+ * Validates the checksum ()
+ * ISSN implementation (reversed mod11)
+ *
+ * @param string $value The barcode to validate
+ * @return boolean
+ */
+ protected function _issn($value)
+ {
+ $checksum = substr($value, -1, 1);
+ $values = str_split(substr($value, 0, -1));
+ $check = 0;
+ $multi = 8;
+ foreach($values as $token) {
+ if ($token == 'X') {
+ $token = 10;
+ }
+
+ $check += ($token * $multi);
+ --$multi;
+ }
+
+ $check %= 11;
+ $check = 11 - $check;
+ if ($check == $checksum) {
+ return true;
+ } else if (($check == 10) && ($checksum == 'X')) {
+ return true;
+ }
+
+ return false;
+ }
+}
diff --git a/libs/Zend/Validate/Barcode/Itf14.php b/libs/Zend/Validate/Barcode/Itf14.php
new file mode 100644
index 0000000000..d207a314c8
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Itf14.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Itf14 extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = 14;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_gtin';
+}
diff --git a/libs/Zend/Validate/Barcode/Leitcode.php b/libs/Zend/Validate/Barcode/Leitcode.php
new file mode 100644
index 0000000000..551ded0649
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Leitcode.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id:$
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Leitcode extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = 14;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_identcode';
+}
diff --git a/libs/Zend/Validate/Barcode/Planet.php b/libs/Zend/Validate/Barcode/Planet.php
new file mode 100644
index 0000000000..72608fa38a
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Planet.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id:$
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Planet extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = array(12, 14);
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_postnet';
+}
diff --git a/libs/Zend/Validate/Barcode/Postnet.php b/libs/Zend/Validate/Barcode/Postnet.php
new file mode 100644
index 0000000000..c638dc7314
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Postnet.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id:$
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Postnet extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = array(6, 7, 10, 12);
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_postnet';
+}
diff --git a/libs/Zend/Validate/Barcode/Royalmail.php b/libs/Zend/Validate/Barcode/Royalmail.php
new file mode 100644
index 0000000000..8c4b733b5b
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Royalmail.php
@@ -0,0 +1,121 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id:$
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Royalmail extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = -1;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
+
+ protected $_rows = array(
+ '0' => 1, '1' => 1, '2' => 1, '3' => 1, '4' => 1, '5' => 1,
+ '6' => 2, '7' => 2, '8' => 2, '9' => 2, 'A' => 2, 'B' => 2,
+ 'C' => 3, 'D' => 3, 'E' => 3, 'F' => 3, 'G' => 3, 'H' => 3,
+ 'I' => 4, 'J' => 4, 'K' => 4, 'L' => 4, 'M' => 4, 'N' => 4,
+ 'O' => 5, 'P' => 5, 'Q' => 5, 'R' => 5, 'S' => 5, 'T' => 5,
+ 'U' => 0, 'V' => 0, 'W' => 0, 'X' => 0, 'Y' => 0, 'Z' => 0,
+ );
+
+ protected $_columns = array(
+ '0' => 1, '1' => 2, '2' => 3, '3' => 4, '4' => 5, '5' => 0,
+ '6' => 1, '7' => 2, '8' => 3, '9' => 4, 'A' => 5, 'B' => 0,
+ 'C' => 1, 'D' => 2, 'E' => 3, 'F' => 4, 'G' => 5, 'H' => 0,
+ 'I' => 1, 'J' => 2, 'K' => 3, 'L' => 4, 'M' => 5, 'N' => 0,
+ 'O' => 1, 'P' => 2, 'Q' => 3, 'R' => 4, 'S' => 5, 'T' => 0,
+ 'U' => 1, 'V' => 2, 'W' => 3, 'X' => 4, 'Y' => 5, 'Z' => 0,
+ );
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_royalmail';
+
+ /**
+ * Validates the checksum ()
+ *
+ * @param string $value The barcode to validate
+ * @return boolean
+ */
+ protected function _royalmail($value)
+ {
+ $checksum = substr($value, -1, 1);
+ $values = str_split(substr($value, 0, -1));
+ $rowvalue = 0;
+ $colvalue = 0;
+ foreach($values as $row) {
+ $rowvalue += $this->_rows[$row];
+ $colvalue += $this->_columns[$row];
+ }
+
+ $rowvalue %= 6;
+ $colvalue %= 6;
+
+ $rowchkvalue = array_keys($this->_rows, $rowvalue);
+ $colchkvalue = array_keys($this->_columns, $colvalue);
+ $chkvalue = current(array_intersect($rowchkvalue, $colchkvalue));
+ if ($chkvalue == $checksum) {
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Allows start and stop tag within checked chars
+ *
+ * @param string $value The barcode to check for allowed characters
+ * @return boolean
+ */
+ public function checkChars($value)
+ {
+ if ($value[0] == '(') {
+ $value = substr($value, 1);
+
+ if ($value[strlen($value) - 1] == ')') {
+ $value = substr($value, 0, -1);
+ } else {
+ return false;
+ }
+ }
+
+ return parent::checkChars($value);
+ }
+}
diff --git a/libs/Zend/Validate/Barcode/Sscc.php b/libs/Zend/Validate/Barcode/Sscc.php
new file mode 100644
index 0000000000..50dd820793
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Sscc.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Ean13.php 18028 2009-09-08 20:52:23Z thomas $
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Sscc extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = 18;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_gtin';
+}
diff --git a/libs/Zend/Validate/Barcode/UpcA.php b/libs/Zend/Validate/Barcode/UpcA.php
deleted file mode 100644
index cf33f31fab..0000000000
--- a/libs/Zend/Validate/Barcode/UpcA.php
+++ /dev/null
@@ -1,103 +0,0 @@
-<?php
-
-/**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Validate
- * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id: UpcA.php 16223 2009-06-21 20:04:53Z thomas $
- */
-
-
-/**
- * @see Zend_Validate_Abstract
- */
-require_once 'Zend/Validate/Abstract.php';
-
-
-/**
- * @category Zend
- * @package Zend_Validate
- * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
-class Zend_Validate_Barcode_UpcA extends Zend_Validate_Abstract
-{
- /**
- * Validation failure message key for when the value is
- * an invalid barcode
- */
- const INVALID = 'invalid';
-
- /**
- * Validation failure message key for when the value is
- * not 12 characters long
- */
- const INVALID_LENGTH = 'invalidLength';
-
- /**
- * Validation failure message template definitions
- *
- * @var array
- */
- protected $_messageTemplates = array(
- self::INVALID => "'%value%' is an invalid UPC-A barcode",
- self::INVALID_LENGTH => "'%value%' should be 12 characters",
- );
-
- /**
- * Defined by Zend_Validate_Interface
- *
- * Returns true if and only if $value contains a valid barcode
- *
- * @param string $value
- * @return boolean
- */
- public function isValid($value)
- {
- if (!is_string($value)) {
- $this->_error(self::INVALID);
- return false;
- }
-
- $this->_setValue($value);
- if (strlen($value) !== 12) {
- $this->_error(self::INVALID_LENGTH);
- return false;
- }
-
- $barcode = substr($value, 0, -1);
- $oddSum = 0;
- $evenSum = 0;
-
- for ($i = 0; $i < 11; $i++) {
- if ($i % 2 === 0) {
- $oddSum += $barcode[$i] * 3;
- } elseif ($i % 2 === 1) {
- $evenSum += $barcode[$i];
- }
- }
-
- $calculation = ($oddSum + $evenSum) % 10;
- $checksum = ($calculation === 0) ? 0 : 10 - $calculation;
-
- if ($value[11] != $checksum) {
- $this->_error(self::INVALID);
- return false;
- }
-
- return true;
- }
-}
diff --git a/libs/Zend/Validate/Barcode/Upca.php b/libs/Zend/Validate/Barcode/Upca.php
new file mode 100644
index 0000000000..449c78dd37
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Upca.php
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: Upca.php 20096 2010-01-06 02:05:09Z bkarwin $
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Upca extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = 12;
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_gtin';
+}
diff --git a/libs/Zend/Validate/Barcode/Upce.php b/libs/Zend/Validate/Barcode/Upce.php
new file mode 100644
index 0000000000..f4ccc74eb6
--- /dev/null
+++ b/libs/Zend/Validate/Barcode/Upce.php
@@ -0,0 +1,69 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ * @version $Id: UpcA.php 18028 2009-09-08 20:52:23Z thomas $
+ */
+
+/**
+ * @see Zend_Validate_Barcode_AdapterAbstract
+ */
+require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
+
+/**
+ * @category Zend
+ * @package Zend_Validate
+ * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license http://framework.zend.com/license/new-bsd New BSD License
+ */
+class Zend_Validate_Barcode_Upce extends Zend_Validate_Barcode_AdapterAbstract
+{
+ /**
+ * Allowed barcode lengths
+ * @var integer
+ */
+ protected $_length = array(6, 7, 8);
+
+ /**
+ * Allowed barcode characters
+ * @var string
+ */
+ protected $_characters = '0123456789';
+
+ /**
+ * Checksum function
+ * @var string
+ */
+ protected $_checksum = '_gtin';
+
+ /**
+ * Overrides parent checkLength
+ *
+ * @param string $value Value
+ * @return boolean
+ */
+ public function checkLength($value)
+ {
+ if (strlen($value) != 8) {
+ $this->setCheck(false);
+ } else {
+ $this->setCheck(true);
+ }
+
+ return parent::checkLength($value);
+ }
+}