Sylius Digital Download: Technical Details
Technical details of Sylius Digital Download: flow diagram, plugin structure, three tables with ER diagram, migrations, design decisions, tests and development.
Sylius Digital Download: Technical Details
This documentation always describes the latest published version.
Flow
graph TD
A["Payment: transition complete"] --> B{"Plugin enabled?"}
B -->|No| Z["End"]
B -->|Yes| C{"Completed payments cover total?"}
C -->|No| Z
C -->|Yes| D["DownloadGrantIssuer: link per item and file"]
D --> E{"New links?"}
E -->|No| Z
E -->|Yes| F["DownloadReadyNotifier: send email"]
F -->|Error| G["Log error, payment stays"]
H["Customer: GET /downloads/token"] --> I{"Link found?"}
I -->|No| J["404"]
I -->|Yes| K{"Blocked, expired or used up?"}
K -->|Yes| L["410 Gone"]
K -->|No| M{"File readable?"}
M -->|No| J
M -->|Yes| N["Increase counter, stream file"]
R["Payment: transition refund"] --> S{"Order still fully paid?"}
S -->|Yes| Z
S -->|No| T["DownloadGrantRevoker: block links"]
Plugin structure
src/
Command/SetupCommand.php mmd:digital-download:setup
Controller/DownloadController.php GET /downloads/{token}
Controller/Admin/ Settings page
DependencyInjection/ Extension, Configuration
Email/ DownloadReadyNotifier
Entity/ DownloadFile, DownloadGrant, DownloadSettings
EventListener/PaymentStateListener.php
Form/Extension/ Extension of the variant form
Form/Type/ Settings form
Menu/ Sidebar group and entry
Migrations/ 2 Migrationen
Repository/
Service/ uploader, issuer, revoker, token, settings, payment check
Twig/DownloadGrantsExtension.php mmd_download_grants, mmd_download_blocked_reason
config/
routes/admin.yaml, shop.yaml
services/ Service wiring
twig_hooks/admin.yaml, shop.yaml
mailer.yaml
templates/ Admin-Abschnitt, Kundenkonto-Block, Mail
translations/ de, en (messages, flashes, validators)
The plugin ships no JavaScript. The interfaces are rendered entirely server-side.
Tables
erDiagram
SYLIUS_PRODUCT_VARIANT ||--o{ MMD_DIGITAL_DOWNLOAD_FILE : "has"
MMD_DIGITAL_DOWNLOAD_FILE ||--o{ MMD_DIGITAL_DOWNLOAD_GRANT : "is released by"
SYLIUS_ORDER_ITEM ||--o{ MMD_DIGITAL_DOWNLOAD_GRANT : "creates"
MMD_DIGITAL_DOWNLOAD_FILE {
int id PK
string storage_path UK
string original_filename
string mime_type
int size
datetime created_at
}
MMD_DIGITAL_DOWNLOAD_GRANT {
int id PK
string token UK
datetime expires_at
int max_downloads
int download_count
datetime revoked_at
datetime created_at
datetime last_downloaded_at
}
MMD_DIGITAL_DOWNLOAD_SETTINGS {
int id PK
bool enabled
int expiry_days
int max_downloads
int max_file_size_mb
text allowed_extensions
}
| Table | Content |
|---|---|
mmd_digital_download_file |
One file of a variant: storage path (unique), original name, MIME type, size. Deleting the variant removes the rows (ON DELETE CASCADE) |
mmd_digital_download_grant |
One link: token (unique, 64 characters), expiry, limit, counter, block timestamp. Unique per order item and file, deleting the order item or file removes the links (ON DELETE CASCADE) |
mmd_digital_download_settings |
One row with id = 1. Created when the settings page is saved for the first time. Until then, the YAML defaults apply |
The bundle registers the entity mapping itself via attribute mapping (alias MmdSyliusDigitalDownloadPlugin).
Migrations
| Version | Content |
|---|---|
Version20261114180000 |
Tables mmd_digital_download_file and mmd_digital_download_grant with foreign keys and unique indexes |
Version20261115100000 |
Table mmd_digital_download_settings |
Sylius' own migrations must have run before, the setup command checks this.
Decisions
- Payment instead of order: The release hangs on the workflow transition of the payment. The plugin sums only payments in state
completedand requires the sum to be greater than 0 and to reach the order total. - Idempotency: The issuer creates only links that are still missing. A second run creates nothing and triggers no second email.
- Email after the transition: A mail error is caught and logged, it does not abort the payment transition.
- Token: 32 random bytes from
random_bytes, hexadecimal, so 64 characters. - Storage path:
year/month/32 characters random.extension. The original name never influences the path, it is only stored, sanitized (path components removed, truncated to 200 characters), as a label. - Settings: The
DownloadSettingsProviderreturns the row from the database, and if it does not exist, an unsaved object with the YAML defaults.
Tests
The repository contains unit tests for entities, services, listeners and forms, an integration test that runs through the real payment workflow (release with exactly one email, download, refund with 410, disabled plugin, settings, unknown token), and a Behat feature for the settings page.
Development
make init # Docker: build containers, install dependencies
vendor/bin/phpunit
vendor/bin/phpstan analyse -c phpstan.neon
vendor/bin/ecs check
The integration tests need the test database, see make database-init.