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 = strtr($value, chr($x), ''); } } 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(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) * * @param string $value The barcode to validate * @return boolean */ protected function _mod10($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] * 3; } else { $sum += $barcode[$length - $i]; } } $calc = $sum % 10; $checksum = ($calc === 0) ? 0 : (10 - $calc); if ($value[$length + 1] != $checksum) { return false; } return true; } }