3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Validator\Barcode
;
12 class Royalmail
extends AbstractAdapter
14 protected $rows = array(
15 '0' => 1, '1' => 1, '2' => 1, '3' => 1, '4' => 1, '5' => 1,
16 '6' => 2, '7' => 2, '8' => 2, '9' => 2, 'A' => 2, 'B' => 2,
17 'C' => 3, 'D' => 3, 'E' => 3, 'F' => 3, 'G' => 3, 'H' => 3,
18 'I' => 4, 'J' => 4, 'K' => 4, 'L' => 4, 'M' => 4, 'N' => 4,
19 'O' => 5, 'P' => 5, 'Q' => 5, 'R' => 5, 'S' => 5, 'T' => 5,
20 'U' => 0, 'V' => 0, 'W' => 0, 'X' => 0, 'Y' => 0, 'Z' => 0,
23 protected $columns = array(
24 '0' => 1, '1' => 2, '2' => 3, '3' => 4, '4' => 5, '5' => 0,
25 '6' => 1, '7' => 2, '8' => 3, '9' => 4, 'A' => 5, 'B' => 0,
26 'C' => 1, 'D' => 2, 'E' => 3, 'F' => 4, 'G' => 5, 'H' => 0,
27 'I' => 1, 'J' => 2, 'K' => 3, 'L' => 4, 'M' => 5, 'N' => 0,
28 'O' => 1, 'P' => 2, 'Q' => 3, 'R' => 4, 'S' => 5, 'T' => 0,
29 'U' => 1, 'V' => 2, 'W' => 3, 'X' => 4, 'Y' => 5, 'Z' => 0,
33 * Constructor for this barcode adapter
35 public function __construct()
38 $this->setCharacters('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ');
39 $this->setChecksum('royalmail');
43 * Validates the checksum ()
45 * @param string $value The barcode to validate
48 protected function royalmail($value)
50 $checksum = substr($value, -1, 1);
51 $values = str_split(substr($value, 0, -1));
54 foreach ($values as $row) {
55 $rowvalue +
= $this->rows
[$row];
56 $colvalue +
= $this->columns
[$row];
62 $rowchkvalue = array_keys($this->rows
, $rowvalue);
63 $colchkvalue = array_keys($this->columns
, $colvalue);
64 $intersect = array_intersect($rowchkvalue, $colchkvalue);
65 $chkvalue = current($intersect);
66 if ($chkvalue == $checksum) {
74 * Allows start and stop tag within checked chars
76 * @param string $value The barcode to check for allowed characters
79 public function hasValidCharacters($value)
81 if ($value[0] == '(') {
82 $value = substr($value, 1);
84 if ($value[strlen($value) - 1] == ')') {
85 $value = substr($value, 0, -1);
91 return parent
::hasValidCharacters($value);