What the title basically means is this:
tldr; My User Domain model, which should not have any relation to the Application layer, needs the UserInterface (a Symfony class) for Symfony Security to work.
My setup is as follows:
app/
...
src/
vendor/
"app" contains all the pure Symfony code that uses all the "Domain" related code from "src"
"src" contains a Domain that has a structure like so:
DomainName/Application
DomainName/Domain
DomainName/Infrastructure
The "User" model (plain old php object) defined within DomainName/Domain SHOULD NOT implement/extend code from the Application layer. But I can't get it to work. I have looked into extending and providing a "different" User model (from within "app") and mappedSuperclasses of Doctrine, but my model has too many relations for that to work.
Is this setup even possible or should I accept this is the only way to go? :(
NB: I hope it is kinda clear what I'm trying to achieve, it's difficult to explain.
Full example layout:
app/
config/security.yaml
security:
...
providers:
app_user_provider:
entity:
class: DomainName\Domain\User
src/DomainName/Domain/User.php
- Nothing special, id, uuid, etc
src/DomainName/Domain/Repository/UserRepository.php
- This is an interface, because the domain does not contain the implementation
src/DomainName/Infrastructure/Persistence/Doctrine/Dbal/UserDbalRepository.php
- This implements the UserRepository, and the UserRepository will always be injected within "app"
src/DomainName/Infrastructure/Persistence/Doctrine/ORM/User.orm.yml
- This is the mapping ORM file for the Entity
A bit old topic, but for other people who will face similiar issue I had exactly same case in my current project, and I solved it by creating Domain User Model and in Infrastructure I have created SecurityUser model, with dependency of my User model from Domain, so I was able to use my Domain UserRepository eg. in custom user provider from which I was returnig SecurityUser, with injected Domain User fetched from repository.