video-games-records/igdb-bundle

VideoGamesRecords IgdbBundle

Installs: 1

Dependents: 1

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

Type:symfony-bundle

pkg:composer/video-games-records/igdb-bundle

dev-dev 2025-10-10 20:31 UTC

This package is auto-updated.

Last update: 2025-10-10 20:31:22 UTC


README

A Symfony bundle that provides IGDB (Internet Game Database) integration for the VideoGamesRecords application. This bundle facilitates data retrieval from the IGDB APIs using the kris-kuiper/igdbv4 package and provides Sonata Admin interfaces for managing IGDB data.

Features

  • 🎮 IGDB API Integration using kris-kuiper/igdbv4 package
  • 🏗️ Symfony 7.2+ Compatibility with modern PHP 8.4+
  • 🔧 Auto-configured Services with dependency injection
  • 📊 Sonata Admin Interfaces for all IGDB entities (read-only)
  • 🌍 Multi-language Support (French/English) with complete translations
  • 🛡️ Security-first Approach with read-only admin interfaces
  • 📝 JMS Serializer Configuration for API responses
  • Command-line Tools for data import from IGDB
  • 🎨 Custom Twig Templates for enhanced admin display

Requirements

  • PHP: 8.4+
  • Symfony: 7.2+
  • Doctrine ORM: 3.3+
  • Sonata Admin Bundle: For admin interfaces (optional)
  • JMS Serializer Bundle: For API serialization

Installation

Install the bundle via Composer:

composer require video-games-records/igdb-bundle

Add the bundle to your config/bundles.php:

return [
    // ...
    VideoGamesRecords\IgdbBundle\VideoGamesRecordsIgdbBundle::class => ['all' => true],
];

Configuration

Configure your IGDB API credentials in config/packages/video_games_records_igdb.yaml:

video_games_records_igdb:
    client_id: '%env(IGDB_CLIENT_ID)%'
    client_secret: '%env(IGDB_CLIENT_SECRET)%'

Add your credentials to .env:

IGDB_CLIENT_ID=your_client_id
IGDB_CLIENT_SECRET=your_client_secret

Entities

The bundle provides the following IGDB entities:

🎮 Game

  • Complete game information from IGDB
  • Relations to genres and platforms
  • Release date management
  • Version parent relationships

🏷️ Genre

  • Game genre classifications
  • Slug and URL management

🖥️ Platform

  • Gaming platform information
  • Generation and abbreviation data
  • Relations to platform types and logos

🔧 PlatformType

  • Platform type classifications
  • Console, PC, Mobile, etc.

🖼️ PlatformLogo

  • Platform logo images
  • Dimensions and image metadata
  • URL generation for different sizes

Contracts

GameInfoInterface

The bundle provides a GameInfoInterface contract that defines the essential methods for game information:

interface GameInfoInterface
{
    public function getName(): string;
    public function getSlug(): string;
    public function getGenres(): Collection;
    public function getReleaseDate(): ?DateTime;
    public function getSummary(): ?string;
    public function getStoryline(): ?string;
    public function getUrl(): ?string;
}

This interface can be implemented by other game entities in your application to ensure consistency across different game data sources (IGDB, manual entries, etc.).

Linking to IGDB Games

To create a relationship between your custom game entities and IGDB games, add a ManyToOne relation in your entity:

use VideoGamesRecords\IgdbBundle\Entity\Game as IgdbGame;

class YourGameEntity implements GameInfoInterface
{
    #[ORM\ManyToOne(targetEntity: IgdbGame::class)]
    #[ORM\JoinColumn(name: 'igdb_game_id', referencedColumnName: 'id', nullable: true)]
    private ?IgdbGame $igdbGame = null;

    public function getIgdbGame(): ?IgdbGame
    {
        return $this->igdbGame;
    }

    public function setIgdbGame(?IgdbGame $igdbGame): self
    {
        $this->igdbGame = $igdbGame;
        return $this;
    }

    // Implement GameInfoInterface methods...
}

## Available Commands

### Data Import Commands

Import data from IGDB API:

```bash
# Search and import games
php bin/console app:search-and-import-games

# Import genres
php bin/console app:import-genres

# Import platforms
php bin/console app:import-platforms

# Import platform types
php bin/console app:import-platform-types

# Import platform logos
php bin/console app:import-platform-logos

Development Commands

Installation and Setup

composer install    # Install dependencies
composer update     # Update dependencies

Testing

./vendor/bin/simple-phpunit    # Run PHPUnit tests
make test                      # Run tests (via Makefile)

Code Quality

make phpstan      # Run PHPStan static analysis (level 5)
make phpcs        # Run PHP CodeSniffer (PSR-12 standard)
make phpcs-fix    # Auto-fix PHP CodeSniffer issues
make lint         # Run all linting tools

Admin Interfaces (Optional)

The bundle provides read-only Sonata Admin interfaces for all entities if Sonata Admin Bundle is installed:

  • Games Admin: /admin/igdb/game/list
  • Genres Admin: /admin/igdb/genre/list
  • Platforms Admin: /admin/igdb/platform/list
  • Platform Types Admin: /admin/igdb/platform-type/list
  • Platform Logos Admin: /admin/igdb/platform-logo/list

Security Features

  • Read-only interfaces - No create/edit/delete actions
  • Route-level protection - Dangerous routes are removed
  • Data integrity - IGDB data cannot be modified
  • Comprehensive filtering - Advanced search capabilities

Translations

Admin interfaces support multiple languages:

  • 🇫🇷 French (fr)
  • 🇬🇧 English (en)

All labels, filters, and messages are fully translated.

Installation with Admin Support

To enable admin interfaces, install Sonata Admin Bundle:

composer require sonata-project/admin-bundle
composer require sonata-project/doctrine-orm-admin-bundle

The admin interfaces will be automatically available once Sonata Admin is installed and configured.

API Serialization

The bundle includes JMS Serializer configuration for API responses:

Serialization Groups

Each entity has specific serialization groups:

  • igdb-game:read - Game data
  • igdb-genre:read - Genre data
  • igdb-platform:read - Platform data
  • igdb-platform-type:read - Platform type data
  • igdb-platform-logo:read - Platform logo data

Usage Example

use JMS\Serializer\SerializerInterface;

class GameController
{
    public function getGame(Game $game, SerializerInterface $serializer): JsonResponse
    {
        $json = $serializer->serialize($game, 'json', [
            'groups' => ['igdb-game:read']
        ]);
        
        return new JsonResponse($json, 200, [], true);
    }
}

Architecture

Bundle Structure

src/
├── Admin/                  # Sonata Admin classes
├── Client/                 # IGDB API client
├── Command/                # Console commands
├── Contract/               # Interfaces
├── DependencyInjection/    # Service configuration
├── Endpoint/               # API endpoints
├── Entity/                 # Doctrine entities
├── Repository/             # Doctrine repositories
└── Resources/
    ├── serialization/      # JMS Serializer config
    ├── translations/       # Multi-language support
    └── views/              # Custom Twig templates

Service Configuration

  • Auto-wired services via config/services.yml
  • Auto-discovery of services in src/ directory
  • PSR-4 autoloading with namespace VideoGamesRecords\IgdbBundle\
  • Automatic Twig namespace registration for templates

Code Standards

  • PHP Version: 8.4+
  • Code Style: PSR-12 (enforced via phpcs.xml)
  • Static Analysis: PHPStan level 5
  • Framework: Symfony 7.2+
  • Documentation: PHPDoc annotations

Development

Adding New Entities

  1. Create the entity in src/Entity/
  2. Add the admin class in src/Admin/
  3. Configure the admin service in config/admin.yml
  4. Add serialization config in src/Resources/serialization/
  5. Add translations in src/Resources/translations/

Custom Templates

Custom Twig templates are available in src/Resources/views/Admin/:

  • list_unix_timestamp.html.twig - For Unix timestamp display
  • show_unix_timestamp.html.twig - For detailed Unix timestamp display
  • show_collection.html.twig - For entity collections display

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Follow PSR-12 coding standards
  4. Add tests for new functionality
  5. Run the test suite (make test)
  6. Run code quality tools (make lint)
  7. Commit your changes (git commit -m 'Add amazing feature')
  8. Push to the branch (git push origin feature/amazing-feature)
  9. Open a Pull Request

License

This bundle is part of the VideoGamesRecords project.

Support

For issues and questions:

  • Create an issue in the project repository
  • Check the VideoGamesRecords documentation
  • Review IGDB API documentation

Made with ❤️ for the VideoGamesRecords community