survos/barcode-bundle

Integrates picqer/php-barcode-generator in a Symfony application

Fund package maintenance!
kbond

Installs: 15 231

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 0

Open Issues: 0

Type:symfony-bundle

pkg:composer/survos/barcode-bundle

2.0.51 2025-11-03 18:16 UTC

This package is auto-updated.

Last update: 2025-11-15 14:24:14 UTC


README

Symfony Bundle for the picqer/php-barcode-generator library, to generate an SVG barcode within twig.

Barcode Bundle Demo

Quick demonstration of survos/barcode-bundle functionality.

Prerequisites

  • PHP 8.2+
  • Symfony CLI
  • Castor task runner

Install Castor

curl "https://castor.jolicode.com/install" | bash

Quick Start

# Create a new Symfony project
symfony new barcode-demo --webapp
cd barcode-demo

# Download the demo castor file
wget https://raw.githubusercontent.com/survos/barcode-bundle/main/castor/castor.php

# See available tasks
castor list

# Build complete demo (installs bundle, creates files, sets up database, starts server)
castor build

Individual Steps

Run these independently if you prefer:

castor setup        # Install bundle and create directories
castor copy-files   # Copy demo files from bundle
castor database     # Configure SQLite and create schema
castor import       # Load sample product data
castor open         # Start web server and open browser
castor clean        # Remove demo files (optional)

What Gets Created

  • src/Entity/Product.php - Sample entity with barcode support
  • src/Repository/ProductRepository.php - Repository
  • src/Command/ImportProductsCommand.php - Data import command
  • templates/products.html.twig - Product listing template
  • SQLite database with sample products

Next Steps

Visit the opened browser to see:

  • Product listing with barcodes
  • EasyAdmin dashboard
  • Barcode generation examples

Cleanup

castor clean  # Removes all demo files

Troubleshothy

Castor file not found: Make sure you're in the project root directory

Permission denied: Run chmod +x castor.php

Bundle not installed: Run castor setup first before other commands

Demo Application

Try the bundle instantly:

symfony new barcode-demo --webapp && cd barcode-demo && \
wget https://raw.githubusercontent.com/survos/barcode-bundle/main/castor/castor.php && \
castor build

See the demo README for step-by-step instructions.

composer req survos/barcode-bundle
{# as a filter #}
{{ '12345'|barcode }}

{# as a function #}
{{ barcode(random(), 2, 80, 'red' }}

To set default values (@todo: install recipe)

# config/packages/barcode.yaml
barcode:
  widthFactor: 3
  height: 120
  foregroundColor: 'purple'

Proof that it works

Requirements:

  • Locally installed PHP 8, with GD or Imagick
  • Symfony CLI
  • sed (to change /app to / without opening an editor)
symfony new BarcodeDemo --webapp && cd BarcodeDemo
symfony composer req survos/barcode-bundle
symfony console make:controller AppController
sed -i "s|/app|/|" src/Controller/AppController.php 

cat <<'EOF' > templates/app/index.html.twig
{% extends 'base.html.twig' %}
{% block body %}
{{ 'test'|barcode }} or {{ barcode('test', 2, 80, 'red') }}
{% endblock %}
EOF

#echo "{{ 'test'|barcode }} or {{ barcode('test', 2, 80, 'red') }} " >> templates/app/index.html.twig
symfony server:start -d
symfony open:local