7

I develop Joomla extensions since 2008. Just today, I realized that Joomla uses Composer and the Symfony framework within its core libraries. I had seen it in the past, but never really gave it a second thought.

I have a local test website with more than 20 of the world's most popular Joomla extensions and none of them uses the core Symfony to simplify even the smallest task. Only one of them uses Symfony, but includes it within its own custom libraries directory. So, I have the following questions:

  1. Can we use Symfony inside Joomla without creating our own libraries directory? If yes, how?
  2. Shouldn't we be able to just install additional Symfony components to the existing Symfony? If not, why can't we?
  3. Have you heard if something like that is planned for Joomla 4?
1

1 Answer 1

6

Joomla uses composer to add + maintain the added library files in /libraries/vendor/ Do not use Joomla's composer for your own composer libraries. That might update Joomla's composer libraries as well which makes Joomla different from the distributed version, so your Joomla website might behave differently then expected. Those composer libraries are only updated by the core maintainers when a new Joomla version is released.

Yes, you can use composer in your own Joomla extensions. Just add the composer files in your own extension folder. In your own extension folder do a

composer require vendor-name/package-name

and you will end up with a composer.json file, the /vendor/autoload.php and the files in /vendor/composer/*

In your extension, you do a

require __DIR__ . '/vendor/autoload.php';
use \Vendor-name\PackageName;

so you can use the class from the included library added by composer.

I've used this method to add an external library in my Joomla plugin: https://github.com/pe7er/plg_content_db8imageresize Note that the library that I used in my plugin is abandoned. However, you can still use the method that I used.

1
  • 1
    Thank you @pe7er for your answer! I am aware of this, I have done it myself and I think it works fine. However, the documentation I linked to, mentions: The Joomla! Project introduced Composer into Joomla 3.4 to easily manage library dependencies in both core and extensions. So, my question is mostly focused on using those core features, rather than including my own... Commented Dec 12, 2019 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.