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
Requires
- php: ^8.1
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^3.0
- psr/log: ^3|^2|^1
- symfony/config: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/doctrine-bridge: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-foundation: ^6.4
- symfony/http-kernel: ^6.4
- symfony/routing: ^6.4
- symfony/yaml: ^6.4 || ^7.1
- tourze/symfony-routing-auto-loader-bundle: 0.0.*
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-11-01 19:14:08 UTC
README
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
- Route Discovery: The
AttributeControllerLoaderautomatically discovers all Doctrine entities - Route Generation: For each entity table, it generates a REST endpoint
- Controller: The
EntityMetadataControllerhandles requests and returns JSON metadata - Environment Control: Routes are only generated when
ENTITY_METADATA_ROUTESis set
Architecture
- AttributeControllerLoader: Implements
RoutingAutoLoaderInterfaceto automatically generate routes - EntityMetadataController: Handles API requests and returns JSON metadata
- Integration: Works with
tourze/symfony-routing-auto-loader-bundlefor 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.