Skip to end of metadata
Go to start of metadata

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[

Zend Framework: Zend_CheckDigit Component Proposal

Proposed Component Name Zend_CheckDigit
Developer Notes http://framework.zend.com/wiki/display/ZFDEV/Zend_CheckDigit
Proposers Steven Brown
Revision 0.1 - 7 February 2008: Created.
0.2 - 9 February 2008: Added more algorithms due to community request (wiki revision: 13)

Table of Contents

1. Overview

Zend_CheckDigit is a utility class to provide access to creation of check digits and validation using various check digit algorithms.

2. References

3. Component Requirements, Constraints, and Acceptance Criteria

  • This component will allow developers to generate check digits from a given number
  • This component will allow developers to validate a given number (with the check digit included)
  • This component will implement the Luhn algorithm
  • This component will implement the Verhoeff algorithm
  • This component will implement the Code 39 mod 43 barcode algorithm
  • This component will implement the Code 128 mod 103 barcode algorithm
  • This component will implement the ISBN-10 algorithm
  • This component will implement the ISBN-13 algorithm
  • This component will implement the EAN-13 algorithm
  • This component will implement the UPC-A algorithm

Additional algorithms that might be considered include:

  • VIN
  • Luhn Mod N
  • EAN-8
  • Other algorithms listed on the Wikipedia page

Some other notes:

  • It may be possible to place this under Zend_Crypt as it is somewhat related
  • Zend_Validate_Ccnum uses Luhn
  • Zend_Validate_Barcode uses Luhn and has some crossover with the barcode algorithms
  • May want to add Zend_Validate classes for each algorithm

4. Dependencies on Other Framework Components

  • Zend_Exception

5. Theory of Operation

In the fashion of existing Zend Framework components a class might be created for each algorithm. The base Zend_CheckDigit class might have static functions to return the class for a specific algorithm.

It might be useful to create an interface for each algorithm with the following methods:

  • generate($number) will return the check digit (int)
  • append($number) will return the original number with the check digit added to the end
  • isValid($number) will return a boolean, true if the check digit contained within $number is correct, false if it is not

It is assumed that the check digit will always be the last digit for isValid, unless the algorithm follows another structure. It would also be possible for append to return a formatted number for algorithms such as ISBN, although this might use a seperate format($number) method.

6. Milestones / Tasks

  • Milestone 1: Design notes...whatever they are
  • Milestone 2: Working prototype checked into the incubator supporting use cases
  • Milestone 3: Unit tests exist, work, and are checked into SVN.
  • Milestone 4: Initial documentation exists.

7. Class Index

  • Zend_CheckDigit (factory class)
  • Zend_CheckDigit_Exception (maybe used when a number is not properly formatted?)
  • Zend_CheckDigit_Luhn
  • Zend_CheckDigit_Verhoeff
  • Zend_CheckDigit_Code39
  • Zend_CheckDigit_Code128
  • Zend_CheckDigit_Isbn10
  • Zend_CheckDigit_Isbn13
  • Zend_CheckDigit_Ean13
  • Zend_CheckDigit_Upc

It may be possible to merge ISBN-10 and ISBN-13 however this may cause issues with length validation. Code128 might need to be split into A, B and C though it should be possible to keep it as one and use the first character to determine with character set is being used. It may be necessary to specify UPC as UPC-A since other formats do exist but are apparently mostly redundant.

Additional classes may be added depending on algorithms that are implemented, such as:

  • Zend_CheckDigit_Vin
  • Zend_CheckDigit_LuhnModN
  • Zend_CheckDigit_Ean8

8. Use Cases

Instantiate class:

Generate check digit:

Validate check digit:

9. Class Skeletons

]]></ac:plain-text-body></ac:macro>

]]></ac:plain-text-body></ac:macro>

Labels:
luhn luhn Delete
verhoeff verhoeff Delete
check check Delete
digit digit Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. May 13, 2008

    <p>Steven, is this proposal ready for community review? I noticed that the 'under construction' note is gone, but it is still in the 'new' section. Please update it as necessary.</p>

    <p>Thanks.<br />
    ,Wil</p>

  2. Jun 18, 2008

    <p>Is there any way to make this part of Zend_Validate?</p>

  3. Jun 20, 2008

    <p>What is the status of this proposal? Is it still active?</p>

    <p>,Wil</p>

    1. Jul 10, 2008

      <p>I no longer have a need for this functionality, unless there is a community need I don't think I would continue with it.</p>