DDD Symfony / Doctrine库 - 安全用户需要用户接口

发布于 2025-02-12 18:38:54 字数 1306 浏览 2 评论 0原文

标题基本上是什么意思:

tldr;我的用户模型与 Application 层没有任何关系,需要使用UserInterface(Symfony类)才能使Symfony Security工作。

我的设置如下:

app/
...
src/
vendor/

“ app”包含所有使用“ src”“ src”“ src”的所有“域”相关代码的纯符号代码,

其中包含一个具有类似结构的域:

DomainName/Application
DomainName/Domain
DomainName/Infrastructure

“用户”模型(普通的旧php域名/域中定义的对象)不应从应用程序层实现/扩展代码。但是我无法工作。我研究了扩展并提供“不同的”用户模型(来自“ app”内部)和绘制学说的典范,但是我的模型有太多的关系,无法使用。

这个设置甚至可能是可能的,还是我应该接受这是唯一要走的方法? :(

nb:我希望有点清楚我要实现的目标,很难解释。

完整的示例布局:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

◇流星雨 2025-02-19 18:38:54

有点旧的话题,但是对于其他将要面对类似问题的人,我在当前项目中遇到的情况完全相同,我通过创建域用户模型和基础架构中解决了它,我创建了SecurityUser模型,并且用户模型的依赖性来自域名,因此我能够使用我的域用户验证。在自定义用户提供商中,我是ReTurnig Securityuser,并从存储库中获取了注入的域用户。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文