How to integrate external libraries in Joomla?

1,295 views
Skip to first unread message

Alejandro Arroyave

unread,
Jun 21, 2016, 8:40:41鈥疨M6/21/16
to Joomla! General Development
Hello,

I want to integrate Whoops (https://github.com/filp/whoops) and Kint (https://github.com/raveren/kint/) as libraries, for use it in my custom component. What's the correct way?

I read the article "Using own library in your extensions" https://docs.joomla.org/Using_own_library_in_your_extensions but I don't understand how to apply it.

Viper

unread,
Jun 22, 2016, 1:34:20鈥疉M6/22/16
to Joomla! General Development
The "correct" way is not a clear question.
Documentation describe a way when you put your library(libraries) in root Joomla libraries folder and register these libraries to use in any extension via plugin event. But if you do not want it, or you want to store you libraries in component folder you can create a 'libraries' folder in you com_mycomponent folder and register in autoload via JLoader::register(). When put this in you main component file(e.g. mycomponent.php).

Allon Moritz

unread,
Jun 22, 2016, 2:20:00鈥疉M6/22/16
to joomla-de...@googlegroups.com

I would put a composer file into the admin part of your component and load the autoloader when you need the libraries.

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.
To post to this group, send email to joomla-de...@googlegroups.com.
Visit this group at https://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/d/optout.

Anibal

unread,
Jun 22, 2016, 7:25:05鈥疉M6/22/16
to Joomla! General Development
Hi,

I've been looking for an answer to a similar question to integrate a bunch of composer packages in an extension.

Until now, I've been loading libraries from the extension custom directory or from custom libraries installed in /libraries directory. Autoloading with Joomla Loader, FoF Loader or manually loading dependencies.

Composer packages can be re-packaged in any of these formats. However, it is an error-prone process and a waste of time for more than 1 or 2 libraries.

Composer offers a consistent view of packages and an autoloader. So, it is tempting to implement it in a local extension "vendor" folder.

In my current practice, I have a clean and consistent composer project with the required packages and dependencies. In a second step, I copy only the vendor folder into the extension, removing all the development assets (for example, documentation and test cases, that can add a lot of additional space. Apache聽log4php alone has 3.2 Mb). At the end, you have a controlled distribution of a set of libraries.

TIP: This slimmed down set must have a new autoloader definition to avoid the declaration of the full list of classes. To generate it:聽composer dump-autoload

REF: For more information about Joomla global "vendor" folder and a general discussion about the current development status:聽https://groups.google.com/forum/#!topic/joomla-dev-general/hYZz5JI8ZFA


Regards,
Anibal


Alejandro Arroyave

unread,
Jun 23, 2016, 7:50:42鈥疨M6/23/16
to Joomla! General Development
Hello Anibal,

Do you have any example in GitHub or anywhere?

PS:聽I express me better in spanish!聽馃槴

Anibal

unread,
Jun 24, 2016, 5:00:05鈥疉M6/24/16
to Joomla! General Development
Hi Alejandro,

I don't have an example. For instance, to implement聽guzzlehttp in your extension, you can run聽php composer.phar require guzzlehttp/guzzle聽in the root administration folder of your extension. Then, in your code:

defined('JPATH_MYTODO') || define('JPATH_MYTODO', JPATH_ADMINISTRATOR . '/components/com_mytodo');
defined('JPATH_MYTODO_VENDOR') || define('JPATH_MYTODO_VENDOR', JPATH_MYTODO . '/vendor');

...
require_once聽JPATH_MYTODO_VENDOR聽. '/autoload.php';

PS: you're expressing yourself fairly well ;-)

Best regards,

Alejandro Arroyave

unread,
Jun 28, 2016, 12:15:18鈥疉M6/28/16
to Joomla! General Development
Thank you for response.

But I have another doubt: Why not use the /libraries directory instead of component directory? Joomla has libraries/vendor/composer directory.

Regards,

Alejandro.

Anibal Sanchez

unread,
Jun 28, 2016, 1:44:22鈥疉M6/28/16
to joomla-de...@googlegroups.com

Hi Alejandro,

You can create your vendor folder in /libraries or inside your extension structure. It is a project internal definition.

On the other hand, /libraries/vendor directory is a Joomla's core folder. So, it cannot be modified. In the previous link, you can find a related discussion.

Regards,

--
You received this message because you are subscribed to a topic in the Google Groups "Joomla! General Development" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/joomla-dev-general/5HCEsUAWvE4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to joomla-dev-gene...@googlegroups.com.

Robert

unread,
Jul 3, 2016, 2:58:15鈥疨M7/3/16
to Joomla! General Development
This might help:聽https://github.com/JandBeyond/conferenceplus/tree/master/code/libraries/conferenceplus

adding libraries with composer and using it in a component, don't think it is a good way when developing a mass distributed extension because you can run into version compatibility problem when other extensions also load libraries聽

Allon Moritz

unread,
Jul 5, 2016, 4:59:38鈥疉M7/5/16
to joomla-de...@googlegroups.com
You will have that problem anyway, if you are loading it trough composer or not. I suggest to use composer as it is the most common way to load libraries nowadays.

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-gene...@googlegroups.com.

Alejandro Arroyave

unread,
Jul 20, 2016, 6:40:29鈥疨M7/20/16
to Joomla! General Development
I could to integrate the external libraries in Joomla. With your example and this example (https://github.com/phproberto/lib_sample) I could resolve it.

Thank you for help.
Reply all
Reply to author
Forward
0 new messages