Using Composer on Joomla 4 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! Apprentice
- Posts: 15
- Joined: Wed May 25, 2011 8:37 pm
Using Composer on Joomla 4
Hi.
I am trying to install the google/apiclient with Composer.
I go to mysite/libraries folder and then run the command
composer require google/apiclient:^2.0
And then Composer starts removing all the joomla libraries.
I do not understand why.
Please, help me.
I am in stuck with that.
P.S. Joomla version 4.1.2
I am trying to install the google/apiclient with Composer.
I go to mysite/libraries folder and then run the command
composer require google/apiclient:^2.0
And then Composer starts removing all the joomla libraries.
I do not understand why.
Please, help me.
I am in stuck with that.
P.S. Joomla version 4.1.2
You do not have the required permissions to view the files attached to this post.
-
- Joomla! Hero
- Posts: 2910
- Joined: Fri Jul 05, 2013 10:35 am
- Location: Parts Unknown
Re: Using Composer on Joomla 4
Joomla does not support managing Composer dependencies. You need to ship the custom vendor folder in your extension. Using prefixer may be need to avoid conflicts with core dependencies.
-
- Joomla! Apprentice
- Posts: 15
- Joined: Wed May 25, 2011 8:37 pm
Re: Using Composer on Joomla 4
What about this article
https://docs.joomla.org/J3.x:Using_Composer_with_Joomla
What do You mean about to ship the custom vendor?
I can copy all the vendors to our libraries/vendor folder.
But what about autoloading?
Or should I use the php include/require commands in my extension?
Thanks a lot for Your help.
https://docs.joomla.org/J3.x:Using_Composer_with_Joomla
What do You mean about to ship the custom vendor?
I can copy all the vendors to our libraries/vendor folder.
But what about autoloading?
Or should I use the php include/require commands in my extension?
Thanks a lot for Your help.
-
- Joomla! Hero
- Posts: 2910
- Joined: Fri Jul 05, 2013 10:35 am
- Location: Parts Unknown
Re: Using Composer on Joomla 4
The last paragraph in that article clearly says you can't install extra libraries. It also explains why you're seeing this behavior — Joomla does not ship composer.json. Thus any composer command you run creates a new project from scratch with a new composer.json and so all existing packages are uninstalled.
To autoload classes you have to load just the vendor/autoload.php file.
To autoload classes you have to load just the vendor/autoload.php file.
-
- Joomla! Explorer
- Posts: 330
- Joined: Thu Oct 29, 2009 8:28 am
- Location: UK
Re: Using Composer on Joomla 4
I am (successfully) using the Google API.
I have the composer json and lock files in my component's administrator directory and therefore the vendor directory directory is there too. In order not to interfere with Joomla classes I've used Scoper to adjust the class names. This works perfectly well.
I have the composer json and lock files in my component's administrator directory and therefore the vendor directory directory is there too. In order not to interfere with Joomla classes I've used Scoper to adjust the class names. This works perfectly well.
It's a community, the more we all contribute, the better it will be.
- Maradona
- Joomla! Enthusiast
- Posts: 154
- Joined: Fri Aug 30, 2013 2:08 pm
- Location: Argentina
Re: Using Composer on Joomla 4
What is Scoper?
-
- Joomla! Explorer
- Posts: 330
- Joined: Thu Oct 29, 2009 8:28 am
- Location: UK
Re: Using Composer on Joomla 4
GitHub - humbug/php-scoper: Prefixes all PHP namespaces in a file ...
PHP-Scoper is a tool which essentially moves any body of code, including all dependencies such as vendor directories, to a new and distinct namespace. Goal PHP-Scoper's goal is to make sure that all code for a project lies in a distinct PHP namespace.
The Google API uses names that the main Joomla js uses, so Scoper, moving the entire Google API (that I've loaded), keeps it separate from Joomla and prevents interference. At least, that's the way it seems to me.
It's a bit like the hand of God for js
It's a community, the more we all contribute, the better it will be.
- Maradona
- Joomla! Enthusiast
- Posts: 154
- Joined: Fri Aug 30, 2013 2:08 pm
- Location: Argentina
-
- Joomla! Apprentice
- Posts: 15
- Joined: Wed May 25, 2011 8:37 pm
Re: Using Composer on Joomla 4
Thanks a lot to SharkyKZ.
You saved my life.
You saved my life.