connectx/entity-angular-bundle
Installation
Run composer require connectx/entity-angular-bundle in your Symfony 4 project root.
If using Symfony Flex, the bundle auto-enables. For older setups, manually enable it in AppKernel.php.
First Generation
Execute php bin/console cx:gen:ts in the project root.
Generated Angular TypeScript files appear in /angular/ (created automatically).
Verify Output Check the generated files for:
id: number, name: string).getId(), setName()).Frontend Integration
.ts files to your Angular project’s src/app/models/ folder.import { User } from '../../models/User';
Entity-Driven Development
# Example workflow step
php bin/console doctrine:migrations:migrate
php bin/console cx:gen:ts
Partial Generation
config/packages/cx_entity_angular.yaml:
cx_entity_angular:
output_dir: '%kernel.project_dir%/src/app/shared/models'
entities:
- App\Entity\User
- App\Entity\Product
Custom Templates
vendor/connectx/entity-angular-bundle/Resources/templates/) to config/packages/cx_entity_angular/templates/ and modify them.Service Layer Abstraction Generate a base service interface alongside models:
// Generated via custom template
export interface UserService {
getUsers(): Observable<User[]>;
saveUser(user: User): Observable<User>;
}
Implement this in Angular with HttpClient.
Form Integration
Use generated interfaces with Angular’s FormBuilder:
this.userForm = this.fb.group({
id: [null],
name: ['', Validators.required]
});
API Response Handling Map API responses to generated interfaces:
this.http.get<User[]>('/api/users').subscribe(users => {
this.users = users;
});
Outdated Dependencies
symfony/console, doctrine/orm).Namespace Collisions
AppEntityUser).User) or configure output paths per namespace.Circular Dependencies
User has ManyToOne to Role), the generated files may fail to compile.No Angular-Specific Features
@Input(), @Output()).serializedName for JSON serialization).Check Generation Logs
Run with -vvv for verbose output:
php bin/console cx:gen:ts -vvv
Look for skipped entities or template errors.
Template Debugging
Enable debug mode in config/packages/cx_entity_angular.yaml:
cx_entity_angular:
debug: true
This may dump template variables to the console.
Custom Field Mappings
{# Override default type mapping #}
{% set typeMap = {
'integer': 'number',
'string': 'string',
'datetime': 'Date',
'array': 'any[]'
} %}
Add Angular Decorators Modify the template to include decorators:
export interface {{ interfaceName }} {
{% for property in properties %}
@Input() {{ property.name }}: {{ typeMap[property.type] }}{% if property.nullable %} | null{% endif %};
{% endfor %}
}
Pre/Post-Generation Hooks Use Symfony’s event system to run logic before/after generation. Example:
// config/services.yaml
services:
App\EventSubscriber\AngularGenSubscriber:
tags:
- { name: kernel.event_subscriber }
// src/EventSubscriber/AngularGenSubscriber.php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use ConnectX\EntityAngularBundle\Event\PreGenerateEvent;
class AngularGenSubscriber implements EventSubscriberInterface {
public static function getSubscribedEvents() {
return [
PreGenerateEvent::NAME => 'onPreGenerate',
];
}
public function onPreGenerate(PreGenerateEvent $event) {
$event->addEntityExclusion('App\Entity\ExcludedEntity');
}
}
Symfony 5/6 Compatibility
composer.json to require newer Symfony components:
"require": {
"symfony/console": "^5.4|^6.0",
"symfony/dependency-injection": "^5.4|^6.0"
}
EntityAngularGenerator class to use modern DI.cache-busting timestamp to imports to avoid unnecessary rebuilds:
import { User } from '../../models/User?v=20230515';
cx_entity_angular:
entities:
- App\Entity\User
- App\Entity\Product
exclude:
- App\Entity\AuditLog
How can I help you explore Laravel packages today?