肿胀的疙瘩容器 - 这正常吗?
Bloated Pimple Container - Is this normal?
所以我刚刚将 Pimple 集成到一个项目中,我现在的情况是我有一个文件位于:
/application/config/pimple.php
其中有 400 多个:
/* Instantiate new Class */
$this->container['Some_class'] = $this->container->factory(function ($c)
{
require_once "application/classes/some/class.php";
return new Class();
});
我的问题是:这是常态吗?我应该担心这个吗?有更好的方法吗?
Should I be concerned about this?
嗯,不。你可以处理它。框架 Silex uses Pimple as service container as well. But Pimple is a small dependency injection container. 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 组件。这样您就可以在配置文件中描述您的 DIC 行为,例如:
parameters:
# ...
mailer.transport: sendmail
services:
mailer:
class: Mailer
arguments: ["%mailer.transport%"]
newsletter_manager:
class: NewsletterManager
calls:
- [setMailer, ["@mailer"]]
注意:建议注册自动加载器而不是手动包含 class。
所以我刚刚将 Pimple 集成到一个项目中,我现在的情况是我有一个文件位于:
/application/config/pimple.php
其中有 400 多个:
/* Instantiate new Class */
$this->container['Some_class'] = $this->container->factory(function ($c)
{
require_once "application/classes/some/class.php";
return new Class();
});
我的问题是:这是常态吗?我应该担心这个吗?有更好的方法吗?
Should I be concerned about this?
嗯,不。你可以处理它。框架 Silex uses Pimple as service container as well. But Pimple is a small dependency injection container. 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 组件。这样您就可以在配置文件中描述您的 DIC 行为,例如:
parameters:
# ...
mailer.transport: sendmail
services:
mailer:
class: Mailer
arguments: ["%mailer.transport%"]
newsletter_manager:
class: NewsletterManager
calls:
- [setMailer, ["@mailer"]]
注意:建议注册自动加载器而不是手动包含 class。