So I've just integrated Pimple into a project and the situation I'm in now is that I have a file at:
/application/config/pimple.php
With 400+ of these in it:
/* 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. 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 component. With that you can describe your DIC behaviour in a configuration file, example:
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.