source-class-Com.Tecnick.Barcode.Type.Linear.StandardTwoOfFiveCheck

It appears that you are using AdBlocking software. The cost of running this website is covered by advertisements. If you like it please feel free to a small amount of money to secure the future of this website.
Overview

Classes

Exceptions

  1: <?php
  2: /**
  3:  * StandardTwoOfFiveCheck.php
  4:  *
  5:  * @since       2015-02-21
  6:  * @category    Library
  7:  * @package     Barcode
  8:  * @author      Nicola Asuni <info@tecnick.com>
  9:  * @copyright   2010-2016 Nicola Asuni - Tecnick.com LTD
 10:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 11:  * @link        https://github.com/tecnickcom/tc-lib-barcode
 12:  *
 13:  * This file is part of tc-lib-barcode software library.
 14:  */
 15: 
 16: namespace Com\Tecnick\Barcode\Type\Linear;
 17: 
 18: use \Com\Tecnick\Barcode\Exception as BarcodeException;
 19: 
 20: /**
 21:  * Com\Tecnick\Barcode\Type\Linear\StandardTwoOfFiveCheck;
 22:  *
 23:  * StandardTwoOfFiveCheck Barcode type class
 24:  * Standard 2 of 5 + CHECKSUM
 25:  *
 26:  * @since       2015-02-21
 27:  * @category    Library
 28:  * @package     Barcode
 29:  * @author      Nicola Asuni <info@tecnick.com>
 30:  * @copyright   2010-2016 Nicola Asuni - Tecnick.com LTD
 31:  * @license     http://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE.TXT)
 32:  * @link        https://github.com/tecnickcom/tc-lib-barcode
 33:  */
 34: class StandardTwoOfFiveCheck extends \Com\Tecnick\Barcode\Type\Linear
 35: {
 36:     /**
 37:      * Barcode format
 38:      *
 39:      * @var string
 40:      */
 41:     protected $format = 'S25+';
 42: 
 43:     /**
 44:      * Map characters to barcodes
 45:      *
 46:      * @var array
 47:      */
 48:     protected $chbar = array(
 49:         '0' => '10101110111010',
 50:         '1' => '11101010101110',
 51:         '2' => '10111010101110',
 52:         '3' => '11101110101010',
 53:         '4' => '10101110101110',
 54:         '5' => '11101011101010',
 55:         '6' => '10111011101010',
 56:         '7' => '10101011101110',
 57:         '8' => '11101010111010',
 58:         '9' => '10111010111010'
 59:     );
 60: 
 61:     /**
 62:      * Calculate the checksum
 63:      *
 64:      * @param $code (string) code to represent.
 65:      *
 66:      * @return char checksum.
 67:      */
 68:     protected function getChecksum($code)
 69:     {
 70:         $clen = strlen($code);
 71:         $sum = 0;
 72:         for ($idx = 0; $idx < $clen; $idx+=2) {
 73:             $sum += intval($code[$idx]);
 74:         }
 75:         $sum *= 3;
 76:         for ($idx = 1; $idx < $clen; $idx+=2) {
 77:             $sum += intval($code[$idx]);
 78:         }
 79:         $check = $sum % 10;
 80:         if ($check > 0) {
 81:             $check = (10 - $check);
 82:         }
 83:         return $check;
 84:     }
 85: 
 86:     /**
 87:      * Format code
 88:      */
 89:     protected function formatCode()
 90:     {
 91:         $this->extcode = $this->code.$this->getChecksum($this->code);
 92:     }
 93:     
 94:     /**
 95:      * Get the bars array
 96:      *
 97:      * @return array
 98:      *
 99:      * @throws BarcodeException in case of error
100:      */
101:     protected function setBars()
102:     {
103:         $this->formatCode();
104:         if ((strlen($this->extcode) % 2) != 0) {
105:             // add leading zero if code-length is odd
106:             $this->extcode = '0'.$this->extcode;
107:         }
108:         $seq = '1110111010';
109:         $clen = strlen($this->extcode);
110:         for ($idx = 0; $idx < $clen; ++$idx) {
111:             $digit = $this->extcode[$idx];
112:             if (!isset($this->chbar[$digit])) {
113:                 throw new BarcodeException('Invalid character: chr('.ord($digit).')');
114:             }
115:             $seq .= $this->chbar[$digit];
116:         }
117:         $seq .= '111010111';
118:         $this->processBinarySequence($seq);
119:     }
120: }
121: 
 

© 2004-2017 – Nicola Asuni - Tecnick.com - All rights reserved.
about - disclaimer - privacy