Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Symfony Aware

Symfony Aware Laravel Package

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.

View on GitHub
Deep Wiki
Context7

At a glance

Frequently asked questions about Symfony Aware
Can I use this package in Laravel without Symfony components?
Yes, but with manual setup. The package provides traits like `EntityManagerAwareTrait` that work with Laravel’s Service Container if you map Symfony service IDs (e.g., `@doctrine.orm.default_entity_manager`) to Laravel’s bindings (e.g., `db`). You’ll need to create a custom service provider to bridge the gap.
Does this work with Laravel’s Eloquent ORM?
No, this package is designed for Symfony’s Doctrine ORM (EntityManager). Eloquent uses Laravel’s query builder, not EntityManager, so you’d need a custom adapter or wrapper to integrate it. Consider Laravel’s native `app()->make()` or `resolve()` for Eloquent.
How do I install and configure this for Laravel?
Run `composer require adtechpotok/symfony-aware`, then bind Symfony service IDs to Laravel’s container in a service provider. For example, alias `@doctrine.orm.default_entity_manager` to `db` in `register()`. Use the traits in your classes and configure services in `config/services.php` with `calls:` or autowire.
Will this work with Laravel 10 and PHP 8.2?
Unlikely out-of-the-box—the package hasn’t been updated since 2018. You may need to fork it or use a compatibility layer (e.g., PHP 8.1 polyfills) to avoid deprecation warnings. Test thoroughly, as Symfony’s DI container differs from Laravel’s.
Is there a performance impact from using these traits?
Minimal. Traits add negligible overhead, but manual service injection (e.g., `setEntityManager`) can complicate dependency graphs. For autowired services, the impact is similar to Laravel’s native DI. Profile your app to confirm, especially in high-traffic areas.
How do I mock these traits in PHPUnit tests?
Use Mockery or PHPUnit’s mock builder to inject dependencies directly into your class’s constructor or setter methods. For example, mock `EntityManager` and pass it to `setEntityManager()` in your test setup. Avoid mocking the trait itself—focus on the injected service.
What’s the difference between this and Laravel’s native `app()->make()`?
This package enforces explicit dependency injection via `set*()` methods and interfaces, making dependencies clearer and IDE-friendly. Laravel’s `app()->make()` is dynamic and less strict. Use this for large-scale apps or when you need Symfony-style DI conventions.
Can I use this with Laravel’s cache or database services?
Yes, but you’ll need to manually bind Laravel’s services (e.g., `cache`, `db`) to Symfony’s expected IDs (e.g., `@cache.app`, `@doctrine.dbal.default_connection`) in a service provider. The package’s mapping table helps identify the correct IDs.
Is this package actively maintained?
No, the last release was in 2018. While the core traits are stable, you’ll need to handle compatibility with newer Laravel/PHP versions yourself. Consider forking the repo or using alternatives like `symfony/dependency-injection` for long-term projects.
How do I migrate from Laravel’s native DI to this package?
Start by refactoring one class to use a trait (e.g., `EntityManagerAwareTrait`). Update your service definitions in `config/services.php` to include Symfony-style bindings with `calls:`. Gradually replace `app()->make()` calls with trait-based injection, testing each step.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware