Composer? Topic is solved
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.
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.
-
- Joomla! Explorer
- Posts: 329
- Joined: Thu Oct 29, 2009 8:28 am
- Location: UK
Composer?
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?
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.
- pe7er
- Joomla! Master
- Posts: 24985
- Joined: Thu Aug 18, 2005 8:55 pm
- Location: Nijmegen, Netherlands
- Contact:
Re: Composer?
Yes, I could add the composer files to your own extension folder.
In your own extension folder do a
It will generate the composer.json file, the /vendor/autoload.php and the files in /vendor/composer/*
In your extension, you do a
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.
In your own extension folder do a
Code: Select all
composer require vendor-name/package-name
In your extension, you do a
Code: Select all
require __DIR__ . '/vendor/autoload.php';
use \Vendor-name\PackageName;
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
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com
-
- Joomla! Explorer
- Posts: 329
- Joined: Thu Oct 29, 2009 8:28 am
- Location: UK
Re: Composer?
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?
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.
- pe7er
- Joomla! Master
- Posts: 24985
- Joined: Thu Aug 18, 2005 8:55 pm
- Location: Nijmegen, Netherlands
- Contact:
Re: Composer?
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:
You will get some new files/folders in your component:
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/
- /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/
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
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com
-
- Joomla! Explorer
- Posts: 329
- Joined: Thu Oct 29, 2009 8:28 am
- Location: UK
Re: Composer?
That's cleared up my confusion. Many thanks!
It's a community, the more we all contribute, the better it will be.
- pe7er
- Joomla! Master
- Posts: 24985
- Joined: Thu Aug 18, 2005 8:55 pm
- Location: Nijmegen, Netherlands
- Contact:
Re: Composer?
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
Peter Martin, Global Moderator
Company website: https://db8.nl/en/ - Joomla specialist, Nijmegen, Netherlands
The best website: https://the-best-website.com
-
- Joomla! Explorer
- Posts: 329
- Joined: Thu Oct 29, 2009 8:28 am
- Location: UK
Re: Composer?
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...)
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.
-
- Joomla! Hero
- Posts: 2906
- Joined: Fri Jul 05, 2013 10:35 am
- Location: Parts Unknown
Re: Composer?
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.
I don't know which library you are talking about but make sure you only include code files and not development files.
-
- Joomla! Explorer
- Posts: 329
- Joined: Thu Oct 29, 2009 8:28 am
- Location: UK
Re: Composer?
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
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.