CodeIgniter Forums
Load Interface? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Load Interface? (/showthread.php?tid=36181)



Load Interface? - El Forum - 11-24-2010

[eluser]ee99ee[/eluser]
Hi. I'm using $this->load->library() to load a class library, but how do I load an interface?

I tried:
Code:
$CI =& get_instance();
$CI->load->library('Billing/IBillingSystem');

But apparently that requires a class called IBillingSystem and not just an Interface, which is all that file has.

-Chris


Load Interface? - El Forum - 11-24-2010

[eluser]smilie[/eluser]
By interface you mean function name?

From User Guide:
Naming Conventions

File names must be capitalized. For example: Myclass.php
Class declarations must be capitalized. For example: class Myclass
Class names and file names must match.

See: http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html

So, either modify file and add class;

Or you can move file to the helpers - which do not require class.

Cheers,
Smilie


Load Interface? - El Forum - 11-24-2010

[eluser]ee99ee[/eluser]
No, I mean an interface

http://php.net/manual/en/language.oop5.interfaces.php


Load Interface? - El Forum - 11-24-2010

[eluser]techgnome[/eluser]
As far as I know, CI doesn't have a way to load interfaces. You can't load like a library because it isn't one. Not sure why you need an interface, but I'd think that simply using an include for the file should be sufficient.

-tg


Load Interface? - El Forum - 11-24-2010

[eluser]ee99ee[/eluser]
Well, we're trying to use good design patterns.... that's too bad it doesn't support it though. But alright. Thanks!


Load Interface? - El Forum - 11-24-2010

[eluser]TaylorOtwell[/eluser]
I usually setup an auto-loader to handle interfaces.

However, I just recently finished a DI framework and IoC container for CI 2.0 that I'm planning to release soon. I just need to tidy up a few things. With it, you can bind interfaces to implementations and let the IoC container resolve your dependencies for you.

And, if you want, with two lines of code in the CodeIgniter.php core file you can even let it build your controllers for you, allowing constructor injection on your controllers.

If your interested in getting your hands on it early, just let me know.