SYMFONY仅为Datatype C Like struct创建全局类

发布于 2025-02-13 18:22:23 字数 277 浏览 1 评论 0原文

我目前正在Symfony 6.1开发一个应用程序。 我总是有一组相同的数据,该数据始终使用相同的格式。为此,我想创建一个类,该类使用此结构生成对象。 该课程应在全球上可用(例如Symfony服务),但允许创建我想要的尽可能多的实例。据我所知,Symfony Services仅在自动化时创建一个实例。 在不弄乱预期的同伴风格的情况下,在Symfony中做到这一点的最佳方法是什么?

class MyDatatype {
    public $foo;
    public $bar;
}

I am currently developing an APP in Symfony 6.1.
I have a always same Set of data, which is using always the same format. For this I want to create a class, which generates Objects using this structure.
This class should be globally available (like a Symfony Service) but allow to create as many Instances as I want to. Symfony Services as far as I know, only create one Instance while Autowiring.
What is the best way to do this in Symfony, without messing with the intended Symfony style?

class MyDatatype {
    public $foo;
    public $bar;
}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文