Permalink
Browse files

Merge pull request #12 from Gemorroj/master

PostNet, and PHPCS fixes
  • Loading branch information...
CloCkWeRX committed Mar 5, 2012
2 parents 0e274b4 + 127a2bd commit 13b1e0ea57c6eb2cbc7417ef0fdbe51bda9d0a1a
View
@@ -100,11 +100,11 @@ public static function draw($text,
throw new Image_Barcode2_Exception('Invalid barcode type ' . $type);
}
- if (!include_once 'Image/Barcode2/' . $type . '.php') {
+ if (!include_once 'Image/Barcode2/' . ucfirst($type) . '.php') {
throw new Image_Barcode2_Exception($type . ' barcode is not supported');
}
- $classname = 'Image_Barcode2_' . $type;
+ $classname = 'Image_Barcode2_' . ucfirst($type);
$obj = new $classname(new Image_Barcode2_Writer());
@@ -2,7 +2,7 @@
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
/**
- * Image_Barcode2_code128 class
+ * Image_Barcode2_Code128 class
*
* Renders Code128 barcodes
* Code128 is a high density encoding for alphanumeric strings.
@@ -57,7 +57,7 @@
* @link http://pear.php.net/package/Image_Barcode2
*/
-class Image_Barcode2_code128 extends Image_Barcode2_Common implements Image_Barcode2_Driver
+class Image_Barcode2_Code128 extends Image_Barcode2_Common implements Image_Barcode2_Driver
{
var $_code = array();
View
@@ -43,7 +43,7 @@
* @link http://pear.php.net/package/Image_Barcode2
* @since Image_Barcode2 0.5
*/
-class Image_Barcode2_code39 extends Image_Barcode2_Common implements Image_Barcode2_Driver, Image_Barcode2_DualWidth
+class Image_Barcode2_Code39 extends Image_Barcode2_Common implements Image_Barcode2_Driver, Image_Barcode2_DualWidth
{
/**
* Coding map
@@ -127,9 +127,9 @@ public function validate()
/**
* Make an image resource using the GD image library
*
- * @return resource The Barcode Image (TM)
+ * @return resource The Barcode Image (TM)
*
- * @author Ryan Briones <ryanbriones@webxdesign.org>
+ * @author Ryan Briones <ryanbriones@webxdesign.org>
*/
public function draw()
{
@@ -207,11 +207,9 @@ public function draw()
*
* @param string $code Code39 barcode code
*
- * @return string $result barcode line code
- * @access private
- * @author Ryan Briones <ryanbriones@webxdesign.org>
- *
- *
+ * @return string $result barcode line code
+ * @access private
+ * @author Ryan Briones <ryanbriones@webxdesign.org>
*/
private function _dumpCode($code)
{
View
@@ -1,5 +1,5 @@
<?php
-class Image_Barcode2_Common
+class Image_Barcode2_Common
{
protected $_barcodeheight;
protected $_barcodewidth;
@@ -37,20 +37,32 @@ public function setWriter(Image_Barcode2_Writer $writer)
{
$this->_writer = $writer;
}
-
+
+ /**
+ * Get the image rendering library.
+ *
+ * @return Image_Barcode2_Writer
+ */
public function getWriter()
{
return $this->_writer;
}
/**
+ * Set the barcode
+ *
* @param string $barcode
*/
public function setBarcode($barcode)
{
$this->_barcode = trim($barcode);
}
+ /**
+ * Get the barcode
+ *
+ * @return string
+ */
public function getBarcode()
{
return $this->_barcode;
@@ -1,5 +1,5 @@
<?php
-interface Image_Barcode2_Driver
+interface Image_Barcode2_Driver
{
/**
* Draws a barcode
@@ -18,7 +18,7 @@ public function setWriter(Image_Barcode2_Writer $writer);
/**
* Set barcode
*
- * @param string $barcode
+ * @param string $barcode barcode
*/
public function setBarcode($barcode);
@@ -2,7 +2,7 @@
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
/**
- * Image_Barcode2_ean13 class
+ * Image_Barcode2_Ean13 class
*
* Renders EAN 13 barcodes
*
@@ -41,7 +41,7 @@
* @link http://pear.php.net/package/Image_Barcode
* @since Image_Barcode2 0.4
*/
-class Image_Barcode2_ean13 extends Image_Barcode2_Common implements Image_Barcode2_Driver
+class Image_Barcode2_Ean13 extends Image_Barcode2_Common implements Image_Barcode2_Driver
{
/**
* Number set
@@ -2,7 +2,7 @@
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
/**
- * Image_Barcode2_ean8 class
+ * Image_Barcode2_Ean8 class
*
* Renders EAN 8 barcodes
*
@@ -42,7 +42,7 @@
* @version Release: @package_version@
* @link http://pear.php.net/package/Image_Barcode2
*/
-class Image_Barcode2_ean8 extends Image_Barcode2_Common implements Image_Barcode2_Driver
+class Image_Barcode2_Ean8 extends Image_Barcode2_Common implements Image_Barcode2_Driver
{
/**
* Number set
@@ -2,7 +2,7 @@
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
/**
- * Image_Barcode2_int25 class
+ * Image_Barcode2_Int25 class
*
* Renders Interleaved 2 of 5 barcodes
*
@@ -42,7 +42,7 @@
* @version Release: @package_version@
* @link http://pear.php.net/package/Image_Barcode2
*/
-class Image_Barcode2_int25 extends Image_Barcode2_Common implements Image_Barcode2_Driver, Image_Barcode2_DualWidth
+class Image_Barcode2_Int25 extends Image_Barcode2_Common implements Image_Barcode2_Driver, Image_Barcode2_DualWidth
{
/**
* Coding map
@@ -2,7 +2,7 @@
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
/**
- * Image_Barcode2_postnet class
+ * Image_Barcode2_Postnet class
*
* Renders PostNet barcodes
*
@@ -38,10 +38,11 @@
require_once 'Image/Barcode2/Driver.php';
require_once 'Image/Barcode2/Common.php';
+require_once 'Image/Barcode2/DualHeight.php';
require_once 'Image/Barcode2/Exception.php';
/**
- * Image_Barcode2_postnet class
+ * Image_Barcode2_Postnet class
*
* Package which provides a method to create PostNet barcode using GD library.
*
@@ -53,7 +54,7 @@
* @version Release: @package_version@
* @link http://pear.php.net/package/Image_Barcode2
*/
-class Image_Barcode2_postnet extends Image_Barcode2_Common implements Image_Barcode2_Driver, Image_Barcode2_DualHeight
+class Image_Barcode2_Postnet extends Image_Barcode2_Common implements Image_Barcode2_Driver, Image_Barcode2_DualHeight
{
/**
* Bar short height
@@ -106,7 +107,7 @@ public function __construct(Image_Barcode2_Writer $writer)
public function validate()
{
// Check barcode for invalid characters
- if (!preg_match('/[0-9]/', $this->getBarcode())) {
+ if (!preg_match('/^[0-9]+$/', $this->getBarcode())) {
throw new Image_Barcode2_Exception('Invalid barcode');
}
}
@@ -2,7 +2,7 @@
/* vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
/**
- * Image_Barcode2_upca class
+ * Image_Barcode2_Upca class
*
* Renders UPC-A barcodes
*
@@ -29,11 +29,11 @@
require_once 'Image/Barcode2/Exception.php';
/**
- * Image_Barcode2_upca class
+ * Image_Barcode2_Upca class
*
* Package which provides a method to create UPC-A barcode using GD library.
*
- * Slightly Modified ean13.php to get upca.php I needed a way to print
+ * Slightly Modified Ean13.php to get Upca.php I needed a way to print
* UPC-A bar codes on a PHP page. The Image_Barcode2 class seemed like
* the best way to do it, so I modified ean13 to print in the UPC-A format.
* Checked the bar code tables against some documentation below (no errors)
@@ -49,7 +49,7 @@
* @version Release: @package_version@
* @link http://pear.php.net/package/Image_Barcode2
*/
-class Image_Barcode2_upca extends Image_Barcode2_Common implements Image_Barcode2_Driver
+class Image_Barcode2_Upca extends Image_Barcode2_Common implements Image_Barcode2_Driver
{
/**
* Number set
@@ -119,7 +119,7 @@ public function __construct(Image_Barcode2_Writer $writer)
public function validate()
{
// Check barcode for invalid characters
- if (!preg_match('/[0-9]{12}/', $this->getBarcode())) {
+ if (!preg_match('/^[0-9]{12}$/', $this->getBarcode())) {
throw new Image_Barcode2_Exception('Invalid barcode');
}
}
@@ -7,5 +7,3 @@
$imgtype = isset($_REQUEST['imgtype']) ? $_REQUEST['imgtype'] : 'png';
Image_Barcode2::draw($num, $type, $imgtype);
-
-
@@ -1,4 +1,4 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<!DOCTYPE html>
<html>
<head>
<title>Image_Barcode Class Test</title>
@@ -33,58 +33,58 @@
}
</style>
</head>
-<body style="background-image: url(#FFFFFF);">
-<?php
+<body style="background-color: #FFFFFF;">
-$num = "019671015005";
-
-$num = isset($_REQUEST) && is_array($_REQUEST) && isset($_REQUEST['num']) ? $_REQUEST['num'] : $num;
-
-?>
<div class="box">
-<h1>Image_Barcode Class test</h1>
-Test number: <b><?php echo($num) ?></b>
+<h1>Image_Barcode2 Class test</h1>
</div>
<div class="test">
<h2>Interleave 2 of 5 (png):</h2>
-<img src="barcode_img.php?num=<?php echo($num) ?>&type=int25&imgtype=png"
- alt="PNG: <?php echo($num) ?>" title="PNG: <?php echo($num) ?>">
+<img src="barcode_img.php?num=1234567895&type=int25&imgtype=png"
+ alt="PNG: 1234567895" title="PNG: 1234567895"/>
</div>
<div class="test">
<h2>Ean13 (png):</h2>
<img
- src="barcode_img.php?num=<?php echo($num) ?>&type=ean13&imgtype=png"
- alt="PNG: <?php echo($num) ?>" title="PNG: <?php echo($num) ?>">
+ src="barcode_img.php?num=1234567891231&type=ean13&imgtype=png"
+ alt="PNG: 1234567891231" title="PNG: 1234567891231"/>
+</div>
+
+<div class="test">
+<h2>Ean8 (png):</h2>
+<img
+ src="barcode_img.php?num=12345670&type=ean8&imgtype=png"
+ alt="PNG: 12345670" title="PNG: 12345670"/>
</div>
<div class="test">
<h2>Code39 (png):</h2>
<img
- src="barcode_img.php?num=<?php echo($num) ?>&type=Code39&imgtype=png"
- alt="PNG: <?php echo($num) ?>" title="PNG: <?php echo($num) ?>">
+ src="barcode_img.php?num=BARCODE&type=Code39&imgtype=png"
+ alt="PNG: BARCODE" title="PNG: BARCODE"/>
</div>
<div class="test">
<h2>UPC-A (png):</h2>
<img
- src="barcode_img.php?num=<?php echo($num) ?>&type=upca&imgtype=png"
- alt="PNG: <?php echo($num) ?>" title="PNG: <?php echo($num) ?>">
+ src="barcode_img.php?num=123456789123&type=upca&imgtype=png"
+ alt="PNG: 123456789123" title="PNG: 123456789123"/>
</div>
<div class="test">
<h2>Code128 (png):</h2>
<img
- src="barcode_img.php?num=<?php echo($num) ?>&type=code128&imgtype=png"
- alt="PNG: <?php echo($num) ?>" title="PNG: <?php echo($num) ?>">
+ src="barcode_img.php?num=barcode&type=code128&imgtype=png"
+ alt="PNG: barcode" title="PNG: barcode"/>
</div>
<div class="test">
<h2>PostNet (png):</h2>
<img
- src="barcode_img.php?num=<?php echo($num) ?>&type=postnet&imgtype=png"
- alt="PNG: <?php echo($num) ?>" title="PNG: <?php echo($num) ?>">
+ src="barcode_img.php?num=202609900&type=postnet&imgtype=png"
+ alt="PNG: 202609900" title="PNG: 202609900"/>
</div>
</body>

0 comments on commit 13b1e0e

Please sign in to comment.