phpsymfonycomposer-phpsymfony-flex

How does composer resolve package names that are not fully qualified as "webapp" or "profiler"?


When you go to a Symfony project (for example created with composer create-project symfony/skeleton:"7.0.*" .) and you run composer require webapp, it will install symfony/webapp-pack.

How does composer find the package name symfony/webapp-pack when it has only been given the string webapp?


Solution

  • Symfony uses their own Composer plugin called Flex. It hooks into the require process.

    \Symfony\Flex\PackageResolver::resolvePackageName() calls:

    \Symfony\Flex\Downloader::getAliases() which makes an HTTP hit to:

    https://raw.githubusercontent.com/symfony/recipes/flex/main/index.json

    which contains a JSON-encoded list of Symfony-specific composer aliases:

        "web-server": "symfony/web-server-bundle",
        "web-server-bundle": "symfony/web-server-bundle",
        "webapp": "symfony/webapp-pack",
        "webhook": "symfony/webhook",
        "weblink": "symfony/web-link",
    

    Note this is not limited to just Symfony packages. For example, also in that file:

    "alice": "hautelook/alice-bundle",
    

    So, you can do:

    composer require alice