tourze/doctrine-entity-routing-bundle

Symfony bundle for automatic Doctrine entity routing

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

pkg:composer/tourze/doctrine-entity-routing-bundle

0.0.1 2025-05-24 17:08 UTC

This package is auto-updated.

Last update: 2025-11-01 19:14:08 UTC


README

English | 中文

Latest Version PHP Version Require License Total Downloads Code Coverage

A Symfony Bundle that automatically generates REST API routes for Doctrine entity metadata inspection.

Features

  • Automatically discovers all Doctrine entities in your application
  • Generates REST API endpoints for entity metadata inspection
  • Provides JSON responses with table structure information
  • Supports environment-based route generation control
  • Includes comprehensive test coverage

Installation

composer require tourze/doctrine-entity-routing-bundle

Configuration

Register the Bundle

Add the bundle to your config/bundles.php:

return [
    // ... other bundles
    Tourze\DoctrineEntityRoutingBundle\DoctrineEntityRoutingBundle::class => ['all' => true],
];

Enable Route Generation

Set the environment variable to enable route generation:

# .env
ENTITY_METADATA_ROUTES=enabled

Add Route Loader

Add the route loader to your config/routes.yaml:

entity_routes:
    resource: .
    type: entity_route

Usage

Once configured, the bundle will automatically generate routes for all your Doctrine entities.

API Endpoints

For each entity table, the bundle generates:

GET /entity/desc/{table_name}

Example Response

{
  "table": "user",
  "columns": [
    {
      "field": "id",
      "type": "integer",
      "length": null,
      "nullable": false
    },
    {
      "field": "email",
      "type": "string",
      "length": 255,
      "nullable": false
    },
    {
      "field": "name",
      "type": "string",
      "length": 100,
      "nullable": true
    }
  ]
}

Error Response

If the table is not found:

{
  "error": "Table not found"
}

Requirements

  • PHP 8.1+
  • Symfony 6.4+
  • Doctrine ORM 3.0+
  • Doctrine Bundle 2.13+

Dependencies

  • tourze/symfony-routing-auto-loader-bundle - For automatic route loading
  • Standard Symfony and Doctrine components

Testing

Run the test suite:

./vendor/bin/phpunit packages/doctrine-entity-routing-bundle/tests

Run PHPStan analysis:

php -d memory_limit=2G ./vendor/bin/phpstan analyse packages/doctrine-entity-routing-bundle

How It Works

  1. Route Discovery: The AttributeControllerLoader automatically discovers all Doctrine entities
  2. Route Generation: For each entity table, it generates a REST endpoint
  3. Controller: The EntityMetadataController handles requests and returns JSON metadata
  4. Environment Control: Routes are only generated when ENTITY_METADATA_ROUTES is set

Architecture

  • AttributeControllerLoader: Implements RoutingAutoLoaderInterface to automatically generate routes
  • EntityMetadataController: Handles API requests and returns JSON metadata
  • Integration: Works with tourze/symfony-routing-auto-loader-bundle for seamless route loading

Contributing

Please see CONTRIBUTING.md for details on how to contribute to this project.

Changelog

Please see CHANGELOG.md for details on what has changed recently.

License

The MIT License (MIT). Please see LICENSE file for more information.