calliostro / discogs-bundle
Lightweight Symfony bundle for the Discogs API with autowiring, resilience, and rate limiting support.
Package info
github.com/calliostro/discogs-bundle
Type:symfony-bundle
pkg:composer/calliostro/discogs-bundle
Requires
- php: ^8.1
- calliostro/php-discogs-api: ^4.1
- symfony/config: ^6.4 || ^7.0 || ^8.0
- symfony/dependency-injection: ^6.4 || ^7.0 || ^8.0
- symfony/http-kernel: ^6.4 || ^7.0 || ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpstan/phpstan: ^2.0
- symfony/phpunit-bridge: ^6.4 || ^7.0 || ^8.0
- symfony/rate-limiter: ^6.4 || ^7.0 || ^8.0
- symfony/security-core: ^6.4 || ^7.0 || ^8.0
Suggests
- symfony/rate-limiter: For proactive client-side rate limiting and traffic shaping
Provides
None
Conflicts
None
Replaces
None
README
A Symfony bundle integrating calliostro/php-discogs-api into your Symfony application. Provides dependency injection, autowiring, built-in retry resilience, and optional rate limiting for PHP 8.1+ and Symfony 6.4, 7.x, and 8.x.
๐ฆ Installation
Install via Composer:
composer require calliostro/discogs-bundle
โ๏ธ Configuration
Configure the bundle in config/packages/calliostro_discogs.yaml:
calliostro_discogs: # Recommended: Personal Access Token (get from https://www.discogs.com/settings/developers) personal_access_token: '%env(DISCOGS_PERSONAL_ACCESS_TOKEN)%' # Alternative: Consumer credentials for OAuth applications # consumer_key: '%env(DISCOGS_CONSUMER_KEY)%' # consumer_secret: '%env(DISCOGS_CONSUMER_SECRET)%' # Optional: HTTP User-Agent header for API requests # user_agent: 'MyApp/1.0 +https://myapp.com' # Optional: Retry resilience settings (enabled by default) # auto_retry: true # Automatically wait and retry on 429 and 503 responses (default: true) # max_retries: 3 # Maximum number of retry attempts (default: 3) # Optional: Proactive rate limiting (requires symfony/rate-limiter) # rate_limiter: discogs_api
Note
By default, the client uses DiscogsClient/4.1.0 (+https://github.com/calliostro/php-discogs-api) as User-Agent. You can override this in the configuration if needed.
Authentication Methods
- Personal Access Token: Obtain your token from Discogs Developer Settings to access user-specific data (collections, wantlists) and benefit from higher rate limits (60 requests/min).
- Consumer Credentials: For OAuth applications, register your application on Discogs to obtain your
consumer_keyandconsumer_secret. - Anonymous Access: If no credentials are configured, the bundle initializes the client for public data endpoints (subject to unauthenticated rate limits of 25 requests/min).
๐ Quick Start
Basic Usage
Inject the DiscogsClient service directly into your controllers or services:
<?php namespace App\Controller; use Calliostro\Discogs\DiscogsClient; use Symfony\Component\HttpFoundation\JsonResponse; final class MusicController { public function artistInfo(string $id, DiscogsClient $client): JsonResponse { $artist = $client->getArtist(artistId: (int) $id); $releases = $client->listArtistReleases(artistId: (int) $id, perPage: 5); return new JsonResponse([ 'artist' => $artist['name'], 'profile' => $artist['profile'] ?? null, 'releases' => $releases['releases'], ]); } }
Collection and Wantlist
// Requires Personal Access Token $collection = $client->listCollectionItems(username: 'your-username', folderId: 0); $wantlist = $client->getUserWantlist(username: 'your-username'); $client->addToCollection( username: 'your-username', folderId: 1, releaseId: 30359313 ); $client->addToWantlist( username: 'your-username', releaseId: 28409710 );
Search and Database Lookups
$results = $client->search( q: 'Billie Eilish', type: 'artist' ); $releases = $client->listArtistReleases(artistId: 4470662); $release = $client->getRelease(releaseId: 30359313); $master = $client->getMaster(masterId: 2835729); $label = $client->getLabel(labelId: 12677);
โจ Key Features
- Lightweight Integration โ Minimal footprint with zero overhead on top of
calliostro/php-discogs-api. - Complete API Coverage โ All 60 Discogs API endpoints supported.
- Direct API Calls โ
$client->getArtist(artistId: 123)maps directly to/artists/{id}. - Built-in Retry Resilience โ Automatic exponential backoff and retry handling for
429 Too Many Requestsand503 Service Unavailableresponses. - Type Safe & IDE Support โ PHP 8.1+ types, named parameters, and PHPStan Level 8 static analysis.
- Symfony Native โ Autowiring support for Symfony 6.4, 7.x, and 8.x.
- Multiple Authentication Methods โ Personal Access Token, OAuth 1.0a, Consumer Credentials, and Anonymous access.
๐ต All Discogs API Methods as Direct Calls
- Database Methods โ
search(),getArtist(),listArtistReleases(),getRelease(),getUserReleaseRating(),updateUserReleaseRating(),deleteUserReleaseRating(),getCommunityReleaseRating(),getReleaseStats(),getMaster(),listMasterVersions(),getLabel(),listLabelReleases() - User Identity Methods โ
getIdentity(),getUser(),updateUser(),listUserSubmissions(),listUserContributions() - User Collection Methods โ
listCollectionFolders(),getCollectionFolder(),createCollectionFolder(),updateCollectionFolder(),deleteCollectionFolder(),listCollectionItems(),getCollectionItemsByRelease(),addToCollection(),updateCollectionItem(),removeFromCollection(),getCustomFields(),setCustomFields(),getCollectionValue() - User Wantlist Methods โ
getUserWantlist(),addToWantlist(),updateWantlistItem(),removeFromWantlist() - User Lists Methods โ
getUserLists(),getUserList() - Marketplace Methods โ
getUserInventory(),getMarketplaceListing(),createMarketplaceListing(),updateMarketplaceListing(),deleteMarketplaceListing(),getMarketplaceFee(),getMarketplaceFeeByCurrency(),getMarketplacePriceSuggestions(),getMarketplaceStats(),getMarketplaceOrder(),getMarketplaceOrders(),updateMarketplaceOrder(),getMarketplaceOrderMessages(),addMarketplaceOrderMessage() - Inventory Export Methods โ
createInventoryExport(),listInventoryExports(),getInventoryExport(),downloadInventoryExport() - Inventory Upload Methods โ
addInventoryUpload(),changeInventoryUpload(),deleteInventoryUpload(),listInventoryUploads(),getInventoryUpload()
Note
Complete method documentation and endpoint parameters can be found in the Discogs API Documentation.
๐ Requirements
- PHP
^8.1(tested on PHP 8.1โ8.6) - Symfony
^6.4 || ^7.0 || ^8.0 - calliostro/php-discogs-api
^4.1
โก Resilience & Rate Limiting
Built-in Retries (Reactive)
Out of the box, calliostro/php-discogs-api v4.1 automatically handles rate limit responses (429 Too Many Requests) and temporary service downtime (503 Service Unavailable). When triggered, the client sleeps for the duration requested by Discogs (via the Retry-After header) or uses exponential backoff before retrying the request.
You can customize or disable this behavior in config/packages/calliostro_discogs.yaml:
calliostro_discogs: auto_retry: true # default: true max_retries: 3 # default: 3
Symfony Rate Limiter (Proactive, Optional)
For high-volume batch processing, background workers, or scraping tasks, use symfony/rate-limiter to throttle outgoing requests client-side before sending them:
composer require symfony/rate-limiter
1. Configure the Rate Limiter
# config/packages/rate_limiter.yaml rate_limiter: discogs_api: policy: 'sliding_window' limit: 25 # 25 for anonymous access, up to 60 for authenticated access interval: '1 minute'
2. Assign to the Bundle
# config/packages/calliostro_discogs.yaml calliostro_discogs: personal_access_token: '%env(DISCOGS_PERSONAL_ACCESS_TOKEN)%' rate_limiter: discogs_api
๐งช Development & Testing Guide
See DEVELOPMENT.md for detailed setup instructions, test suite commands, static analysis, and contribution guidelines.
๐ค Contributing
Contributions are welcome! Please ensure that all tests pass and coding standards are maintained:
composer cs-fix
composer analyse
composer test
๐ License
This project is licensed under the MIT License โ see the LICENSE file for details.
โ๏ธ Disclaimer
Discogs is a registered trademark of Zink Media, LLC. This project is an independent, unofficial open-source library and is not affiliated with, endorsed by, or sponsored by Discogs or Zink Media, LLC.
๐ Acknowledgments
- Discogs for providing the database and API.
- Symfony for the web framework and dependency injection container.
- Underlying client:
calliostro/php-discogs-api. - Sister Symfony bundles:
calliostro/spotify-web-api-bundle,calliostro/last-fm-client-bundle, andcalliostro/musicbrainz-bundle.