How to specify Composer install path?

PhpSymfony1Composer Php

Php Problem Overview


I have this definition:

{
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "symfony/sfGuardPlugin",
                "version": "4.0.2",
                "dist": {
                    "url": "http://plugins.symfony-project.org/get/sfGuardPlugin/sfGuardPlugin-4.0.2.tgz",
                    "type": "tar"
                }
            }
        }
    ],
    "require": {
        "symfony/sfGuardPlugin": "4.0.*"
    }
}

I am using Symfony 1, and I'd like to install them on plugins/sfGuardPlugin/. How do I specify this?

Php Solutions


Solution 1 - Php

It seems that you can define the vendor dir to be something else (plugins in your case):

{
    "config": {
        "vendor-dir": "plugins"
    }
}

Then, you might rename the package name to not have a level dir inside, like:

        "package": {
            "name": "sfGuardPlugin",

So, your composer.json should look like this:

{
    "config": {
        "vendor-dir": "plugins"
    },
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "sfGuardPlugin",
                "version": "4.0.2",
                "dist": {
                    "url": "http://plugins.symfony-project.org/get/sfGuardPlugin/sfGuardPlugin-4.0.2.tgz",
                    "type": "tar"
                }
            }
        }
    ],
    "require": {
        "sfGuardPlugin": "4.0.*"
    }
}

Edit

Using this configuration, you will get the path (which is of course not good for symfony):

>plugins/sfGuardPlugin/sfGuardPlugin-4.0.2/

I found a workaround with this composer.json:

{
    "config": {
        "vendor-dir": "plugins"
    },
    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "sfGuardPlugin",
                "version": "4.0.2",
                "source": {
                    "url": "http://svn.symfony-project.com/plugins/sfGuardPlugin/",
                    "type": "svn",
                    "reference": "branches/1.3/"
                }
            }
        }
    ],
    "require": {
        "sfGuardPlugin": "4.0.*"
    }
}

Solution 2 - Php

You can also use composer/installers, a multi-framework composer library installer with the "symfony1-plugin" package type. This is what my composer.json file looks like, in order for it to install both Symfony 1.4 (in lib/vendor) and plugins in (/plugins):

{
    "config": {
        "vendor-dir": "lib/vendor"
    },
    "repositories": {
        "symfony": {
            "type": "package",
            "package": {
                "name": "symfony/symfony1",
                "version": "1.4",
                "dist": {
                    "url": "https://github.com/symfony/symfony1/zipball/1.4",
                    "type": "zip"
                }
            }
        },
        "sfResquePlugin" : {
            "type": "package",
            "package": {
                "name": "devpips/sfResquePlugin",
                "type": "symfony1-plugin",
                "version": "0.1",
                "dist": {
                    "url": "https://github.com/devpips/sfResquePlugin/zipball/master",
                    "type": "zip"
                }
            }
        }
    },
    "require": {
        "composer/installers": "dev-master",
        "symfony/symfony1": "1.4",
        "devpips/sfResquePlugin":"0.1"
    }
}

Solution 3 - Php

See COMPOSER_VENDOR_DIR environment variable.

> By setting this var you can make Composer install the dependencies into a directory other than vendor.

Can be helpful in the case you want to override this in a particular environment such as vagrant or docker where you wouldn't want this to be in a shared folder / volume.

And as J0k said, there's vendor-dir in config section of composer.json

> Defaults to vendor. You can install dependencies into a different directory if you want to. $HOME and ~ will be replaced by your home directory's path in vendor-dir and all *-dir options below.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTowerView Question on Stackoverflow
Solution 1 - Phpj0kView Answer on Stackoverflow
Solution 2 - PhpAdam V.View Answer on Stackoverflow
Solution 3 - PhpGabLeRouxView Answer on Stackoverflow