Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

hotfix custom barcode adapter wasn't being set to options. #6576

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions library/Zend/Validator/Barcode.php
Expand Up @@ -91,15 +91,17 @@ public function setAdapter($adapter, $options = null)
throw new Exception\InvalidArgumentException('Barcode adapter matching "' . $adapter . '" not found');
}

$this->options['adapter'] = new $adapter($options);
$adapter = new $adapter($options);
}

if (!$this->options['adapter'] instanceof Barcode\AdapterInterface) {
if (!$adapter instanceof Barcode\AdapterInterface) {
throw new Exception\InvalidArgumentException(
"Adapter $adapter does not implement Zend\\Validate\\Barcode\\AdapterInterface"
sprintf("Adapter %s does not implement Zend\\Validator\\Barcode\\AdapterInterface", get_class($adapter))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be checking if $adapter is an object before calling get_class. The common pattern we use is:

(is_object($adapter) ? get_class($adapter) : gettype($adapter)

);
}

$this->options['adapter'] = $adapter;

return $this;
}

Expand Down
9 changes: 9 additions & 0 deletions tests/ZendTest/Validator/BarcodeTest.php
Expand Up @@ -32,6 +32,15 @@ public function testSetAdapter()
$barcode->setAdapter('ean13');
$this->assertTrue($barcode->isValid('0075678164125'));
}

public function testSetCustomAdapter()
{
$barcode = new Barcode([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use short array syntax as we still support 5.3. I'll fix this on merge, though.

'adapter' => $this->getMock('Zend\Validator\Barcode\AdapterInterface')
]);

$this->assertInstanceOf('Zend\Validator\Barcode\AdapterInterface', $barcode->getAdapter());
}

/**
* @ZF-4352
Expand Down