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

Commit

Permalink
s/Locater/Locator/gs
Browse files Browse the repository at this point in the history
- Fixed all instances where class/interface names used "Locater" to "Locator",
  and attempted to ensure tests would run when possible (in some cases, tests
  were failing before)
  • Loading branch information
weierophinney committed Apr 14, 2011
7 parents 369a5ce + 2f4d803 + 045137d + 2fdcee4 + 147c99e + d95685a + 9fceeb6 commit a62b890
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
24 changes: 18 additions & 6 deletions src/Barcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* @namespace
*/
namespace Zend\Barcode;
use Zend\Loader\PluginLoader,
Zend\Loader\ShortNameLocater,
use Zend\Loader\PrefixPathLoader,
Zend\Loader\ShortNameLocator,
Zend\Config\Config,
Zend,
Zend\Barcode\Exception\RendererCreationException,
Expand Down Expand Up @@ -64,12 +64,12 @@ class Barcode
/**
* Set plugin loader to use for validator or filter chain
*
* @param \Zend\Loader\ShortNameLocater $loader
* @param \Zend\Loader\ShortNameLocator $loader
* @param string $type 'object', or 'renderer'
* @return \Zend\Form\Element
* @throws \Zend\Form\Exception on invalid type
*/
public static function setPluginLoader(ShortNameLocater $loader, $type)
public static function setPluginLoader(ShortNameLocator $loader, $type)
{
$type = strtoupper($type);
switch ($type) {
Expand All @@ -89,7 +89,7 @@ public static function setPluginLoader(ShortNameLocater $loader, $type)
* 'decorator', 'filter', or 'validate' for $type.
*
* @param string $type
* @return \Zend\Loader\ShortNameLocater
* @return \Zend\Loader\ShortNameLocator
* @throws \Zend\Loader\Exception on invalid type.
*/
public static function getPluginLoader($type)
Expand All @@ -101,7 +101,7 @@ public static function getPluginLoader($type)
$prefixSegment = ucfirst(strtolower($type));
$pathSegment = $prefixSegment;
if (!isset(self::$_loaders[$type])) {
self::$_loaders[$type] = new PluginLoader(
self::$_loaders[$type] = new PrefixPathLoader(
array('Zend\\Barcode\\' . $prefixSegment . '\\' => 'Zend/Barcode/' . $pathSegment . '/')
);
}
Expand Down Expand Up @@ -230,6 +230,12 @@ public static function makeBarcode($barcode, $barcodeConfig = array())

$barcodeName = self::getPluginLoader(self::OBJECT)->load($barcode);

if (!class_exists($barcodeName)) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid Barcode "%s"; does not resolve to a valid class', $barcode
));
}

/*
* Create an instance of the barcode class.
* Pass the config to the barcode class constructor.
Expand Down Expand Up @@ -296,6 +302,12 @@ public static function makeRenderer($renderer = 'image', $rendererConfig = array

$rendererName = self::getPluginLoader(self::RENDERER)->load($renderer);

if (!class_exists($rendererName)) {
throw new Exception\InvalidArgumentException(sprintf(
'Invalid renderer "%s"; does not resolve to a valid class', $renderer
));
}

/*
* Create an instance of the barcode class.
* Pass the config to the barcode class constructor.
Expand Down
20 changes: 10 additions & 10 deletions test/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
Zend\Barcode\Renderer,
Zend\Barcode\Object,
Zend\Config\Config,
Zend\Loader\PluginLoader,
Zend\Loader\PrefixPathLoader,
Zend\Pdf;

/**
Expand All @@ -49,9 +49,9 @@ public function setUp()

public function tearDown()
{
$loader = new PluginLoader(array('Zend\Barcode\Object' => 'Zend/Barcode/Object'));
$loader = new PrefixPathLoader(array('Zend\Barcode\Object' => 'Zend/Barcode/Object'));
Barcode\Barcode::setPluginLoader($loader, Barcode\Barcode::OBJECT);
$loader = new PluginLoader(array('Zend\Barcode\Renderer' => 'Zend/Barcode/Renderer'));
$loader = new PrefixPathLoader(array('Zend\Barcode\Renderer' => 'Zend/Barcode/Renderer'));
Barcode\Barcode::setPluginLoader($loader, Barcode\Barcode::RENDERER);
}

Expand Down Expand Up @@ -216,15 +216,15 @@ public function testBarcodeObjectFactoryWithBarcodeAsZendConfigAndBadBarcodePara

public function testBarcodeObjectFactoryWithNamespace()
{
$loader = new PluginLoader(array('ZendTest\Barcode\Object\TestAsset' => __DIR__ . '/Object/TestAsset'));
$loader = new PrefixPathLoader(array('ZendTest\Barcode\Object\TestAsset' => __DIR__ . '/Object/TestAsset'));
Barcode\Barcode::setPluginLoader($loader, Barcode\Barcode::OBJECT);
$barcode = Barcode\Barcode::makeBarcode('barcodeNamespace');
$this->assertTrue($barcode instanceof \ZendTest\Barcode\Object\TestAsset\BarcodeNamespace);
}

public function testBarcodeObjectFactoryWithNamespaceExtendStandardLibray()
{
$loader = new PluginLoader(array('Zend\Barcode\Object' => 'Zend/Barcode/Object',
$loader = new PrefixPathLoader(array('Zend\Barcode\Object' => 'Zend/Barcode/Object',
'ZendTest\Barcode\Object\TestAsset' => __DIR__ . '/Object/TestAsset'));
Barcode\Barcode::setPluginLoader($loader, Barcode\Barcode::OBJECT);
$barcode = Barcode\Barcode::makeBarcode('error');
Expand All @@ -234,14 +234,14 @@ public function testBarcodeObjectFactoryWithNamespaceExtendStandardLibray()
public function testBarcodeObjectFactoryWithNamespaceButWithoutExtendingObjectAbstract()
{
$this->setExpectedException('\Zend\Barcode\Exception');
$loader = new PluginLoader(array('ZendTest\Barcode\Object\TestAsset' => __DIR__ . '/Object/TestAsset'));
$loader = new PrefixPathLoader(array('ZendTest\Barcode\Object\TestAsset' => __DIR__ . '/Object/TestAsset'));
Barcode\Barcode::setPluginLoader($loader, Barcode\Barcode::OBJECT);
$barcode = Barcode\Barcode::makeBarcode('barcodeNamespaceWithoutExtendingObjectAbstract');
}

public function testBarcodeObjectFactoryWithUnexistantBarcode()
{
$this->setExpectedException('\Zend\Loader\PluginLoaderException');
$this->setExpectedException('\Zend\Barcode\Exception\InvalidArgumentException');
$barcode = Barcode\Barcode::makeBarcode('zf123', array());
}

Expand Down Expand Up @@ -304,7 +304,7 @@ public function testBarcodeRendererFactoryWithBarcodeAsZendConfigAndBadBarcodePa
public function testBarcodeRendererFactoryWithNamespace()
{
$this->_checkGDRequirement();
$loader = new PluginLoader(array('ZendTest\Barcode\Renderer\TestAsset' => __DIR__ . '/Renderer/TestAsset'));
$loader = new PrefixPathLoader(array('ZendTest\Barcode\Renderer\TestAsset' => __DIR__ . '/Renderer/TestAsset'));
Barcode\Barcode::setPluginLoader($loader, Barcode\Barcode::RENDERER);
$renderer = Barcode\Barcode::makeRenderer('rendererNamespace');
$this->assertTrue($renderer instanceof \Zend\Barcode\BarcodeRenderer);
Expand All @@ -313,14 +313,14 @@ public function testBarcodeRendererFactoryWithNamespace()
public function testBarcodeFactoryWithNamespaceButWithoutExtendingRendererAbstract()
{
$this->setExpectedException('\Zend\Barcode\Exception');
$loader = new PluginLoader(array('ZendTest\Barcode\Renderer\TestAsset' => __DIR__ . '/Renderer/TestAsset'));
$loader = new PrefixPathLoader(array('ZendTest\Barcode\Renderer\TestAsset' => __DIR__ . '/Renderer/TestAsset'));
Barcode\Barcode::setPluginLoader($loader, Barcode\Barcode::RENDERER);
$renderer = Barcode\Barcode::makeRenderer('rendererNamespaceWithoutExtendingRendererAbstract');
}

public function testBarcodeRendererFactoryWithUnexistantRenderer()
{
$this->setExpectedException('\Zend\Loader\PluginLoaderException');
$this->setExpectedException('\Zend\Loader\Exception\PluginLoaderException');
$renderer = Barcode\Barcode::makeRenderer('zend', array());
}

Expand Down

0 comments on commit a62b890

Please sign in to comment.