1

bit of a theory question this one. I would like to write my own library for codeigniter. It's going to be from connecting to different british Accountancy packages via API's. If it were a single package I was writing it for then I could create the library easily, however, it will be multiple. I intend to load the library as follows:

$params = array('package' => 'quickbooks');

$this->load->library('accountancy', $params);

Through my research so far, each API does not offer the same functionality therefore my library will have to be able to disable/enable functions based on the selected package. Also, the api's are different so each function will have to work differently based on the selected package also.

Firstly, is a library the best course of action?

Does anyone have any tutorials they can point me to or anything else to help?

Not looking for someone else to write it for me, just looking to be pointed in the right direction.

Thanks

user1530205
  • 302
  • 6
  • 19
  • Do the "API's" have *any* similar functions that can be shared across the packages? If not, then I probably wouldn't even make a *single* library, and just have a library/model for each package. If it is shared I would just bunch the shared functions into a base library that the specific packages extend and load those libraries separately as needed rather than using a master library to "switch" between packages. – Alex Feb 06 '18 at 23:33
  • It would be way more flexible if you created a composer package that was not specific to CodeIgniter. – Brian Gottier Feb 07 '18 at 00:28
  • I actually considered the composer package structure as ive seen Omnipay in the past and that acts in a very similar way to what I want. I may have a look at this again, as a potential answer, although I have looked for Omnipay source code to give me a starting point but struggled to find something – user1530205 Feb 07 '18 at 10:31

1 Answers1

2

There are probably multiple solutions.

If what you need to accomplish can be conceived as an abstraction layer (which means that, regardless of which accounting package you're using, you use the same functions to get things done) then using the "Drivers" approach might work.

First, check out the CI documentation for Using CodeIgniter Drivers.

CI uses the driver pattern for the cache, database and session classes. Studying that source code may prove helpful. Cache.php might be the easiest to get your head around to start with.

Via Google I found one Codeigniter Drivers Tutorial and I'm pretty sure the Stack Overflow has some info too.

Here's another example of using CI drivers.

I confess that I didn't look at either tut very closely. So I'm not certain how helpful they will be.

DFriend
  • 8,869
  • 1
  • 13
  • 26
  • actually your last link (https://code.tutsplus.com/tutorials/how-to-create-custom-drivers-in-codeigniter--cms-29339) shows a really nice and helpful example how to implement drivers, thanks for the find... – Vickel Feb 07 '18 at 00:48
  • Appreciate it thanks, I'll take a look shortly and come back to you. – user1530205 Feb 07 '18 at 10:27