I\'m working on 2 applications right now. The first one is a CMS, and the second is a shop. I want to move my vendor one level above and the share it between projects.
I know this is an old question but I run into the same problem. I'm using Laravel 7 and I solved the problem with the following method.
I wrote a shellscript (my-vendor.sh) at the root of my project with the following code :
#!/bin/bash
MY_VENDOR_DIRECTORY=my-vendor
VENDOR_DIRECTORY=vendor
if [ ! -d "$MY_VENDOR_DIRECTORY" ]
then
echo "Le dossier $MY_VENDOR_DIRECTORY n'existe pas : on le crée."
mkdir "$MY_VENDOR_DIRECTORY"
else
echo "Le dossier $MY_VENDOR_DIRECTORY existe : on le vide."
rm -rf "$MY_VENDOR_DIRECTORY/*"
fi
echo "Copie des fichiers autoload généré depuis $VENDOR_DIRECTORY vers $MY_VENDOR_DIRECTORY."
cp "$VENDOR_DIRECTORY/autoload.php" "$MY_VENDOR_DIRECTORY"
cp -R "$VENDOR_DIRECTORY/composer" "$MY_VENDOR_DIRECTORY"
cd "$MY_VENDOR_DIRECTORY/composer"
echo "Remplacement de 'require \$file' par \str_replace(\"$MY_VENDOR_DIRECTORY\/composer\/..\", \"vendor\", \$file)"
sed -i "s/require \$file/require \\str_replace('$MY_VENDOR_DIRECTORY\/composer\/..', 'vendor', \$file)/" autoload_real.php
echo "Remplacement de 'include \$file' par \str_replace(\"$MY_VENDOR_DIRECTORY\/composer\/..\", \"vendor\", \$file) "
sed -i "s/include \$file/require \\str_replace('$MY_VENDOR_DIRECTORY\/composer\/..', 'vendor', \$file)/" ClassLoader.php
Then, I replace the following code in public/index.php
:
require __DIR__.'/../vendor/autoload.php'
=> by require __DIR__.'/../my-vendor/autoload.php';
After that, I add my-vendor.sh
command in the post-autoload-dump
scripts.
I made this modifications in my two projects, launch composer dump-autoload
and it work like a charm :)
A link to the gist : https://gist.github.com/flibidi67/7c2cfdc1ff1b977b48204be0bee5eb76
Hope this can help someone else ;)