CodeIgniter Forums
Using a third party library without composer - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Using a third party library without composer (/showthread.php?tid=92608)



Using a third party library without composer - occitan - 03-17-2025

I would like to use this library in a controller but without installing it with composer. How do i go about that?
https://github.com/MaestroError/php-heic-to-jpg
Where do I put the library and how do I properly namespace it?

Does this look correct?

require APPPATH . 'ThirdParty/HeicToJpg/src/HeicToJpg.php';
use Maestroerror\HeicToJpg;


RE: Using a third party library without composer - InsiteFX - 03-17-2025

1) Place the Library in app\ThirdParty

2) Open app\Config\Autoload.php

3) Add the Library to the $classmap

4) 'LibraryName' => APPPATH . 'ThirdParty/Libraryname.php',

5) Top of Controller - Use Libraryname

6) 
PHP Code:
$library = new myLibrary(); 



RE: Using a third party library without composer - occitan - 03-17-2025

Okay awesome thank you!

I tried the above, do I need to include anything at the top of my Controller like the use keyword?
If I implement the class like this:


// autoload.php
PHP Code:
public $classmap = [
        'HeicToJpg' => APPPATH 'ThirdParty/HeicToJpg/src/HeicToJpg.php',
]; 

// Controller in a method
PHP Code:
$fileIsHeic HeicToJpg::isHeic($_FILES['image-input']['tmp_name']);

if (
$fileIsHeic) {
        Maestroerror\HeicToJpg::convert($_FILES['image-input']['tmp_name'])->saveAs($uploads_folder $filename '.jpg');


I get the error:
Error: Class "App\Controllers\HeicToJpg" not found


RE: Using a third party library without composer - JustJohnQ - 03-17-2025

Yes,

You need to add the class with the 'use' keyword.

Try adding:
PHP Code:
use LibraryName