View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFPROP:Proposal Zone Template}

{zone-data:component-name}
Zend_Validate_Isbn
{zone-data}

{zone-data:proposer-list}
[Renan de Lima|mailto:renandelima@gmail.com]
{zone-data}

{zone-data:liaison}
TBD
{zone-data}

{zone-data:revision}
0.1 - 4 May 2009: Initial Release.
0.2 - 26 July 2009: Implementation, tests and documentation.
{zone-data}

{zone-data:overview}
Zend_Validate_Isbn is a component to check both ISBN-10 and ISBN-13 barcode formats.
{zone-data}

{zone-data:references}
* [ISBN Wikipedia Entry|http://en.wikipedia.org/wiki/International_Standard_Book_Number]
{zone-data}

{zone-data:requirements}
* this will validate IBSN entries
{zone-data}

{zone-data:dependencies}
* Zend_Validate
{zone-data}

{zone-data:operation}
This component classes implements Zend_Validate_Abstract, so it looks like others Zend_Validate classes.
{zone-data}

{zone-data:milestones}
* Milestone 1: \[DONE\] proposal finished
* Milestone 2: \[DONE\] proposal accepted
* Milestone 3: \[DONE\] implementation, tests and documentation
* Milestone 4: \[DONE\] moved to core
{zone-data}

{zone-data:class-list}
* Zend_Validate_Isbn
{zone-data}

{zone-data:use-cases}
{composition-setup}
{deck:id=Usecases}

{card:label=UC-01 basic}
{code}
<?php

//
// BASIC
require_once 'Zend/Validate/Isbn.php';

$validator = new Zend_Validate_Isbn();

$validator->isValid('158715336X'); // true
$validator->isValid('9780765319340'); // true
{code}
{card}

{card:label=UC-02 ISBN-10}
{code}
<?php

//
// ISBN-10
require_once 'Zend/Validate/Isbn.php';

$validator = new Zend_Validate_Isbn();
$validator->setType(Zend_Validate_Isbn::ISBN10);
// or
$options = array('type' => Zend_Validate_Isbn::ISBN10);
$validator = new Zend_Validate_Isbn($options);

$validator->isValid('158715336X'); // true
$validator->isValid('9780765319340'); // false
{code}
{card}


{card:label=UC-03 ISBN-13}
{code}
<?php

//
// ISBN-13
require_once 'Zend/Validate/Isbn.php';

$validator = new Zend_Validate_Isbn();
$validator->setType(Zend_Validate_Isbn::ISBN13);
// or
$options = array('type' => Zend_Validate_Isbn::ISBN13);
$validator = new Zend_Validate_Isbn($options);

$validator->isValid('158715336X'); // false
$validator->isValid('9780765319340'); // true
{code}
{card}


{card:label=UC-04 separator}
{code}
<?php

//
// SEPARATOR
require_once 'Zend/Validate/Isbn.php';

$validator = new Zend_Validate_Isbn();
$validator->setSeparator('-');
// or
$options = array('separator' => '-');
$validator = new Zend_Validate_Isbn($options);

$validator->isValid('1 587 15336 X'); // false
$validator->isValid('1-587-15336-X'); // true
$validator->isValid('1-587 15336-X'); // false
$validator->isValid('158715336X'); // false
{code}
{card}

{deck}
{zone-data}

{zone-data:skeletons}
{composition-setup}
{deck:id=Skeleton}

{card:label=Zend_Validate_Isbn}
{code}<?php

/**
* @see Zend_Validate_Abstract
*/
require_once 'Zend/Validate/Abstract.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_Isbn extends Zend_Validate_Abstract
{
const AUTO = 'auto';
const ISBN10 = '10';
const ISBN13 = '13';
const INVALID = 'isbnInvalid';

/**
* Validation failure message template definitions
*
* @var array
*/
protected $_messageTemplates = array(
self::INVALID => "'%value%' is an invalid ISBN",
);

/**
* Allowed type
*
* @var string
*/
protected $_type = self::AUTO;

/**
* Separator character
*
* @var string
*/
protected $_separator = '';

/**
* Set up options.
*
* @param array $options
* @return void
* @throws Zend_Validate_Exception
*/
public function __construct(array $options = array());

/**
* Detect input format.
*
* @return string
*/
protected function _detectFormat();

/**
* Defined by Zend_Validate_Interface.
*
* Returns true if and only if $value contains a valid ISBN
*
* @param string $value
* @return boolean
*/
public function isValid($value);

/**
* Set separator characters.
*
* It is allowed only empty string, hyphen and space.
*
* @param string $separator
* @return Zend_Validate_Isbn Provides a fluent interface
* @throws Zend_Validate_Exception
*/
public function setSeparator($separator);

/**
* Get separator characters.
*
* @return string
*/
public function getSeparator();

/**
* Set allowed ISBN type.
*
* @param string $type
* @return Zend_Validate_Isbn Provides a fluent interface
* @throws Zend_Validate_Exception
*/
public function setType($type);

/**
* Get allowed ISBN type.
*
* @return string
*/
public function getType();
}
{code}
{card}

{deck}
{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>