🚀 SYMFONY INTEGRATION! Seamless autowiring for the complete Discogs music database API. Zero bloat, maximum performance.
Symfony bundle that integrates the modern calliostro/php-discogs-api into your Symfony application. Built with modern PHP 8.1+ features, dependency injection, and powered by Guzzle.
Install via Composer:
composer require calliostro/discogs-bundle
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: Professional rate limiting (requires symfony/rate-limiter)
# rate_limiter: discogs_api # Your configured RateLimiterFactory service
Personal Access Token: You need to get your token from Discogs to access your account data and get higher rate limits. For read-only operations on public data, you can use anonymous access.
Consumer Credentials: For building applications that need OAuth authentication, register your app at Discogs to get your consumer key and secret.
User-Agent: By default, the client uses DiscogsClient/4.0.0 (+https://github.com/calliostro/php-discogs-api) as User-Agent. You can override this in the configuration if needed.
<?php
// src/Controller/MusicController.php
namespace App\Controller;
use Calliostro\Discogs\DiscogsClient;
use Symfony\Component\HttpFoundation\JsonResponse;
class MusicController
{
public function artistInfo(string $id, DiscogsClient $client): JsonResponse
{
$artist = $client->getArtist(artistId: $id);
$releases = $client->listArtistReleases(artistId: $id, perPage: 5);
return new JsonResponse([
'artist' => $artist['name'],
'profile' => $artist['profile'] ?? null,
'releases' => $releases['releases'],
]);
}
}
// 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 // Billie Eilish - Happier Than Ever
);
$client->addToWantlist(username: 'your-username', releaseId: 28409710); // Taylor Swift - Midnights
$results = $client->search(
q: 'Billie Eilish',
type: 'artist'
);
$releases = $client->listArtistReleases(artistId: 4470662); // Billie Eilish
$release = $client->getRelease(releaseId: 30359313); // Happier Than Ever
$master = $client->getMaster(masterId: 2835729); // Midnights master
$label = $client->getLabel(labelId: 12677); // Interscope Records
$client->getArtist(id: 123) maps to /artists/{id}, no abstractionsAll 60 Discogs API endpoints are supported with clean documentation — see Discogs API Documentation for complete method reference
<?php
// src/Service/MusicService.php
namespace App\Service;
use Calliostro\Discogs\DiscogsClient;
class MusicService
{
public function __construct(
private readonly DiscogsClient $client
) {
}
public function getArtistWithReleases(int $artistId): array
{
$artist = $this->client->getArtist(artistId: $artistId);
$releases = $this->client->listArtistReleases(
artistId: $artistId,
perPage: 10
);
return [
'artist' => $artist,
'releases' => $releases['releases'],
];
}
public function addToMyCollection(int $releaseId): void
{
// Requires Personal Access Token
$this->client->addToCollection(
username: 'your-username', // Replace with actual username
folderId: 1, // "Uncategorized" folder
releaseId: $releaseId
);
}
}
For high-volume applications, use the powerful symfony/rate-limiter component:
composer require symfony/rate-limiter
# config/packages/rate_limiter.yaml
rate_limiter:
discogs_api:
policy: 'sliding_window'
limit: 25 # Safe for both anonymous and authenticated access
interval: '1 minute'
# config/packages/calliostro_discogs.yaml
calliostro_discogs:
personal_access_token: '%env(DISCOGS_PERSONAL_ACCESS_TOKEN)%'
rate_limiter: discogs_api
Choose your rate limit based on your authentication:
The bundle uses a Guzzle middleware that automatically handles rate limiting by:
This seamless integration ensures your application never exceeds API limits without requiring any code changes. Higher rates may result in HTTP 429 responses if rate limiting is not configured.
Contributions are welcome! Please see DEVELOPMENT.md for detailed setup instructions, testing guide, and development workflow.
This project is licensed under the MIT License — see the LICENSE file for details.
⭐ Star this repo if you find it useful! It helps others discover this lightweight solution.
How can I help you explore Laravel packages today?