codemonkeys-ru/repository-alias-bundle
Pros:
$this->get('project.repo.blogpost') vs. $this->getDoctrine()->getRepository('AcmeBundle:Blog\Post')).newEntity()), improving developer ergonomics.Cons:
doctrine/orm.getDoctrine() service, which Laravel replaces with DB::connection() or entityManager().AppServiceProvider), but loses native getRepository() functionality.App\Repositories namespace.Repository pattern implementations.| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Deprecation | High | Evaluate if core functionality is reusable. |
| Symfony Dependencies | High | Abstract Symfony-specific code (e.g., getDoctrine()). |
| Laravel ORM Mismatch | Medium | Test with Laravel’s Doctrine bridge. |
| Performance Overhead | Low | Minimal; only adds container lookups. |
| Maintenance Burden | Medium | Fork and modernize if critical. |
Why not use Laravel’s native solutions?
Model::query() or app()->make('App\Repositories\UserRepository').entityManager->getRepository() is standard.Is Symfony’s DI container alignment worth the effort?
get() shortcut by default).app()->alias('project.repo.blogpost', BlogPostRepository::class)).What’s the fallback if integration fails?
Repository pattern (e.g., new BlogPostRepository()).Does the bundle support modern features?
Repository interfaces or app()->make().Assess Current Repository Usage:
Model::query(), getDoctrine()->getRepository()).Laravel-Specific Setup:
doctrine/orm and configure config/packages/doctrine.yaml.config/bundles.php (Symfony-style) or via a custom Laravel service provider.getDoctrine() to Laravel’s entityManager():
// In AppServiceProvider
$this->app->singleton('doctrine', function () {
return app('doctrine')->getManager();
});
RepositoryAliasManager) that maps keys to Eloquent models.$this->app->bind('project.repo.blogpost', function () {
return new BlogPostRepository(new BlogPost());
});
Configuration:
config.yml with Laravel’s config/repository_alias.php:
return [
'repository_key' => 'project.repo',
'repositories' => [
'blogpost' => 'App\Models\BlogPost',
'blogcomment' => 'App\Models\BlogComment',
],
];
// In a service or helper
public function getRepository(string $alias) {
return $this->app->make($alias);
}
Testing:
newEntity() and repository methods work.DependencyInjection may need mocking).Phase 1: Proof of Concept
RepositoryAlias::get('project.repo.blogpost')).Phase 2: Full Integration
getDoctrine()->getRepository() calls with aliases.Phase 3: Maintenance
Repository facade).ContainerAware).| Scenario | Impact | Mitigation |
|---|---|---|
| Bundle breaks with PHP 8.1+ | Integration fails | Fork and patch. |
| Doctrine/Laravel version conflict | Repository access fails | Fallback to entityManager->getRepository(). |
| Misconfigured aliases | ServiceNotFoundException |
Validate config on boot. |
| Abandoned upstream | No security updates | Monitor for CVEs; replace if needed. |
app()->make()).How can I help you explore Laravel packages today?