Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do PHP Composer Packages Come From?

When I run

$ composer.phar install

where do the packages that get installed come from?

I understand that Packagist is the default repository for PHP packages, and that lacking a different package in composer.json, this is where composer will look for packages.

However, what I'm not clear on is how Composer and Packagist interact.

  • Does Composer download files directly from packagist.org

  • Or does Composer get a git/svn/hg repository link from packagist and download the files from the repository directly?

  • Or something else?

like image 622
Alan Storm Avatar asked Apr 24 '13 22:04

Alan Storm


People also ask

Where does composer install packages from?

Composer can be configured to install packages to a folder other than the default vendor folder by using composer/installers. Now when your theme is installed with Composer it will be placed into wp-content/themes/themename/ folder.

What is PHP composer package?

Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you.

Where are the packages pulled from composer stored?

composer/vendor/bin/ in your path.

How does PHP composer work?

From the Composer documentation: Composer is not a package manager in the same sense as Yum or Apt are. Yes, it deals with "packages" or libraries, but it manages them on a per-project basis, installing them in a directory (e.g. vendor) inside your project. By default it will never install anything globally.


1 Answers

It depends on the contents of your composer.json file.

For example, if your composer.json contained simply

{
    "require": {
        "phpunit/phpunit": "3.8.*@dev"
    }
}

then composer searches packagist, and finds phpunit here:

https://packagist.org/packages/phpunit/phpunit

which tells composer to load phpunit from here:

https://github.com/sebastianbergmann/phpunit.git

If instead your composer.json contained

{
    "repositories": [
        {
            "type": "vcs",
            "url": "http://github.com/sebastianbergmann/phpunit"
        }
    ],
    "require": {
        "phpunit/phpunit": "3.8.*@dev"
    }
}

then composer will not look to packagist, but go directly to github to download the repo.

The packages registered on Packagist are usually the "authoritative" version of the package (not a fork), but I have found several instances where this is NOT the case, so you should check it to be sure you are pulling the package you expect.

like image 188
Ross Smith II Avatar answered Sep 28 '22 19:09

Ross Smith II