简体   繁体   English

P肿的imple容器-这正常吗?

[英]Bloated Pimple Container - Is this normal?

So I've just integrated Pimple into a project and the situation I'm in now is that I have a file at: 所以我刚刚将Pimple集成到一个项目中,现在的情况是我在以下位置有一个文件:

/application/config/pimple.php

With 400+ of these in it: 其中有400多个:

/* Instantiate new Class */
$this->container['Some_class'] = $this->container->factory(function ($c) 
{
    require_once "application/classes/some/class.php";
    return new Class();
});

My question is: Is this the norm? 我的问题是:这是规范吗? Should I be concerned about this? 我应该担心这个吗? Is there a better way of doing it? 有更好的方法吗?

Should I be concerned about this? 我应该担心这个吗?

Well, no. 好吧,不。 You can work with that. 可以使用它。 The framework Silex uses Pimple as service container as well. Silex框架也将Pimple用作服务容器。 But Pimple is a small dependency injection container. 但是Pimple是一个小的依赖项注入容器。 It is very good for small projects, but if your container grows up, you might want something different. 这对于小型项目非常有用,但是如果您的容器长大了,您可能会想要一些其他的东西。 If you look for something "better", look for the DependencyInjection's component. 如果您寻找“更好”的东西,请寻找DependencyInjection的组件。 With that you can describe your DIC behaviour in a configuration file, example: 这样,您可以在配置文件中描述DIC行为,例如:

parameters:
    # ...
    mailer.transport: sendmail

services:
    mailer:
        class:     Mailer
        arguments: ["%mailer.transport%"]
    newsletter_manager:
        class:     NewsletterManager
        calls:
            - [setMailer, ["@mailer"]]

Note : it is advisable to register an autoloader instead of include the class manually. 注意 :建议注册一个自动加载器,而不是手动包含该类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM