CodeIgniter Forums
creating model vs creating library, composer and vendor folder - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: External Resources (https://forum.codeigniter.com/forumdisplay.php?fid=7)
+--- Forum: Addins (https://forum.codeigniter.com/forumdisplay.php?fid=13)
+--- Thread: creating model vs creating library, composer and vendor folder (/showthread.php?tid=67599)



creating model vs creating library, composer and vendor folder - sneakyimp - 03-13-2017

I'm converting an old custom class that makes use of a mostly-abandoned php-opencloud SDK from rackspace. The original instructions were to add some use statements and then require one file:
Code:
use OpenCloud\ObjectStore\ObjectStoreBase;
use OpenCloud\ObjectStore\ObjectStoreCDN;
// get the rackspace/OpenCloud library
require_once "opencloud/lib/php-opencloud.php"; // where should I put this file?
Then you could start using the library.

I'm wondering how to best make use of this library in my CodeIgniter project. I've noticed that many SDKs (paypal, authorize.net, others) are using Composer these days so I'm guessing I might want to install a more recent version of the SDK but I've noticed that no one has committed any changes to that SDK in a year and I've also been told by Rackspace that there is no active development on any V2 version. I'd appreciate any advice folks may have on using these apparently abandoned SDKs.

More importantly, assuming I get the right library installed, where does it go? Do I put it in a subdir of the application/libraries folder? Seems like I'd need to write my own custom library class so $this->load->library("MyClass") has something to instantiate. Or should I create a Model class that just starts off with those use and require statements above?

Any assistance would be much appreciated.


RE: creating model vs creating library, composer and vendor folder - koficypher - 03-14-2017

Well sneakyimp, i cant tell you much about the opencloud sdk because i have not used it before neither can i tell if it will be compatible with the latest version of CI or PHP. But what i can show you is how to use composer with CI for any other package as well as opencloud sdk supposing it will work with the latest build of CI. Here follow these previous threads, here and here. They contain steps on how to use composer with CI and if youre new to using composer too look here. That will do it!!


RE: creating model vs creating library, composer and vendor folder - ivantcholakov - 03-14-2017

In such a situation, by instinct first I would install the package using Composer (v1 or v2, it your choice). Then, I would make a model in CI3 way, it would extend CI_Model. The application would use this model only, without direct usage of the package's stuff. If something needs to be changed in the future, that change would be isolated within the created model.

Code:
require_once "opencloud/lib/php-opencloud.php"; // where should I put this file?

I don't think you need this line, probably you can skip it. The Composer autoloader would be already active and it would do its job.


RE: creating model vs creating library, composer and vendor folder - sneakyimp - 03-23-2017

Thank you both for this advice. ivantcholakov, I have in fact isolated my code from the details of the library used. I always like my code to be buffered from any APIs I use by a class of my own devising.