Skip to content

Commit a06b96d

Browse files
authored
Merge pull request #5 from ageekdev/rename-type-enum-name
refactor: replace deprecated Type enum with BarcodeType in codebase
2 parents 00bcd4c + 104f47e commit a06b96d

16 files changed

+302
-118
lines changed

README.md

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
<h1 align="center">Laravel Barcode</h1>
22

3-
[![Latest Version on Packagist](https://img.shields.io/packagist/v/ageekdev/laravel-barcode.svg?style=flat-square&logo=Packagist)](https://packagist.org/packages/ageekdev/laravel-barcode)
4-
[![Laravel 9.x](https://img.shields.io/badge/Laravel-9.x-red.svg?style=flat-square)](https://laravel.com/docs/9.x)
5-
[![Laravel 10.x](https://img.shields.io/badge/Laravel-10.x-red.svg?style=flat-square)](http://laravel.com/docs/10.x)
6-
[![Laravel 11.x](https://img.shields.io/badge/Laravel-11.x-red.svg?style=flat-square)](http://laravel.com/docs/11.x)
7-
[![Laravel 12.x](https://img.shields.io/badge/Laravel-12.x-red.svg?style=flat-square)](http://laravel.com/docs/12.x)
8-
[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/ageekdev/laravel-barcode/run-tests.yml?style=flat-square)](https://github.com/ageekdev/laravel-barcode/actions/workflows/run-tests.yml)
9-
[![Total Downloads](https://img.shields.io/packagist/dt/ageekdev/laravel-barcode.svg?style=flat-square&logo=Packagist)](https://packagist.org/packages/ageekdev/laravel-barcode)
3+
<p align="center">
4+
<img src="https://banners.beyondco.de/Laravel%20Barcode.png?theme=light&packageManager=composer+require&packageName=ageekdev%2Flaravel-barcode&pattern=architect&style=style_1&description=Generate+barcodes+easily+in+your+Laravel+application&md=1&showWatermark=0&fontSize=100px&images=barcode&widths=200&heights=200" width="650">
5+
</p>
106

11-
This package can generate SVG, PNG, JPG and HTML images from the most used 1D barcode standards. Here's how you can use it:
7+
<p align="center">
8+
<a href="https://packagist.org/packages/ageekdev/laravel-barcode"><img alt="Latest Version on Packagist" src="https://img.shields.io/packagist/v/ageekdev/laravel-barcode.svg?style=flat-square&logo=Packagist"></a>
9+
<a href="https://github.com/ageekdev/laravel-barcode/actions/workflows/run-tests.yml"><img alt="GitHub Tests Action Status" src="https://img.shields.io/github/actions/workflow/status/ageekdev/laravel-barcode/run-tests.yml?style=flat-square"></a>
10+
<a href="https://packagist.org/packages/ageekdev/laravel-barcode"><img alt="Total Downloads" src="https://img.shields.io/packagist/dt/ageekdev/laravel-barcode.svg?style=flat-square&logo=Packagist"></a>
11+
<a href="https://laravel.com/docs/9.x"><img alt="Laravel 9.x" src="https://img.shields.io/badge/Laravel-9.x-red.svg?style=flat-square"></a>
12+
<a href="https://laravel.com/docs/10.x"><img alt="Laravel 10.x" src="https://img.shields.io/badge/Laravel-10.x-red.svg?style=flat-square"></a>
13+
<a href="https://laravel.com/docs/11.x"><img alt="Laravel 11.x" src="https://img.shields.io/badge/Laravel-11.x-red.svg?style=flat-square"></a>
14+
<a href="https://laravel.com/docs/12.x"><img alt="Laravel 12.x" src="https://img.shields.io/badge/Laravel-12.x-red.svg?style=flat-square"></a>
15+
</p>
1216

13-
## Installation
17+
# Laravel Barcode Generator
1418

15-
You can install the package via composer:
19+
A package to generate barcodes in various formats (SVG, PNG, JPG, HTML) for Laravel applications.
20+
21+
## ⚙️ Installation
22+
23+
You can install the package via Composer:
1624

1725
```bash
1826
composer require ageekdev/laravel-barcode
@@ -28,52 +36,52 @@ php artisan vendor:publish --tag="laravel-barcode-config"
2836

2937
```php
3038
use AgeekDev\Barcode\Facades\Barcode;
31-
use AgeekDev\Barcode\Enums\Type;
39+
use AgeekDev\Barcode\Enums\BarcodeType;
3240

3341
$barcode = Barcode::imageType("svg")
3442
->foregroundColor("#000000")
3543
->height(30)
3644
->widthFactor(2)
37-
->type(Type::TYPE_CODE_128)
45+
->type(BarcodeType::CODE_128)
3846
->generate("081231723897");
3947
```
4048

4149
## Accepted barcode types
4250
These barcode types are supported. All types support different character sets or have mandatory lengths. Please see wikipedia for supported chars and lengths per type.
4351

44-
Most used types are TYPE_CODE_128 and TYPE_CODE_39. Because of the best scanner support, variable length and most chars supported.
45-
46-
- TYPE_CODE_32 (italian pharmaceutical code 'MINSAN')
47-
- TYPE_CODE_39
48-
- TYPE_CODE_39_CHECKSUM
49-
- TYPE_CODE_39E
50-
- TYPE_CODE_39E_CHECKSUM
51-
- TYPE_CODE_93
52-
- TYPE_STANDARD_2_5
53-
- TYPE_STANDARD_2_5_CHECKSUM
54-
- TYPE_INTERLEAVED_2_5
55-
- TYPE_INTERLEAVED_2_5_CHECKSUM
56-
- TYPE_CODE_128
57-
- TYPE_CODE_128_A
58-
- TYPE_CODE_128_B
59-
- TYPE_CODE_128_C
60-
- TYPE_EAN_2
61-
- TYPE_EAN_5
62-
- TYPE_EAN_8
63-
- TYPE_EAN_13
64-
- TYPE_UPC_A
65-
- TYPE_UPC_E
66-
- TYPE_MSI
67-
- TYPE_MSI_CHECKSUM
68-
- TYPE_POSTNET
69-
- TYPE_PLANET
70-
- TYPE_RMS4CC
71-
- TYPE_KIX
72-
- TYPE_IMB
73-
- TYPE_CODABAR
74-
- TYPE_CODE_11
75-
- TYPE_PHARMA_CODE
76-
- TYPE_PHARMA_CODE_TWO_TRACKS
52+
Most used types are CODE_128 and CODE_39. Because of the best scanner support, variable length and most chars supported.
53+
54+
- CODE_32 (italian pharmaceutical code 'MINSAN')
55+
- CODE_39
56+
- CODE_39_CHECKSUM
57+
- CODE_39E
58+
- CODE_39E_CHECKSUM
59+
- CODE_93
60+
- STANDARD_2_5
61+
- STANDARD_2_5_CHECKSUM
62+
- INTERLEAVED_2_5
63+
- INTERLEAVED_2_5_CHECKSUM
64+
- CODE_128
65+
- CODE_128_A
66+
- CODE_128_B
67+
- CODE_128_C
68+
- EAN_2
69+
- EAN_5
70+
- EAN_8
71+
- EAN_13
72+
- UPC_A
73+
- UPC_E
74+
- MSI
75+
- MSI_CHECKSUM
76+
- POSTNET
77+
- PLANET
78+
- RMS4CC
79+
- KIX
80+
- IMB
81+
- CODABAR
82+
- CODE_11
83+
- PHARMA_CODE
84+
- PHARMA_CODE_TWO_TRACKS
7785

7886
## Testing
7987

@@ -95,7 +103,6 @@ Please review [our security policy](../../security/policy) on how to report secu
95103

96104
## Credits
97105

98-
- [Tint Naing Win](https://github.com/tintnaingwinn)
99106
- [All Contributors](../../contributors)
100107

101108
This package contains code copied from [PHP Barcode Generator](https://github.com/picqer/php-barcode-generator)

config/barcode.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
| TYPE_KIX, TYPE_IMB, TYPE_CODABAR, TYPE_CODE_11, TYPE_PHARMA_CODE, TYPE_PHARMA_CODE_TWO_TRACKS
2828
|
2929
*/
30-
'type' => \AgeekDev\Barcode\Enums\Type::TYPE_CODE_128,
30+
'type' => \AgeekDev\Barcode\Enums\BarcodeType::CODE_128,
3131

3232
/*
3333
* Foreground color of the barcode

phpstan.neon.dist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ parameters:
44
- src
55
tmpDir: build/phpstan
66
checkOctaneCompatibility: true
7+
ignoreErrors:
8+
- '#Parameter \$type of method .* has typehint with deprecated enum AgeekDev\\Barcode\\Enums\\Type#'
79

src/AbstractGenerator.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace AgeekDev\Barcode;
44

55
use AgeekDev\Barcode\Contracts\ImageType;
6+
use AgeekDev\Barcode\Enums\BarcodeType;
67
use AgeekDev\Barcode\Enums\Type;
78
use AgeekDev\Barcode\Types\TypeInterface;
89

@@ -17,7 +18,7 @@ abstract class AbstractGenerator implements ImageType
1718

1819
protected int $widthFactor;
1920

20-
protected Type $type;
21+
protected BarcodeType|Type $type;
2122

2223
public function __construct()
2324
{
@@ -27,17 +28,17 @@ public function __construct()
2728
$this->type = config('barcode.type');
2829
}
2930

30-
protected function getBarcodeData(string $code, Type $type): Barcode
31+
protected function getBarcodeData(string $code, BarcodeType|Type $type): Barcode
3132
{
3233
return $this->createDataBuilderForType($type)->getBarcodeData($code);
3334
}
3435

35-
protected function createDataBuilderForType(Type $type): TypeInterface
36+
protected function createDataBuilderForType(BarcodeType|Type $type): TypeInterface
3637
{
3738
return $type->class();
3839
}
3940

40-
public function type(Type $type): static
41+
public function type(BarcodeType|Type $type): static
4142
{
4243
$this->type = $type;
4344

src/BarcodeManager.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use AgeekDev\Barcode\Drivers\JPG;
1010
use AgeekDev\Barcode\Drivers\PNG;
1111
use AgeekDev\Barcode\Drivers\SVG;
12+
use AgeekDev\Barcode\Enums\BarcodeType;
1213
use AgeekDev\Barcode\Enums\Type;
1314
use AgeekDev\Barcode\Exceptions\BarcodeException;
1415
use Closure;
@@ -151,7 +152,7 @@ public function generate(string $text): string
151152
/**
152153
* Set the barcode type.
153154
*/
154-
public function type(Type $type): ImageType
155+
public function type(BarcodeType|Type $type): ImageType
155156
{
156157
return $this->imageType()->type($type);
157158
}

src/Contracts/ImageType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
namespace AgeekDev\Barcode\Contracts;
44

5+
use AgeekDev\Barcode\Enums\BarcodeType;
56
use AgeekDev\Barcode\Enums\Type;
67

78
interface ImageType
89
{
910
public function generate(string $text): string;
1011

11-
public function type(Type $type): static;
12+
public function type(BarcodeType|Type $type): static;
1213

1314
public function foregroundColor(string $foregroundColor): static;
1415

src/Enums/BarcodeType.php

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
<?php
2+
3+
namespace AgeekDev\Barcode\Enums;
4+
5+
use AgeekDev\Barcode\Types\TypeCodabar;
6+
use AgeekDev\Barcode\Types\TypeCode11;
7+
use AgeekDev\Barcode\Types\TypeCode128;
8+
use AgeekDev\Barcode\Types\TypeCode128A;
9+
use AgeekDev\Barcode\Types\TypeCode128B;
10+
use AgeekDev\Barcode\Types\TypeCode128C;
11+
use AgeekDev\Barcode\Types\TypeCode32;
12+
use AgeekDev\Barcode\Types\TypeCode39;
13+
use AgeekDev\Barcode\Types\TypeCode39Checksum;
14+
use AgeekDev\Barcode\Types\TypeCode39Extended;
15+
use AgeekDev\Barcode\Types\TypeCode39ExtendedChecksum;
16+
use AgeekDev\Barcode\Types\TypeCode93;
17+
use AgeekDev\Barcode\Types\TypeEan13;
18+
use AgeekDev\Barcode\Types\TypeEan8;
19+
use AgeekDev\Barcode\Types\TypeIntelligentMailBarcode;
20+
use AgeekDev\Barcode\Types\TypeInterface;
21+
use AgeekDev\Barcode\Types\TypeInterleaved25;
22+
use AgeekDev\Barcode\Types\TypeInterleaved25Checksum;
23+
use AgeekDev\Barcode\Types\TypeKix;
24+
use AgeekDev\Barcode\Types\TypeMsi;
25+
use AgeekDev\Barcode\Types\TypeMsiChecksum;
26+
use AgeekDev\Barcode\Types\TypePharmacode;
27+
use AgeekDev\Barcode\Types\TypePharmacodeTwoCode;
28+
use AgeekDev\Barcode\Types\TypePlanet;
29+
use AgeekDev\Barcode\Types\TypePostnet;
30+
use AgeekDev\Barcode\Types\TypeRms4cc;
31+
use AgeekDev\Barcode\Types\TypeStandard2of5;
32+
use AgeekDev\Barcode\Types\TypeStandard2of5Checksum;
33+
use AgeekDev\Barcode\Types\TypeUpcA;
34+
use AgeekDev\Barcode\Types\TypeUpcE;
35+
use AgeekDev\Barcode\Types\TypeUpcExtension2;
36+
use AgeekDev\Barcode\Types\TypeUpcExtension5;
37+
38+
enum BarcodeType: string
39+
{
40+
case CODE_32 = 'C32';
41+
42+
case CODE_39 = 'C39';
43+
44+
case CODE_39_CHECKSUM = 'C39+';
45+
46+
case CODE_39E = 'C39E'; // CODE 39 EXTENDED
47+
48+
case CODE_39E_CHECKSUM = 'C39E+'; // CODE 39 EXTENDED + CHECKSUM
49+
50+
case CODE_93 = 'C93';
51+
52+
case STANDARD_2_5 = 'S25';
53+
54+
case STANDARD_2_5_CHECKSUM = 'S25+';
55+
56+
case INTERLEAVED_2_5 = 'I25';
57+
58+
case INTERLEAVED_2_5_CHECKSUM = 'I25+';
59+
60+
case CODE_128 = 'C128';
61+
62+
case CODE_128_A = 'C128A';
63+
64+
case CODE_128_B = 'C128B';
65+
66+
case CODE_128_C = 'C128C';
67+
68+
case EAN_2 = 'EAN2'; // 2-Digits UPC-Based Extention
69+
70+
case EAN_5 = 'EAN5'; // 5-Digits UPC-Based Extention
71+
72+
case EAN_8 = 'EAN8';
73+
74+
case EAN_13 = 'EAN13';
75+
76+
case UPC_A = 'UPCA';
77+
78+
case UPC_E = 'UPCE';
79+
80+
case MSI = 'MSI'; // MSI (Variation of Plessey code)
81+
82+
case MSI_CHECKSUM = 'MSI+'; // MSI + CHECKSUM (modulo 11)
83+
84+
case POSTNET = 'POSTNET';
85+
86+
case PLANET = 'PLANET';
87+
88+
case RMS4CC = 'RMS4CC'; // RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
89+
90+
case KIX = 'KIX'; // KIX (Klant index - Customer index)
91+
92+
case IMB = 'IMB'; // IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
93+
94+
case CODABAR = 'CODABAR';
95+
96+
case CODE_11 = 'CODE11';
97+
98+
case PHARMA_CODE = 'PHARMA';
99+
100+
case PHARMA_CODE_TWO_TRACKS = 'PHARMA2T';
101+
102+
public function class(): TypeInterface
103+
{
104+
return match ($this) {
105+
self::CODE_32 => new TypeCode32,
106+
107+
self::CODE_39 => new TypeCode39,
108+
109+
self::CODE_39_CHECKSUM => new TypeCode39Checksum,
110+
111+
self::CODE_39E => new TypeCode39Extended,
112+
113+
self::CODE_39E_CHECKSUM => new TypeCode39ExtendedChecksum,
114+
115+
self::CODE_93 => new TypeCode93,
116+
117+
self::STANDARD_2_5 => new TypeStandard2of5,
118+
119+
self::STANDARD_2_5_CHECKSUM => new TypeStandard2of5Checksum,
120+
121+
self::INTERLEAVED_2_5 => new TypeInterleaved25,
122+
123+
self::INTERLEAVED_2_5_CHECKSUM => new TypeInterleaved25Checksum,
124+
125+
self::CODE_128 => new TypeCode128,
126+
127+
self::CODE_128_A => new TypeCode128A,
128+
129+
self::CODE_128_B => new TypeCode128B,
130+
131+
self::CODE_128_C => new TypeCode128C,
132+
133+
self::EAN_2 => new TypeUpcExtension2,
134+
135+
self::EAN_5 => new TypeUpcExtension5,
136+
137+
self::EAN_8 => new TypeEan8,
138+
139+
self::EAN_13 => new TypeEan13,
140+
141+
self::UPC_A => new TypeUpcA,
142+
143+
self::UPC_E => new TypeUpcE,
144+
145+
self::MSI => new TypeMsi,
146+
147+
self::MSI_CHECKSUM => new TypeMsiChecksum,
148+
149+
self::POSTNET => new TypePostnet,
150+
151+
self::PLANET => new TypePlanet,
152+
153+
self::RMS4CC => new TypeRms4cc,
154+
155+
self::KIX => new TypeKix,
156+
157+
self::IMB => new TypeIntelligentMailBarcode,
158+
159+
self::CODABAR => new TypeCodabar,
160+
161+
self::CODE_11 => new TypeCode11,
162+
163+
self::PHARMA_CODE => new TypePharmacode,
164+
165+
self::PHARMA_CODE_TWO_TRACKS => new TypePharmacodeTwoCode,
166+
};
167+
}
168+
}

src/Enums/Type.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
use AgeekDev\Barcode\Types\TypeUpcExtension2;
3636
use AgeekDev\Barcode\Types\TypeUpcExtension5;
3737

38+
/**
39+
* @deprecated see BarcodeType
40+
*/
3841
enum Type: string
3942
{
4043
case TYPE_CODE_32 = 'C32';

0 commit comments

Comments
 (0)