Space Cat, Prince Among Thieves

Require a Remote Zip File with Composer

I previously showed you how to Load a Github Gist with Composer, but sometimes you need to install code that isn't isn't even in a public facing VCS.

I for instance wanted to use a library only distributed by Zip.

It's actually fairly easy! In your composer.json file, you simply add a repositories section to the root. You will want to update the url section to point at the remote zip you intend to load, as well as updating the name and autoload sections. More information on configuring composers autoloader can be found here.

"repositories": [
    {
        "type": "package",
        "package": {
            "name": "dr-que/x-y",
            "version": "master",
            "dist": {
                "type": "zip",
                "url": "http://xyplot.drque.net/Downloads/XY_Plot-1.4.zip",
                "reference": "master"
            },
            "autoload": {
                "classmap": ["."]
            }
        }
    }
]

Then in your require section, add your selected name as follows.

"require": {
    "dr-que/x-y": "dev-master"
}

Then just run composer update and you should be ready to roll!


Comment by: Ed on

Ed's Gravatar Thanks!

P.S. I also tried to include dr-que, but other lib - http://polynomialregression.drque.net/ :)

Comment by: Jigarius Caesar on

Jigarius Caesar's Gravatar Hi. What if I want composer to only get a subfolder from the ZIP? Is that possible? Say, I want "http://xyplot.drque.net/Downloads/XY_Plot-1.4.zip:/dist"

Comment by: Jesse G Donat on

Jesse G Donat's Gravatar Not as far as I am aware, however you could simply point the autoloader at the subdirectory.

Email address will never be publicly visible.

See my Tweet about comment formatting.