calliostro/discogs-bundle

Bundle around the Discogs API client for Symfony 6.4, Symfony 7 and Symfony 8

v3.1.1 2025-08-22 11:07 UTC

This package is auto-updated.

Last update: 2025-08-22 11:20:16 UTC


README

Build Status Version License

🚀 Easy integration of calliostro/php-discogs-api into Symfony 6.4+, 7, and 8!

📚 For more about the Discogs API, visit Discogs Developers.

⚡ Requirements

  • PHP: 8.1 or higher
  • Symfony: 6.4, 7.x, or 8.x

📦 Installation

Symfony Flex (Recommended)

composer require calliostro/discogs-bundle

Without Symfony Flex

1️⃣ Install the Bundle

composer require calliostro/discogs-bundle

2️⃣ Register the Bundle

Add to config/bundles.php:

// config/bundles.php
return [
    // ...existing bundles...
    Calliostro\DiscogsBundle\CalliostroDiscogsBundle::class => ['all' => true],
];

🎸 Usage

The bundle provides a DiscogsClient service for autowiring:

// src/Controller/MusicController.php
use Discogs\DiscogsClient;

class MusicController
{
    public function getArtist(DiscogsClient $discogs): Response
    {
        $artist = $discogs->getArtist(['id' => 8760]);

        return new JsonResponse([
            'name' => $artist['name'],
            'profile' => $artist['profile'] ?? null,
        ]);
    }
}

⚙️ Configuration

Create config/packages/calliostro_discogs.yaml:

# config/packages/calliostro_discogs.yaml
calliostro_discogs:
    # Required: HTTP User-Agent header for API requests
    user_agent: 'MyApp/1.0 +https://myapp.com'

    # Recommended: Your application credentials from discogs.com/applications
    consumer_key: ~
    consumer_secret: ~

    # Rate limiting configuration
    throttle:
        enabled: true
        microseconds: 1000000  # Wait time when the rate limit is hit

    # OAuth 1.0a authentication (for user-specific data)
    oauth:
        enabled: false
        token_provider: calliostro_discogs.hwi_oauth_token_provider

🔐 Authentication

Basic Authentication (Recommended)

Register your app at Discogs Applications to get:

  • consumer_key
  • consumer_secret

This enables access to protected endpoints and higher rate limits. 🚦

OAuth 1.0a (Optional)

For user-specific data, OAuth 1.0a is supported via HWIOAuthBundle:

# config/packages/calliostro_discogs.yaml
calliostro_discogs:
    oauth:
        enabled: true
        # token_provider: calliostro_discogs.hwi_oauth_token_provider  # Default, no need to specify

🛡️ Custom Token Provider

Implement OAuthTokenProviderInterface for custom OAuth token handling:

use Calliostro\DiscogsBundle\OAuthTokenProviderInterface;

class CustomTokenProvider implements OAuthTokenProviderInterface
{
    public function getToken(): string
    {
        // Return OAuth token
    }

    public function getTokenSecret(): string
    {
        // Return OAuth token secret
    }
}

📖 Documentation

🤝 Contributing

Found a bug or missing feature? Please create an issue or submit a pull request. Contributions welcome! 💡

🙏 Credits

This bundle is based on ricbra/RicbraDiscogsBundle for Symfony 2.