Hi all,

Unless I'm doing something wrong, I think I found a bug in the setAdapter()
method of Zend_Validate_Barcode.

Following the documentation, I defined a custom barcode validation adapter:

class My_Barcode_MyBar extends Zend_Validate_Barcode_AdapterAbstract
> {
>     protected $_length     = 'even';
>     protected $_characters = '0123456789ABCDE';
>     protected $_checksum   = '_mod66';
>
>     protected function _mod66($barcode)
>     {
>         // do some validations and return a boolean
>     }
> }


But when I try to use it like so:

$valid = new Zend_Validate_Barcode('My_Barcode_MyBar');
> if ($valid->isValid($input)) {
>     // input appears to be valid
> } else {
>     // input is invalid
> }


Zend_Loader throws an exception  with the following message:

File "My/barcode/mybar.php" does not exist or class "My_barcode_mybar" was
> not found in the file


The problem comes from the line 134 in Zend_Validate_Barcode:

$adapter = ucfirst(strtolower($adapter));


This is working for loading the adapters provided with the Zend Framework
but cause a failure when trying to load custom adapters.

Here's a possible fix:

$zfAdapter = ucfirst(strtolower($adapter));
> require_once 'Zend/Loader.php';
> if (Zend_Loader::isReadable('Zend/Validate/Barcode/' . $zfAdapter. '.php'))
> {
>     $adapter = 'Zend_Validate_Barcode_' . $zfAdapter;
> }


Let me know if I should open an issue on the tracker or if I missed
something.


Martin Carpentier

Reply via email to