Symfony Bundle for the picqer/php-barcode-generator library, to generate an SVG barcode within twig.
Quick demonstration of survos/barcode-bundle functionality.
- PHP 8.2+
- Symfony CLI
- Castor task runner
curl "https://castor.jolicode.com/install" | bash# 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 buildRun 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)src/Entity/Product.php- Sample entity with barcode supportsrc/Repository/ProductRepository.php- Repositorysrc/Command/ImportProductsCommand.php- Data import commandtemplates/products.html.twig- Product listing template- SQLite database with sample products
Visit the opened browser to see:
- Product listing with barcodes
- EasyAdmin dashboard
- Barcode generation examples
castor clean # Removes all demo filesCastor 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
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 buildSee 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'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