dbp/relay-template-bundle
Symfony bundle template for creating new Digital Blueprint relay bundles. Provides a starting structure, config, and CI setup for building relay integrations. Intended as a scaffold and typically not used directly in production projects.
Prerequisites:
relay-template-bundle as a dependency:
composer require dbp/relay-template-bundle
Enable the Bundle:
Add the bundle to your config/bundles.php:
return [
// ...
DigitalBlueprint\RelayTemplateBundle\RelayTemplateBundle::class => ['all' => true],
];
Generate a New Relay Bundle:
Use the provided command to scaffold a new bundle (replace YourBundle with your bundle name):
php bin/console make:relay-bundle YourBundle
This creates:
src/YourBundle/).ExampleResource).First Use Case:
Extend the generated ExampleResource to model your domain. For example:
src/YourBundle/Entity/YourEntity.php).src/YourBundle/Dto/YourEntityDto.php).src/YourBundle/Controller/YourEntityController.php) to handle business logic.Register Routes:
Add routing in config/routes/your_bundle.yaml:
your_bundle_example:
resource: |
alias: 'your_bundle.example'
path: '/example'
controller: 'YourBundle\Controller\ExampleController'
type: 'apiPlatform'
Test Locally: Run the Symfony server and test the API:
symfony serve
Access endpoints like http://localhost:8000/api/example.
Bundle Generation:
make:relay-bundle to create standardized bundles with:
@ORM\Entity).Resource Customization:
ExampleResource to fit your domain:
#[ApiResource(
collectionOperations: ['get', 'post'],
itemOperations: ['get', 'put', 'delete'],
shortName: 'your_entity'
)]
class YourEntity extends ExampleResource
{
// Override or add custom logic
}
State Processors:
src/YourBundle/Processor/YourEntityProcessor.php):
class YourEntityProcessor implements StateProcessorInterface
{
public function __invoke(Operation $operation, mixed $data, array $uriVariables): void
{
// Custom logic (e.g., validation, side effects)
}
}
services.yaml:
YourBundle\Processor\YourEntityProcessor:
tags: ['api_platform.state_processor']
Validation:
@Assert\NotBlank).class YourEntityDto
{
#[Assert\NotBlank]
public string $name;
#[Assert\Positive]
public int $value;
}
Event-Driven Workflows:
// src/YourBundle/EventListener/YourEntityListener.php
class YourEntityListener
{
public function onPostCreate(YourEntityEvent $event): void
{
// Handle post-create logic
}
}
services.yaml:
YourBundle\EventListener\YourEntityListener:
tags: ['kernel.event_listener', { event: 'your_bundle.example.post_create' }]
CRUD API Development:
ExampleResource → customize entity/DTO → register routes.Integration with Relay Gateway:
Testing:
WebTestCase for API tests:
class YourEntityTest extends WebTestCase
{
public function testGetExample(): void
{
$client = static::createClient();
$client->request('GET', '/api/example');
$this->assertResponseIsSuccessful();
}
}
Leverage API Platform Features:
Symfony Dependency Injection:
class YourEntityController
{
public function __construct(
private YourEntityManager $manager
) {}
}
Database Migrations:
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
Documentation:
php bin/console api:docs:generate
CI/CD:
# .github/workflows/test.yml
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: composer install
- run: phpstan analyse src --level=5
- run: phpunit
Symfony vs. Laravel Conflicts:
PHP Attribute Migration:
@ORM\Entity) won’t work with PHP attributes.doctrine/annotations as a bridge or migrate to attributes:
composer require doctrine/annotations
API Platform Version Mismatch:
composer require api/api-platform-core:^4.0
Event System Differences:
EventDispatcher or create a wrapper for Laravel’s events.Doctrine vs. Eloquent:
doctrine/dbal.Service Container Conflicts:
Testing Environment:
WebTestCase may not work seamlessly with Laravel’s testing helpers.Enable Debug Mode:
APP_DEBUG=true in .env for detailed error messages:
APP_DEBUG=1
Symfony Profiler:
php bin/console debug:container YourBundle\Service\YourService
Log Configuration:
config/packages/monolog.yaml:
monolog:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
Dependency Dumping:
php bin/console cache:clear
composer dump-autoload
API Platform Debug:
php bin/console debug:api
How can I help you explore Laravel packages today?