From 698865fa6eccded3cdb6b69951e1170e600ef773 Mon Sep 17 00:00:00 2001 From: Gustavo Arnosti Neves Date: Sat, 20 May 2017 02:10:17 -0300 Subject: [PATCH] v1.0.5 adding exception patch to upstream php-barcode-generator; catching exception for invalid barcode; little code cleanning; chmod disabled for now (chown was already), until rebuilt as an option; more tests and errors detected --- barcode.php | 207 +++++++++--------- .../src/BarcodeGenerator.php | 1 + 2 files changed, 109 insertions(+), 99 deletions(-) diff --git a/barcode.php b/barcode.php index f25db86..3f194b7 100755 --- a/barcode.php +++ b/barcode.php @@ -14,16 +14,11 @@ require_once 'vendor/autoload.php'; -define("_BC_VERSION", "1.0.4"); +define("_BC_VERSION", "1.0.5"); - # permission to set to barcode files -define("_BC_PERMISSION", 0644); - # group to set to barcode files (disabled at bot) -define("_BC_SYSGROUP", "yourGrpHere"); - # default padding for barcode +# default padding for cli messages define("_BC_PADDING", 30); - $verbose = false; $quiet = false; @@ -37,6 +32,9 @@ $width = 2; $height = 30; $color = '#000000'; +#$_defPermission = $false; # to be implemented +#$_defGroup = $false; # to be implemented + $encodings_list = array( 'CODE_39', 'CODE_39_CHECKSUM', @@ -80,12 +78,105 @@ $formats_list = array( sort($formats_list); +/////////////////// PRINT HELP + +// prints help information +function print_help($getopt) { + global $encodings_list; + global $formats_list; + + echo $getopt->getHelpText(_BC_PADDING); + echo "\nRequired Options and Parameters:\n"; + echo " -e \n"; + echo " -f \n"; + echo " \n"; + echo " \n"; + echo "\nOutput Formats:\n"; + foreach($formats_list as $for) { + echo " $for\n"; + } + echo "\nEncodings:\n"; + foreach($encodings_list as $enc) { + echo " $enc\n"; + } + echo "\nExamples:\n"; + echo " barcode -f HTML -e CODE_39 \"1234567890\" \"/tmp/1234567890.html\"\n"; + echo " barcode -e CODE_128 -f PNG -c \"#888\" -w 3 -h 50 \"AGREATBAR\" \"/tmp/AGREATBAR.png\"\n"; + echo " barcode \"1234567890\" \"/tmp/mybar.svg\" --encoding EAN_13 --format SVG\n"; +} + + +/////////////////// CREATE BASH SCRIPT + +// creates a bash script named barcode that will run this script +// from anywhere on the system. Assumes barcode.php is running +// on its final installation location +function create_bash_script() { + $error = true; + $bc_path = __FILE__; + $bash_path = dirname($bc_path) . DIRECTORY_SEPARATOR . "barcode"; + + $bash_script = <<getBarcode($bc_string, $bc_type, $width, $height, $color); +try { + $bc_data = $generator->getBarcode($bc_string, $bc_type, $width, $height, $color); +} catch (Exception $e) { + echo "Error: ".$e->getMessage()."\n"; + exit(1); +} // sanity check $tgtDir = dirname($bc_file); @@ -256,52 +307,10 @@ if (@file_put_contents($bc_file, $bc_data) === false) { } // set permissions and group -chmod($bc_file, _BC_PERMISSION); -#chgrp($bc_file, _BC_SYSGROUP); - - -// prints help information -function print_help($getopt) { - global $encodings_list; - global $formats_list; - - echo $getopt->getHelpText(_BC_PADDING); - echo "\nRequired Options and Parameters:\n"; - echo " -e \n"; - echo " -f \n"; - echo " \n"; - echo " \n"; - echo "\nOutput Formats:\n"; - foreach($formats_list as $for) { - echo " $for\n"; - } - echo "\nEncodings:\n"; - foreach($encodings_list as $enc) { - echo " $enc\n"; - } - echo "\nExamples:\n"; - echo " barcode -f HTML -e CODE_39 \"1234567890\" \"/tmp/1234567890.html\"\n"; - echo " barcode -e CODE_128 -f PNG -c \"#888\" -w 3 -h 50 \"AGREATBAR\" \"/tmp/AGREATBAR.png\"\n"; - echo " barcode \"1234567890\" \"/tmp/mybar.svg\" --encoding EAN_13 --format SVG\n"; -} - -// check if encoding callback -function isEncoding($enc=null) { - global $encodings_list; - return in_array(strtoupper($enc), $encodings_list); -} - -// check if format callback -function isFormat($format=null) { - global $formats_list; - return in_array(strtoupper($format), $formats_list); -} - -// check if empty callback -function not_empty($str) { - return (!empty($str)); -} +#chmod($bc_file, $_defPermission); +#chgrp($bc_file, $_defGroup); +/////////////////// CREATE BARCODE ENDS // done exit(0); diff --git a/vendor/picqer/php-barcode-generator/src/BarcodeGenerator.php b/vendor/picqer/php-barcode-generator/src/BarcodeGenerator.php index d05684f..4da721f 100644 --- a/vendor/picqer/php-barcode-generator/src/BarcodeGenerator.php +++ b/vendor/picqer/php-barcode-generator/src/BarcodeGenerator.php @@ -2812,6 +2812,7 @@ abstract class BarcodeGenerator protected function convertBarcodeArrayToNewStyle($oldBarcodeArray) { + if (empty($oldBarcodeArray['bcode'])) throw new \Exception("Could not process barcode! Seems like your barcode string is invalid for the proposed format."); $newBarcodeArray = []; $newBarcodeArray['code'] = $oldBarcodeArray['code']; $newBarcodeArray['maxWidth'] = $oldBarcodeArray['maxw'];