idci/barcode-bundle
A Symfony bundle for generating barcodes, wrapping popular PHP barcode libraries behind a simple service and Twig helpers. Render common symbologies such as EAN, UPC, Code 128 and QR directly in your templates, with configurable output formats for embedding in views, PDFs or downloads.
Read this first: this is a Symfony 2 bundle, and you are on Laravel. There is no composer require path that lands you in a working state. idci/barcode-bundle registers itself through AppKernel, YAML/XML service definitions, and a Twig function extension. Laravel has no equivalent primitives. Your "getting started" is therefore a 30-minute triage, not an install.
Minimal triage steps (do these before writing any code):
composer require idci/barcode-bundle --dry-run
Expect it to fail against Laravel 10/11 and PHP 8.x because of symfony/symfony ~2.x, old psr/* pins, and possibly twig/twig version clashes. If it fails, the integration path is "fork," not "require," and the rest of this guide applies.composer.json — actual PHP/Symfony constraints, which decide feasibility.Twig/ (or Extension/) — the public surface. This is where the barcode actually gets rendered; in bundles of this vintage the generation logic is often inlined here rather than in a clean service.DependencyInjection/ and Resources/config/ — what services exist and whether the generator is injectable.Where to look first if you need a working barcode this sprint: skip the bundle entirely. picqer/php-barcode-generator (MIT, framework-agnostic, actively maintained) gives you the same one-dimensional symbologies inside a Laravel service provider in under an hour. milon/barcode is the Laravel-native wrapper if you want zero provider code.
First use case to validate against: a fulfillment label — Code 128 rendering into a PDF (dompdf/snappy) as an inline SVG or a base64 PNG data URI. If your use case is QR/DataMatrix/PDF417, this package is the wrong engine regardless of framework; go to endroid/qr-code.
Because there is no native Laravel path, there are exactly three patterns worth knowing. Pick deliberately.
If you ever read the source or port it, this is the shape it expects. It is not available to you on Laravel, but it tells you what the public API is:
// Symfony 2 AppKernel: register bundle, configure defaults
new IDCI\Bundle\BarcodeBundle\IDCIBarcodeBundle(),
{# Twig extension is the primary entry point #}
<img src="{{ barcode('code128', 'INV-2024-0042') }}" />
The reusable-service API advertised in the description lives behind the container; you inject it into a controller or service and ask it to render. Everything below assumes you've extracted that renderer into a standalone class in your fork.
This is the only viable way to use this package from Laravel. Budget a day, gate it on the license decision.
// 1. Vendor under an internal namespace, strip bundle metadata:
// remove DependencyInjection/, Resources/config/, IDCIBarcodeBundle.php
// keep only the generator. Expose it as one injectable class.
namespace App\Support\Barcode;
class BarcodeRenderer
{
public function render(string $symbology, string $payload, array $opts = []): string
{
// adapted from the original Twig extension's body
}
}
// 2. Bind it as a singleton; keep controllers thin.
// app/Providers/BarcodeServiceProvider.php
public function register(): void
{
$this->app->singleton(BarcodeRenderer::class);
}
// 3. Expose it via a Blade component, not a directive — easier to test.
// resources/views/components/barcode.blade.php
<img src="{{ app(App\Support\Barcode\BarcodeRenderer::class)
->render($symbology, $payload, $options) }}" alt="{{ $payload }}" />
Capture a golden baseline before any edit. Render a handful of (symbology, payload, size) tuples from the original code, store the bytes, and assert against them after the extraction. With zero upstream tests, these snapshots are the only regression net you will ever have.
Barcode rendering is pure output of a tuple. Cache it and this becomes a boring, cheap dependency.
public function render(string $symbology, string $payload, array $opts = []): string
{
$key = 'barcode:' . hash('xxh128', serialize([$symbology, $payload, $opts]));
return Cache::remember($key, now()->addYear(), function () use ($symbology, $payload, $opts) {
return $this->renderer->render($symbology, $payload, $opts);
});
}
Integration tips:
data:image/svg+xml;base64,....Pitfalls
composer require into Laravel, period. Do not spend a day fighting composer why-not. If the constraint probe fails, the answer is fork or drop — not vendor-patch Symfony 2 into Illuminate.BarecodeBundle (missing "c") in the README, while the package is barcode-bundle. Expect broken links and confusion when searching; that mismatch has also cost this repo discoverability.Debugging
PATH — a common failure mode in bundles of this vintage on modern container images.Config quirks
Resources/config/. In your fork, surface them as a config/barcode.php file rather than leaving them hardcoded inside the extracted renderer.Extension points
The honest recommendation
The right day-to-day pattern for a Laravel developer is to not adopt this package. Wrap picqer/php-barcode-generator (1D, MIT) or endroid/qr-code (2D, MIT) behind the same one-method service you'd have built around the fork. That gives you:
Reserve this bundle as a reference implementation to read once, then close the evaluation.
How can I help you explore Laravel packages today?