CodeIgniter Forums
Integrate third party library like unirest.io/php.html - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Integrate third party library like unirest.io/php.html (/showthread.php?tid=67661)



Integrate third party library like unirest.io/php.html - burebista - 03-21-2017

How to integrate in codeigniter 3

third party library like http://unirest.io/php.html

without using composer

thank you


RE: Integrate third party library like unirest.io/php.html - ciadmin - 03-21-2017

Figured this out through experimentation Smile

1) Download the Unirest repo.
2) Copy its src folder into your application/libraries, resulting in Unirest.php and the Unirest folder there.
3) Modify application/libraries/Unirest.php, adding a bogus class to make CI happy
Code:
<?php

require_once dirname(__FILE__) . '/Unirest/Exception.php';
require_once dirname(__FILE__) . '/Unirest/Method.php';
require_once dirname(__FILE__) . '/Unirest/Response.php';
require_once dirname(__FILE__) . '/Unirest/Request.php';
require_once dirname(__FILE__) . '/Unirest/Request/Body.php';

// bogus class to make CI happy
class Unirest {
}
4) You should now be able to use the conventional CI loader ... $this->load->library('unirest'); and then use the package per the Unirest docs Big Grin


RE: Integrate third party library like unirest.io/php.html - burebista - 03-22-2017

worked great, thank you,

i thought all this files must be inside third_party, i was confused.
So any libraries , external, shoud go inside app../libraries/
regards


RE: Integrate third party library like unirest.io/php.html - ciadmin - 03-22-2017

Unirest could have been bundled as a package too, in which case it would have gone inside application/third_party.

If you write a *library* that wraps an external "package", that would go inside application/libraries.
If you write a *package* that wraps an external "package", that would go inside application/third_party.
These are two different ways of achieving a similar effect.

If the external "package" includes classes, models and views, it would be better as a *package*.
Unirest was simple enough that I kept it as a library.


RE: Integrate third party library like unirest.io/php.html - burebista - 03-22-2017

i got it now, thank you for the explanation