Composer? Topic is solved

For Joomla! 4.x Coding related discussions, you could also use: http://groups.google.com/group/joomla-dev-general

Moderators: ooffick, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
MarkRS
Joomla! Explorer
Joomla! Explorer
Posts: 329
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

Composer?

Post by MarkRS » Mon May 23, 2022 10:57 am

My component needs to use Google libraries (pub/sub, Firebase, &tc), and I expect it's foolish to simply package those into my extension installation file and that I should do it using composer, but exactly how? I've found articles talking about how it's a good idea, but not exactly how to do it.

I imagine I should set up a composer.json file, is that right? And if so, where?
It's a community, the more we all contribute, the better it will be.

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 24985
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: Composer?

Post by pe7er » Mon May 23, 2022 11:26 am

Yes, I could add the composer files to your own extension folder.
In your own extension folder do a

Code: Select all

composer require vendor-name/package-name
It will generate the composer.json file, the /vendor/autoload.php and the files in /vendor/composer/*

In your extension, you do a

Code: Select all

require __DIR__ . '/vendor/autoload.php';
use \Vendor-name\PackageName;
so you can use the class from the included library added by composer.

PS: I've copied this solution from https://joomla.stackexchange.com/a/26521/13472 where I posted it earlier.
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

MarkRS
Joomla! Explorer
Joomla! Explorer
Posts: 329
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

Re: Composer?

Post by MarkRS » Mon May 23, 2022 12:57 pm

Hi Pe7er,

Yes, I saw your post, and looked at your github stuff, but I am still, sadly, a little confused.

Where does that go in my installable extension file? The vendor directory can't be straight off the component directory in the J4 scheme of things, can it?

And all the, quite extensive, vendor code, does it go in the extension folder or should it get installed to the libraries/vendor area.. errr... somehow?
It's a community, the more we all contribute, the better it will be.

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 24985
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: Composer?

Post by pe7er » Mon May 23, 2022 1:13 pm

Do not put the composer files that you need in Joomla's /libraries/vendor/ !
When you do a "composer install" or "composer update" in Joomla itself, it will update all packages that Joomla uses which could change Joomla's behavior. You need to keep Joomla original and use composer only in your own extension.

Let's assume that your component's name is com_something.
In the /administrator/components/com_something/ folder you should use composer to install some packages (e.g. the ones you find at https://packagist.org/ ) using:

Code: Select all

composer require some-dev-name/some-package-installed-via-composer/
composer require another-dev-name/another-package-installed-via-composer/
You will get some new files/folders in your component:
  • /administrator/components/com_something/composer.json
  • /administrator/components/com_something/vendor/autoload.php
  • /administrator/components/com_something/vendor/some-dev-name/some-package-installed-via-composer/
  • /administrator/components/com_something/vendor/another-dev-name/another-package-installed-via-composer/
To make your component installable to other websites, you'll need to add some lines for the composer stuff to your component manifest file /administrator/components/com_something/com_something.xml

Code: Select all

<files>
        <file>composer.json</file>
        <folder>vendor</folder>
</files>
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

MarkRS
Joomla! Explorer
Joomla! Explorer
Posts: 329
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

Re: Composer?

Post by MarkRS » Mon May 23, 2022 1:19 pm

That's cleared up my confusion. Many thanks!
It's a community, the more we all contribute, the better it will be.

User avatar
pe7er
Joomla! Master
Joomla! Master
Posts: 24985
Joined: Thu Aug 18, 2005 8:55 pm
Location: Nijmegen, Netherlands
Contact:

Re: Composer?

Post by pe7er » Mon May 23, 2022 1:27 pm

You're welcome!
Kind Regards,
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com

MarkRS
Joomla! Explorer
Joomla! Explorer
Posts: 329
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

Re: Composer?

Post by MarkRS » Fri May 27, 2022 9:54 am

Ok, another question on this, since I'm not very up on Composer.

I don't need to include the actual vendor files in my package, do I?
I expect it makes life easier (in terms of easy packaging and installation), but it can add a huge amount to the installation package. There are over 11,600 files (30Mb) in the Google pub/sub extension!

This is an "in house" component, so needing some manual intervention isn't a disaster.

If this is the case presumably I'd need to run "composer install" at the installed site? (Mmm, that's starting to get tricky I suppose on a normal hosted site...)
It's a community, the more we all contribute, the better it will be.

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2906
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Composer?

Post by SharkyKZ » Fri May 27, 2022 11:26 am

You got it right. For your own purposes you can do whatever you want. But if you intend to distribute it, you should really make it installable with a "single click" ZIP upload. Joomla isn't really designed to work with Composer.
I don't know which library you are talking about but make sure you only include code files and not development files.

MarkRS
Joomla! Explorer
Joomla! Explorer
Posts: 329
Joined: Thu Oct 29, 2009 8:28 am
Location: UK

Re: Composer?

Post by MarkRS » Fri May 27, 2022 1:53 pm

It's the libraries for handling notifications of purchases through the Google store. It doesn't look like it has development stuff too, but I haven't looked very far through the eleven and a half thousand files :/

I thought large parts of Joomla are actually *built* with Composer. I can see it's not built for the rest of us to work with Composer though :(
It's a community, the more we all contribute, the better it will be.


Locked

Return to “Joomla! 4.x Coding”