1

The IoC container is kind of a complex subject for me, and coming from a Codeigniter background (where you just could copy and paste a library and it worked by including it with include_once()), it's a difficult concept to wrap my head around.

I'm trying to use Graufette for my project and I think I need to use an IoC Container so I can load the library and use it. The thing is that:

  • I don't know where to put the library files
  • I don't know where to put the code that registers the IoC container
  • I don't know how to load libraries outside the libraries folder

According to Mr. Dayle Rees, you simply register the container in application/start.php and call it in your controllers with IoC::resolve(). The thing is that he doesn't specify where do you put the files to register (or if you can put the IoC::register() code elsewhere).

I don't go blindly and say "in the libraries folder" because, as I've seen, they get loaded automatically (and can be accessed statically). For Gaufrette, and other libraries (like SwiftMailer, but that's another story because there's a bundle for that), that is not the case.

Where can I put those files and load them with the IoC Container? Is it even necessary to do that?

AeroCross
  • 3,969
  • 3
  • 23
  • 30

1 Answers1

0

I just briefly looked at the read me for this library and to me it seems like you should drop it in to the libraries directory, or create vendor directory and drop it in there. From the looks of it you should be autoloading it. Once it's being autoloaded you can use the IoC to bind an instance of it and retrieve that instance every time instead of having to setup the library each and every time you want to use it.

Jason Lewis
  • 18,537
  • 4
  • 61
  • 64
  • Since you mentioned the vendor, I tried using Composer and it created the vendor folder. Since it's a PSR-0 compilant library, I used the Autoloader::namespace() method in start.php pointing to `vendor/knplabs/gaufrette/src/Gaufrette` and it loaded perfectly. Dunno if I need to use the IoC container tho, but `vendor` is the place to use! Thanks! – AeroCross Apr 27 '13 at 03:16