本文整理汇总了PHP中Zend_Validate_Barcode类的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Validate_Barcode类的具体用法?PHP Zend_Validate_Barcode怎么用?PHP Zend_Validate_Barcode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zend_Validate_Barcode类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSetType
public function testSetType()
{
$barcode = new Zend_Validate_Barcode('upc-a');
$this->assertTrue($barcode->isValid('065100004327'));
$barcode->setType('ean-13');
$this->assertTrue($barcode->isValid('0075678164125'));
}
示例2: isWorldWideId
private function isWorldWideId($worldWideId, $type)
{
$adapters = array('UPC' => array('8' => 'Upce', '12' => 'Upca'), 'EAN' => array('8' => 'Ean8', '13' => 'Ean13'));
$length = strlen($worldWideId);
if (!isset($adapters[$type], $adapters[$type][$length])) {
return false;
}
try {
$validator = new Zend_Validate_Barcode($adapters[$type][$length]);
return $validator->isValid($worldWideId);
} catch (Zend_Validate_Exception $e) {
return true;
}
}
示例3: testUPCE
public function testUPCE()
{
$barcode = new Zend_Validate_Barcode('upce');
$this->assertTrue($barcode->isValid('02345673'));
$this->assertFalse($barcode->isValid('02345672'));
$this->assertFalse($barcode->isValid('123'));
$this->assertTrue($barcode->isValid('123456'));
$this->assertTrue($barcode->isValid('0234567'));
}
示例4: _validateText
/**
* Particular validation for Upce barcode objects
* (to suppress checksum character substitution)
*
* @param string $value
* @param array $options
* @throws Zend_Barcode_Object_Exception
*/
protected function _validateText($value, $options = array())
{
$validator = new Zend_Validate_Barcode(array('adapter' => 'upce', 'checksum' => false));
$value = $this->_addLeadingZeros($value, true);
if (!$validator->isValid($value)) {
$message = implode("\n", $validator->getMessages());
/**
* @see Zend_Barcode_Object_Exception
*/
throw new Zend_Barcode_Object_Exception($message);
}
}
示例5: _validateText
/**
* Standard validation for most of barcode objects
* @param string $value
* @param array $options
*/
protected function _validateText($value, $options = array())
{
$validatorName = isset($options['validator']) ? $options['validator'] : $this->getType();
$validator = new Zend_Validate_Barcode(array('adapter' => $validatorName, 'checksum' => false));
$checksumCharacter = '';
$withChecksum = false;
if ($this->_mandatoryChecksum) {
$checksumCharacter = $this->_substituteChecksumCharacter;
$withChecksum = true;
}
$value = $this->_addLeadingZeros($value, $withChecksum) . $checksumCharacter;
if (!$validator->isValid($value)) {
$message = implode("\n", $validator->getMessages());
/**
* @see Zend_Barcode_Object_Exception
*/
require_once 'Zend/Barcode/Object/Exception.php';
throw new Zend_Barcode_Object_Exception($message);
}
}
示例6: testArrayLengthMessage
/**
* @group ZF-10116
*/
public function testArrayLengthMessage()
{
$barcode = new Zend_Validate_Barcode('ean8');
$this->assertFalse($barcode->isValid('123'));
$message = $barcode->getMessages();
$this->assertTrue(array_key_exists('barcodeInvalidLength', $message));
$this->assertContains("length of 7/8 characters", $message['barcodeInvalidLength']);
}
示例7: _validateText
/**
* Particular validation for Ean8 barcode objects
* (to suppress checksum character substitution)
* @param string $value
* @param array $options
*/
protected function _validateText($value, $options = array())
{
$validator = new Zend_Validate_Barcode(array('adapter' => 'ean8', 'checksum' => false));
$value = $this->_addLeadingZeros($value, true);
if (!$validator->isValid($value)) {
$message = implode("\n", $validator->getMessages());
/**
* @see Zend_Barcode_Object_Exception
*/
require_once PHP_LIBRARY_PATH . 'Zend/Barcode/Object/Exception.php';
throw new Zend_Barcode_Object_Exception($message);
}
}