Browse Source

[ZF-8689] Zend_Validate_Barcode:

- added a INTELLIGENTMAIL adapter

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20028 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 years ago
parent
commit
00d521205e

+ 13 - 0
documentation/manual/en/module_specs/Zend_Validate-Barcode.xml

@@ -223,6 +223,19 @@
 
         <listitem>
             <para>
+                <emphasis>INTELLIGENTMAIL</emphasis>: Intelligent Mail is a postal barcode.
+            </para>
+
+            <para>
+                This barcode can have a length of 20, 25, 29 or 31 characters. It supports only
+                digits, and contains no checksum. This standard is the successor of
+                <acronym>PLANET</acronym> and <acronym>POSTNET</acronym>. It is mainly used by the
+                United States Postal Services.
+            </para>
+        </listitem>
+
+        <listitem>
+            <para>
                 <emphasis>ITF14</emphasis>: ITF14 is the GS1 implementation of an Interleaved Two
                 of Five bar code.
             </para>

+ 58 - 0
library/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-2009 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-2009 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);
+    }
+}

+ 8 - 0
tests/Zend/Validate/BarcodeTest.php

@@ -345,6 +345,14 @@ class Zend_Validate_BarcodeTest extends PHPUnit_Framework_TestCase
         $this->assertFalse($barcode->isValid('564000000051'));
     }
 
+    public function testINTELLIGENTMAIL()
+    {
+        $barcode = new Zend_Validate_Barcode('intelligentmail');
+        $this->assertTrue($barcode->isValid('01234567094987654321'));
+        $this->assertFalse($barcode->isValid('123'));
+        $this->assertFalse($barcode->isValid('5555512371'));
+    }
+
     public function testITF14()
     {
         $barcode = new Zend_Validate_Barcode('itf14');