adtechpotok/symfony-aware
Symfony “aware” interfaces and traits for quickly injecting common services (EntityManager, Doctrine, cache, logger, kernel, request stack, etc.) into your classes. Works with explicit service calls or Symfony 3.3+ autowiring.
EntityManagerAwareTrait) mirrors Laravel’s accessor methods (e.g., app('db')) but is more explicit and type-safe. Useful for enforcing dependencies in legacy or large-scale Laravel apps.db, cache) or Eloquent ORM support, requiring manual mapping.doctrine/orm package).EntityManager equivalent, necessitating wrappers or adapters.ContainerAware trait could conflict with Laravel’s Illuminate\Contracts\Container\Container if not namespaced carefully.@doctrine.orm.default_entity_manager vs. Laravel’s db).make() vs. Symfony’s get()).setEntityManager) may complicate dependency graphs.app()->make())?bind() in AppServiceProvider) map to Symfony-style IDs?EntityManagerAware traits complicate unit tests?symfony/dependency-injection be considered?EntityManager support).EntityManagerAware).// app/Providers/SymfonyAwareServiceProvider.php
public function register()
{
$this->app->alias('doctrine.orm.default_entity_manager', 'db');
}
EntityManagerAwareTrait).config/services.php to include Symfony-style bindings:
# config/services.yaml (if using Laravel Mix)
services:
App\Services\SomeService:
calls:
- [setEntityManager, ['@doctrine.orm.default_entity_manager']]
class LaravelAwareContainer implements \Psr\Container\ContainerInterface {
public function get($id) {
return $this->app->make($this->mapSymfonyIdToLaravel($id));
}
}
doctrine/orm:^2.10).cache/db services to Symfony IDs.Mockery or PHPUnit to mock traits (e.g., __construct() injection).composer require doctrine/orm adtechpotok/symfony-aware
AppServiceProvider.$this->em is injectable).EntityManagerAwareInterface).app()->make() may achieve similar results with less boilerplate.bind() method for similar functionality:
$this->app->bind(EntityManagerInterface::class, function ($app) {
return $app->make('db')->connection()->getDoctrineSchemaManager()->getEntityManager();
});
| Risk | Mitigation Strategy |
|---|---|
| Service Unavailability | Use Laravel’s app()->bound() checks before injection. |
| Container Conflicts | Isolate Symfony DI in a separate namespace (e.g., SymfonyAware). |
| Trait Method Collisions | Prefix trait methods (e.g., symfonySetEntityManager). |
| Deprecation | Plan to migrate to symfony/dependency-injection if package is abandoned. |
EntityManager vs. Eloquent’s DB).How can I help you explore Laravel packages today?