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

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:  * MsiCheck.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\MsiCheck;
 22:  *
 23:  * MsiCheck Barcode type class
 24:  * MSI + CHECKSUM (modulo 11)
 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 MsiCheck extends \Com\Tecnick\Barcode\Type\Linear
 35: {
 36:     /**
 37:      * Barcode format
 38:      *
 39:      * @var string
 40:      */
 41:     protected $format = 'MSI+';
 42: 
 43:     /**
 44:      * Map characters to barcodes
 45:      *
 46:      * @var array
 47:      */
 48:     protected $chbar = array(
 49:         '0' => '100100100100',
 50:         '1' => '100100100110',
 51:         '2' => '100100110100',
 52:         '3' => '100100110110',
 53:         '4' => '100110100100',
 54:         '5' => '100110100110',
 55:         '6' => '100110110100',
 56:         '7' => '100110110110',
 57:         '8' => '110100100100',
 58:         '9' => '110100100110',
 59:         'A' => '110100110100',
 60:         'B' => '110100110110',
 61:         'C' => '110110100100',
 62:         'D' => '110110100110',
 63:         'E' => '110110110100',
 64:         'F' => '110110110110'
 65:     );
 66: 
 67:     /**
 68:      * Calculate the checksum
 69:      *
 70:      * @param $code (string) code to represent.
 71:      *
 72:      * @return char checksum.
 73:      */
 74:     protected function getChecksum($code)
 75:     {
 76:         $clen = strlen($code);
 77:         $pix = 2;
 78:         $check = 0;
 79:         for ($pos = ($clen - 1); $pos >= 0; --$pos) {
 80:             $check += (hexdec($code[$pos]) * $pix);
 81:             ++$pix;
 82:             if ($pix > 7) {
 83:                 $pix = 2;
 84:             }
 85:         }
 86:         $check %= 11;
 87:         if ($check > 0) {
 88:             $check = (11 - $check);
 89:         }
 90:         return $check;
 91:     }
 92: 
 93:     /**
 94:      * Format code
 95:      */
 96:     protected function formatCode()
 97:     {
 98:         $this->extcode = $this->code.$this->getChecksum($this->code);
 99:     }
100:     
101:     /**
102:      * Get the bars array
103:      *
104:      * @return array
105:      *
106:      * @throws BarcodeException in case of error
107:      */
108:     protected function setBars()
109:     {
110:         $this->formatCode();
111:         $seq = '110'; // left guard
112:         $clen = strlen($this->extcode);
113:         for ($pos = 0; $pos < $clen; ++$pos) {
114:             $digit = $this->extcode[$pos];
115:             if (!isset($this->chbar[$digit])) {
116:                 throw new BarcodeException('Invalid character: chr('.ord($digit).')');
117:             }
118:             $seq .= $this->chbar[$digit];
119:         }
120:         $seq .= '1001'; // right guard
121:         $this->processBinarySequence($seq);
122:     }
123: }
124: 
 

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