Installation:
composer require calliostro/discogs-bundle
For Symfony projects, add the bundle to config/bundles.php:
Calliostro\DiscogsBundle\DiscogsBundle::class => ['all' => true],
Zero-Configuration Mode:
Use the DiscogsClient directly for public API access without configuration:
use Calliostro\DiscogsBundle\Client\DiscogsClient;
$client = new DiscogsClient();
$releases = $client->listReleases(['page' => 1, 'per_page' => 20]);
Basic Usage:
Leverage IDE autocomplete for method names (e.g., getArtist, searchDatabase). Example:
$artist = $client->getArtist(['id' => 123456]);
Type-Safe API Calls:
Use typed parameters with camelCase naming (e.g., listReleases(int $page, int $perPage)). The bundle validates inputs automatically.
Symfony Integration:
DiscogsClientInterface into services:
public function __construct(private DiscogsClientInterface $discogs) {}
config/packages/discogs.yaml for settings like API keys and rate limits.Authentication:
# config/packages/discogs.yaml
discogs:
auth:
token: '%env(DISCOGS_PAT)%'
Rate Limiting:
Integrate with Symfony’s RateLimiter component for granular control:
discogs:
rate_limiter:
enabled: true
limit: 30
interval: '1 minute'
$results = $client->searchDatabase('The Beatles', 'master');
listReleases(['page' => 1, 'per_page' => 50])).Breaking Changes:
getArtist instead of artistGet). Update all calls.// Old (v3.x)
$client->listReleases(['page' => 1]);
// New (v4.0.0)
$client->listReleases(page: 1);
Configuration:
config/packages/discogs.yaml structure is simplified but may differ from v3.x. Review the UPGRADE.md for specifics.Rate Limiting:
RateLimiter is configured if using custom limits.monolog:
handlers:
discogs:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.discogs.log"
level: debug
Custom Clients:
Extend DiscogsClient to add domain-specific methods:
class CustomDiscogsClient extends DiscogsClient {
public function getTopReleases(int $year): array {
return $this->listReleases(['year' => $year, 'sort' => 'released', 'order' => 'desc']);
}
}
Event Listeners: Use Symfony’s event dispatcher to intercept API calls (e.g., for caching or analytics):
$dispatcher->addListener(DiscogsEvents::REQUEST, function (DiscogsRequestEvent $event) {
// Pre-process request
});
Testing:
Mock DiscogsClientInterface for unit tests:
$mock = $this->createMock(DiscogsClientInterface::class);
$mock->method('getArtist')->willReturn(['id' => 123456, 'name' => 'Test Artist']);
How can I help you explore Laravel packages today?