cvs: pear /Validate Validate.php package.xml package_ISPN.xml /Validate/Validate ISPN.php /Validate/tests issn.php product_numbers.php

From: Date: Thu, 20 Jan 2005 15:18:33 +0000
Subject: cvs: pear /Validate Validate.php package.xml package_ISPN.xml /Validate/Validate ISPN.php /Validate/tests issn.php product_numbers.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-28700@lists.php.net to get a copy of this message
dufuz Thu Jan 20 10:18:33 2005 EDT Added files: /pear/Validate/Validate ISPN.php /pear/Validate package_ISPN.xml Modified files: /pear/Validate/tests issn.php product_numbers.php /pear/Validate package.xml Validate.php Log: - Splitted these functions over to a new sub package called Validate_ISPN (International Standard Product Numbers) * ISSN * ISBN * ISMN * EAN8 * EAN13 * EAN14 * UCC12 * SSCC

http://cvs.php.net/diff.php/pear/Validate/tests/issn.php?r1=1.1&r2=1.2&ty=u Index: pear/Validate/tests/issn.php diff -u pear/Validate/tests/issn.php:1.1 pear/Validate/tests/issn.php:1.2 --- pear/Validate/tests/issn.php:1.1 Mon Jan 17 21:20:52 2005 +++ pear/Validate/tests/issn.php Thu Jan 20 10:18:32 2005 @@ -1,6 +1,6 @@ <?php require_once 'PHPUnit.php'; -require 'Validate.php'; +require 'Validate/ISPN.php'; class Validate_ISSN_Test extends PHPUnit_TestCase { @@ -31,7 +31,7 @@ function testISSN() { foreach ($this->issn as $issn => $expected_result) { - $r = Validate::issn($issn); + $r = Validate_ISPN::issn($issn); $this->assertEquals($r, $expected_result); } } http://cvs.php.net/diff.php/pear/Validate/tests/product_numbers.php?r1=1.1&r2=1.2&ty=u Index: pear/Validate/tests/product_numbers.php diff -u pear/Validate/tests/product_numbers.php:1.1 pear/Validate/tests/product_numbers.php:1.2 --- pear/Validate/tests/product_numbers.php:1.1 Mon Jan 17 21:20:52 2005 +++ pear/Validate/tests/product_numbers.php Thu Jan 20 10:18:32 2005 @@ -1,6 +1,6 @@ <?php require_once 'PHPUnit.php'; -require 'Validate.php'; +require 'Validate/ISPN.php'; class Validate_Trade_Test extends PHPUnit_TestCase { @@ -37,7 +37,7 @@ function testUCC12() { foreach ($this->ucc12 as $ucc12 => $expected_result) { - $r = Validate::ucc12($ucc12); + $r = Validate_ISPN::ucc12($ucc12); $this->assertEquals($r, $expected_result); } } @@ -45,7 +45,7 @@ function testEAN8() { foreach ($this->ean8 as $ean8 => $expected_result) { - $r = Validate::ean8($ean8); + $r = Validate_ISPN::ean8($ean8); $this->assertEquals($r, $expected_result); } } @@ -53,7 +53,7 @@ function testEAN13() { foreach ($this->ean13 as $ean13 => $expected_result) { - $r = Validate::ean13($ean13); + $r = Validate_ISPN::ean13($ean13); $this->assertEquals($r, $expected_result); } } @@ -61,7 +61,7 @@ function testEAN14() { foreach ($this->ean14 as $ean14 => $expected_result) { - $r = Validate::ean14($ean14); + $r = Validate_ISPN::ean14($ean14); $this->assertEquals($r, $expected_result); } } @@ -69,7 +69,7 @@ function testSSCC() { foreach ($this->sscc as $sscc => $expected_result) { - $r = Validate::sscc($sscc); + $r = Validate_ISPN::sscc($sscc); $this->assertEquals($r, $expected_result); } } http://cvs.php.net/diff.php/pear/Validate/package.xml?r1=1.32&r2=1.33&ty=u Index: pear/Validate/package.xml diff -u pear/Validate/package.xml:1.32 pear/Validate/package.xml:1.33 --- pear/Validate/package.xml:1.32 Mon Jan 17 21:20:52 2005 +++ pear/Validate/package.xml Thu Jan 20 10:18:32 2005 @@ -54,7 +54,16 @@ - _check_control_number renamed to _checkControlNumber _get_control_number renamed to _getControlNumber _mult_weights renamed to _multWeights -- added email, issn and product_numbers tests +- added email test +- Splitted these functions over to a new sub package called Validate_ISPN (International Standard Product Numbers) + * ISSN + * ISBN + * ISMN + * EAN8 + * EAN13 + * EAN14 + * UCC12 + * SSCC </notes> <filelist> <dir name="/"> @@ -63,8 +72,6 @@ <file>number.php</file> <file>date.php</file> <file>email.php</file> - <file>product_numbers.php</file> - <file>issn.php</file> </dir> <dir name="docs" role="doc"> <file>sample_multiple.php</file> http://cvs.php.net/diff.php/pear/Validate/Validate.php?r1=1.54&r2=1.55&ty=u Index: pear/Validate/Validate.php diff -u pear/Validate/Validate.php:1.54 pear/Validate/Validate.php:1.55 --- pear/Validate/Validate.php:1.54 Mon Jan 17 21:19:12 2005 +++ pear/Validate/Validate.php Thu Jan 20 10:18:32 2005 @@ -17,7 +17,7 @@ // | Pierre-Alain Joye <paj@pearfr.org> | // +----------------------------------------------------------------------+ // -// $Id: Validate.php,v 1.54 2005/01/18 02:19:12 dufuz Exp $ +// $Id: Validate.php,v 1.55 2005/01/20 15:18:32 dufuz Exp $ // // Methods for common data validations // @@ -310,240 +310,6 @@ return true; } - /** - * Validate a ISBN number - * - * This function checks given number according - * - * @param string $isbn number (only numeric chars will be considered) - * @return bool true if number is valid, otherwise false - * @author Damien Seguy <dams@nexen.net> - */ - function isbn($isbn) - { - if (preg_match("/[^0-9 IXSBN-]/", $isbn)) { - return false; - } - - if (!ereg("^ISBN", $isbn)){ - return false; - } - - $isbn = ereg_replace('-', '', $isbn); - $isbn = ereg_replace(' ', '', $isbn); - $isbn = eregi_replace('ISBN', '', $isbn); - if (strlen($isbn) != 10) { - return false; - } - if (preg_match("/[^0-9]{9}[^0-9X]/", $isbn)){ - return false; - } - - $t = 0; - for ($i = 0; $i < strlen($isbn) - 1; $i++){ - $t += $isbn[$i]*(10-$i); - } - $f = $isbn[9]; - if ($f == 'X') { - $t += 10; - } else { - $t += $f; - } - if ($t % 11) { - return false; - } - return true; - } - - - /** - * Validate an ISSN (International Standard Serial Number) - * - * This function checks given ISSN number - * ISSN identifies periodical publications: - * http://www.issn.org - * - * @param string $issn number (only numeric chars will be considered) - * @return bool true if number is valid, otherwise false - * @author Piotr Klaban <makler@man.torun.pl> - */ - function issn($issn) - { - static $weights_issn = array(8,7,6,5,4,3,2); - - $issn = strtoupper($issn); - $issn = eregi_replace('ISSN', '', $issn); - $issn = str_replace(array('-', '/', ' ', "\t", "\n"), '', $issn); - $issn_num = eregi_replace('X', '0', $issn); - - // check if this is an 8-digit number - if (!is_numeric($issn_num) || strlen($issn) != 8) { - return false; - } - - return Validate::_checkControlNumber($issn, $weights_issn, 11, 11); - } - - /** - * Validate a ISMN (International Standard Music Number) - * - * This function checks given ISMN number (ISO Standard 10957) - * ISMN identifies all printed music publications from all over the world - * whether available for sale, hire or gratis--whether a part, a score, - * or an element in a multi-media kit: - * http://www.ismn-international.org/ - * - * @param string $ismn ISMN number - * @return bool true if number is valid, otherwise false - * @author Piotr Klaban <makler@man.torun.pl> - */ - function ismn($ismn) - { - static $weights_ismn = array(3,1,3,1,3,1,3,1,3); - - $ismn = eregi_replace('ISMN', '', $ismn); - $ismn = eregi_replace('M', '3', $ismn); // change first M to 3 - $ismn = str_replace(array('-', '/', ' ', "\t", "\n"), '', $ismn); - - // check if this is a 10-digit number - if (!is_numeric($ismn) || strlen($ismn) != 10) { - return false; - } - - return Validate::_checkControlNumber($ismn, $weights_ismn, 10, 10); - } - - - /** - * Validate a EAN/UCC-8 number - * - * This function checks given EAN8 number - * used to identify trade items and special applications. - * http://www.ean-ucc.org/ - * http://www.uc-council.org/checkdig.htm - * - * @param string $ean number (only numeric chars will be considered) - * @return bool true if number is valid, otherwise false - * @author Piotr Klaban <makler@man.torun.pl> - */ - function ean8($ean) - { - static $weights_ean8 = array(3,1,3,1,3,1,3); - - $ean = str_replace(array('-', '/', ' ', "\t", "\n"), '', $ean); - - // check if this is a 8-digit number - if (!is_numeric($ean) || strlen($ean) != 8) { - return false; - } - - return Validate::_checkControlNumber($ean, $weights_ean8, 10, 10); - } - - /** - * Validate a EAN/UCC-13 number - * - * This function checks given EAN/UCC-13 number used to identify - * trade items, locations, and special applications (e.g., coupons) - * http://www.ean-ucc.org/ - * http://www.uc-council.org/checkdig.htm - * - * @param string $ean number (only numeric chars will be considered) - * @return bool true if number is valid, otherwise false - * @author Piotr Klaban <makler@man.torun.pl> - */ - function ean13($ean) - { - static $weights_ean13 = array(1,3,1,3,1,3,1,3,1,3,1,3); - - $ean = str_replace(array('-', '/', ' ', "\t", "\n"), '', $ean); - - // check if this is a 13-digit number - if (!is_numeric($ean) || strlen($ean) != 13) { - return false; - } - - return Validate::_checkControlNumber($ean, $weights_ean13, 10, 10); - } - - /** - * Validate a EAN/UCC-14 number - * - * This function checks given EAN/UCC-14 number - * used to identify trade items. - * http://www.ean-ucc.org/ - * http://www.uc-council.org/checkdig.htm - * - * @param string $ean number (only numeric chars will be considered) - * @return bool true if number is valid, otherwise false - * @author Piotr Klaban <makler@man.torun.pl> - */ - function ean14($ean) - { - static $weights_ean14 = array(3,1,3,1,3,1,3,1,3,1,3,1,3); - - $ean = str_replace(array('-', '/', ' ', "\t", "\n"), '', $ean); - - // check if this is a 14-digit number - if (!is_numeric($ean) || strlen($ean) != 14) { - return false; - } - - return Validate::_checkControlNumber($ean, $weights_ean14, 10, 10); - } - - /** - * Validate a UCC-12 (U.P.C.) ID number - * - * This function checks given UCC-12 number used to identify - * trade items, locations, and special applications (e.g., * coupons) - * http://www.ean-ucc.org/ - * http://www.uc-council.org/checkdig.htm - * - * @param string $ucc number (only numeric chars will be considered) - * @return bool true if number is valid, otherwise false - * @author Piotr Klaban <makler@man.torun.pl> - */ - function ucc12($ucc) - { - static $weights_ucc12 = array(3,1,3,1,3,1,3,1,3,1,3); - - $ucc = str_replace(array('-', '/', ' ', "\t", "\n"), '', $ucc); - - // check if this is a 12-digit number - if (!is_numeric($ucc) || strlen($ucc) != 12) { - return false; - } - - return Validate::_checkControlNumber($ucc, $weights_ucc12, 10, 10); - } - - /** - * Validate a SSCC (Serial Shipping Container Code) - * - * This function checks given SSCC number - * used to identify logistic units. - * http://www.ean-ucc.org/ - * http://www.uc-council.org/checkdig.htm - * - * @param string $sscc number (only numeric chars will be considered) - * @return bool true if number is valid, otherwise false - * @author Piotr Klaban <makler@man.torun.pl> - */ - function sscc($sscc) - { - static $weights_sscc = array(3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3); - - $sscc = str_replace(array('-', '/', ' ', "\t", "\n"), '', $sscc); - - // check if this is a 18-digit number - if (!is_numeric($sscc) || strlen($sscc) != 18) { - return false; - } - - return Validate::_checkControlNumber($sscc, $weights_sscc, 10, 10); - } - function _substr(&$date, $num, $opt = false) { if ($opt && strlen($date) >= $opt && preg_match('/^[0-9]{'.$opt.'}/', $date, $m)) { http://cvs.php.net/co.php/pear/Validate/Validate/ISPN.php?r=1.1&p=1 Index: pear/Validate/Validate/ISPN.php +++ pear/Validate/Validate/ISPN.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2005 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 3.0 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available through the world-wide-web at the following url: | // | http://www.php.net/license/3_0.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Piotr Klaban <makler@man.torun.pl> | // | Damien Seguy <dams@nexen.net> | // +----------------------------------------------------------------------+ // // $Id: ISPN.php,v 1.1 2005/01/20 15:18:32 dufuz Exp $ /** * ISPN is also known as International Standard Product Numbers */ require_once 'Validate.php'; class Validate_ISPN { /** * Validate a ISBN number * The ISBN is a unique machine-readable identification number, * which marks any book unmistakably. * * This function checks given number according * * @param string $isbn number (only numeric chars will be considered) * @return bool true if number is valid, otherwise false * @author Damien Seguy <dams@nexen.net> */ function isbn($isbn) { if (preg_match("/[^0-9 IXSBN-]/", $isbn)) { return false; } if (!ereg("^ISBN", $isbn)){ return false; } $isbn = ereg_replace('-', '', $isbn); $isbn = ereg_replace(' ', '', $isbn); $isbn = eregi_replace('ISBN', '', $isbn); if (strlen($isbn) != 10) { return false; } if (preg_match("/[^0-9]{9}[^0-9X]/", $isbn)){ return false; } $t = 0; for ($i = 0; $i < strlen($isbn) - 1; $i++){ $t += $isbn[$i]*(10-$i); } $f = $isbn[9]; if ($f == 'X') { $t += 10; } else { $t += $f; } if ($t % 11) { return false; } return true; } /** * Validate an ISSN (International Standard Serial Number) * * This function checks given ISSN number * ISSN identifies periodical publications: * http://www.issn.org * * @param string $issn number (only numeric chars will be considered) * @return bool true if number is valid, otherwise false * @author Piotr Klaban <makler@man.torun.pl> */ function issn($issn) { static $weights_issn = array(8,7,6,5,4,3,2); $issn = strtoupper($issn); $issn = eregi_replace('ISSN', '', $issn); $issn = str_replace(array('-', '/', ' ', "\t", "\n"), '', $issn); $issn_num = eregi_replace('X', '0', $issn); // check if this is an 8-digit number if (!is_numeric($issn_num) || strlen($issn) != 8) { return false; } return Validate::_checkControlNumber($issn, $weights_issn, 11, 11); } /** * Validate a ISMN (International Standard Music Number) * * This function checks given ISMN number (ISO Standard 10957) * ISMN identifies all printed music publications from all over the world * whether available for sale, hire or gratis--whether a part, a score, * or an element in a multi-media kit: * http://www.ismn-international.org/ * * @param string $ismn ISMN number * @return bool true if number is valid, otherwise false * @author Piotr Klaban <makler@man.torun.pl> */ function ismn($ismn) { static $weights_ismn = array(3,1,3,1,3,1,3,1,3); $ismn = eregi_replace('ISMN', '', $ismn); $ismn = eregi_replace('M', '3', $ismn); // change first M to 3 $ismn = str_replace(array('-', '/', ' ', "\t", "\n"), '', $ismn); // check if this is a 10-digit number if (!is_numeric($ismn) || strlen($ismn) != 10) { return false; } return Validate::_checkControlNumber($ismn, $weights_ismn, 10, 10); } /** * Validate a EAN/UCC-8 number * * This function checks given EAN8 number * used to identify trade items and special applications. * http://www.ean-ucc.org/ * http://www.uc-council.org/checkdig.htm * * @param string $ean number (only numeric chars will be considered) * @return bool true if number is valid, otherwise false * @author Piotr Klaban <makler@man.torun.pl> */ function ean8($ean) { static $weights_ean8 = array(3,1,3,1,3,1,3); $ean = str_replace(array('-', '/', ' ', "\t", "\n"), '', $ean); // check if this is a 8-digit number if (!is_numeric($ean) || strlen($ean) != 8) { return false; } return Validate::_checkControlNumber($ean, $weights_ean8, 10, 10); } /** * Validate a EAN/UCC-13 number * * This function checks given EAN/UCC-13 number used to identify * trade items, locations, and special applications (e.g., coupons) * http://www.ean-ucc.org/ * http://www.uc-council.org/checkdig.htm * * @param string $ean number (only numeric chars will be considered) * @return bool true if number is valid, otherwise false * @author Piotr Klaban <makler@man.torun.pl> */ function ean13($ean) { static $weights_ean13 = array(1,3,1,3,1,3,1,3,1,3,1,3); $ean = str_replace(array('-', '/', ' ', "\t", "\n"), '', $ean); // check if this is a 13-digit number if (!is_numeric($ean) || strlen($ean) != 13) { return false; } return Validate::_checkControlNumber($ean, $weights_ean13, 10, 10); } /** * Validate a EAN/UCC-14 number * * This function checks given EAN/UCC-14 number * used to identify trade items. * http://www.ean-ucc.org/ * http://www.uc-council.org/checkdig.htm * * @param string $ean number (only numeric chars will be considered) * @return bool true if number is valid, otherwise false * @author Piotr Klaban <makler@man.torun.pl> */ function ean14($ean) { static $weights_ean14 = array(3,1,3,1,3,1,3,1,3,1,3,1,3); $ean = str_replace(array('-', '/', ' ', "\t", "\n"), '', $ean); // check if this is a 14-digit number if (!is_numeric($ean) || strlen($ean) != 14) { return false; } return Validate::_checkControlNumber($ean, $weights_ean14, 10, 10); } /** * Validate a UCC-12 (U.P.C.) ID number * * This function checks given UCC-12 number used to identify * trade items, locations, and special applications (e.g., * coupons) * http://www.ean-ucc.org/ * http://www.uc-council.org/checkdig.htm * * @param string $ucc number (only numeric chars will be considered) * @return bool true if number is valid, otherwise false * @author Piotr Klaban <makler@man.torun.pl> */ function ucc12($ucc) { static $weights_ucc12 = array(3,1,3,1,3,1,3,1,3,1,3); $ucc = str_replace(array('-', '/', ' ', "\t", "\n"), '', $ucc); // check if this is a 12-digit number if (!is_numeric($ucc) || strlen($ucc) != 12) { return false; } return Validate::_checkControlNumber($ucc, $weights_ucc12, 10, 10); } /** * Validate a SSCC (Serial Shipping Container Code) * * This function checks given SSCC number * used to identify logistic units. * http://www.ean-ucc.org/ * http://www.uc-council.org/checkdig.htm * * @param string $sscc number (only numeric chars will be considered) * @return bool true if number is valid, otherwise false * @author Piotr Klaban <makler@man.torun.pl> */ function sscc($sscc) { static $weights_sscc = array(3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3); $sscc = str_replace(array('-', '/', ' ', "\t", "\n"), '', $sscc); // check if this is a 18-digit number if (!is_numeric($sscc) || strlen($sscc) != 18) { return false; } return Validate::_checkControlNumber($sscc, $weights_sscc, 10, 10); } } ?> http://cvs.php.net/co.php/pear/Validate/package_ISPN.xml?r=1.1&p=1 Index: pear/Validate/package_ISPN.xml +++ pear/Validate/package_ISPN.xml <?xml version="1.0" encoding="ISO-8859-1" ?> <package version="1.0"> <name>Validate_ISPAN</name> <summary>Validation class for ISPAN (International Standard Product Numbers)</summary> <description> Package containes ISPAN (International Standard Product Numbers) validations such as: * ISSN * ISBN * ISMN * EAN8 * EAN13 * EAN14 * UCC12 * SSCC </description> <license>PHP</license> <maintainers> <maintainer> <user>dufuz</user> <role>lead</role> <name>Helgi Þormar</name> <email>dufuz@php.net</email> </maintainer> </maintainers> <release> <version>0.5</version> <state>alpha</state> <date>2004-03-17</date> <notes> - Split from Validate into independent package - CS fixes - Added issn and product_numbers tests </notes> <filelist> <dir name="/"> <dir name="Validate"> <file role="php">ISPN.php</file> </dir> <dir name="tests" role="test"> <file>product_numbers.php</file> <file>issn.php</file> </dir> </dir> </filelist> <deps> <dep type="php" rel="ge" version="4.1.0" /> </deps> </release> <changelog> </changelog> </package>
« previous php.pear.cvs (#28700) next »