如何强制执行 composer `extra.symfony.require` 限制?

How composer `extra.symfony.require` restriction is enforced?

假设我有一个 Symfony v4.4 (Flex) 项目,在 composer.json:

中包含以下块
"extra": {
    "symfony": {
        "allow-contrib": false,
        "require": "4.4.*"
    }
}

正如预期的那样,它限制 Symfony 核心包坚持 v4.4 版本。

symfony/monolog-bridge 包尊重它,所以你不能安装 symfony/monolog-bridge ~4.3.0^5.0.

但是您可以安装 symfony/monolog-bundle ~3.5.0,这也是意料之中的,因为它只是一个捆绑包,不属于核心 Symfony 框架,并且有自己独立的发布和版本控制周期。

我无法理解的是什么帮助 composer 区分哪些包是 Symfony 核心包,以便应用 extra.symfony.require 限制,哪些不是?

我原本以为是作曲家的type属性让它成为可能,但我找不到任何symfony-bridge类型的独特痕迹。如果是 - link 源代码或文档将非常有帮助。

UPD:

默认的 Symfony(带 Flex)v4.4 composer.json:

{
    "name": "symfony/website-skeleton",
    "type": "project",
    "license": "MIT",
    "description": "A skeleton to start a new Symfony website",
    "require": {
        "php": "^7.1.3",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "sensio/framework-extra-bundle": "^5.1",
        "symfony/asset": "*",
        "symfony/console": "*",
        "symfony/dotenv": "*",
        "symfony/expression-language": "*",
        "symfony/flex": "^1.3.1",
        "symfony/form": "*",
        "symfony/framework-bundle": "*",
        "symfony/http-client": "*",
        "symfony/intl": "*",
        "symfony/mailer": "*",
        "symfony/monolog-bundle": "^3.1",
        "symfony/orm-pack": "*",
        "symfony/process": "*",
        "symfony/security-bundle": "*",
        "symfony/serializer-pack": "*",
        "symfony/translation": "*",
        "symfony/twig-pack": "*",
        "symfony/validator": "*",
        "symfony/web-link": "*",
        "symfony/yaml": "*"
    },
    "require-dev": {
        "symfony/debug-pack": "*",
        "symfony/maker-bundle": "^1.0",
        "symfony/profiler-pack": "*",
        "symfony/test-pack": "*"
    },
    "config": {
        "preferred-install": {
            "*": "dist"
        },
        "sort-packages": true
    },
    "autoload": {
        "psr-4": {
            "App\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\Tests\": "tests/"
        }
    },
    "replace": {
        "paragonie/random_compat": "2.*",
        "symfony/polyfill-ctype": "*",
        "symfony/polyfill-iconv": "*",
        "symfony/polyfill-php71": "*",
        "symfony/polyfill-php70": "*",
        "symfony/polyfill-php56": "*"
    },
    "scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "assets:install %PUBLIC_DIR%": "symfony-cmd"
        },
        "post-install-cmd": [
            "@auto-scripts"
        ],
        "post-update-cmd": [
            "@auto-scripts"
        ]
    },
    "conflict": {
        "symfony/symfony": "*"
    },
    "extra": {
        "symfony": {
            "allow-contrib": false,
            "require": "4.4.*"
        }
    }
}

现在,如果您添加 "symfony/monolog-bridge": "^5.0" 依赖项并且 composer update 您将得到

$ composer update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Restricting packages listed in "symfony/symfony" to "4.4.*"
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - The requested package symfony/monolog-bridge ^5.0 exists as symfony/monolog-bridge[4.4.x-dev, v4.4.0, v4.4.0-BETA1, v4.4.0-BETA2, v4.4.0-RC1, v4.4.1] but these are rejected by your constraint.
  Problem 2
    - symfony/monolog-bundle v3.5.0 requires symfony/monolog-bridge ~3.4 || ~4.0 || ^5.0 -> satisfiable by symfony/monolog-bridge[4.4.x-dev, v4.4.0, v4.4.0-BETA1, v4.4.0-BETA2, v4.4.0-RC1, v4.4.1] but these conflict with your requirements or minimum-stability.
    - symfony/monolog-bundle v3.5.0 requires symfony/monolog-bridge ~3.4 || ~4.0 || ^5.0 -> satisfiable by symfony/monolog-bridge[4.4.x-dev, v4.4.0, v4.4.0-BETA1, v4.4.0-BETA2, v4.4.0-RC1, v4.4.1] but these conflict with your requirements or minimum-stability.
    - symfony/monolog-bundle v3.4.0 requires symfony/monolog-bridge ~3.4|~4.0 -> satisfiable by symfony/monolog-bridge[4.4.x-dev, v4.4.0, v4.4.0-BETA1, v4.4.0-BETA2, v4.4.0-RC1, v4.4.1] but these conflict with your requirements or minimum-stability.
    - symfony/monolog-bundle v3.3.1 requires symfony/monolog-bridge ~2.7|~3.3|~4.0 -> satisfiable by symfony/monolog-bridge[4.4.x-dev, v4.4.0, v4.4.0-BETA1, v4.4.0-BETA2, v4.4.0-RC1, v4.4.1] but these conflict with your requirements or minimum-stability.
    - symfony/monolog-bundle v3.3.0 requires symfony/monolog-bridge ~2.7|~3.3|~4.0 -> satisfiable by symfony/monolog-bridge[4.4.x-dev, v4.4.0, v4.4.0-BETA1, v4.4.0-BETA2, v4.4.0-RC1, v4.4.1] but these conflict with your requirements or minimum-stability.
    - symfony/monolog-bundle v3.2.0 requires symfony/monolog-bridge ~2.7|~3.0|~4.0 -> satisfiable by symfony/monolog-bridge[4.4.x-dev, v4.4.0, v4.4.0-BETA1, v4.4.0-BETA2, v4.4.0-RC1, v4.4.1] but these conflict with your requirements or minimum-stability.
    - symfony/monolog-bundle v3.1.2 requires symfony/monolog-bridge ~2.7|~3.0|~4.0 -> satisfiable by symfony/monolog-bridge[4.4.x-dev, v4.4.0, v4.4.0-BETA1, v4.4.0-BETA2, v4.4.0-RC1, v4.4.1] but these conflict with your requirements or minimum-stability.
    - symfony/monolog-bundle v3.1.1 requires symfony/monolog-bridge ~2.7|~3.0|~4.0 -> satisfiable by symfony/monolog-bridge[4.4.x-dev, v4.4.0, v4.4.0-BETA1, v4.4.0-BETA2, v4.4.0-RC1, v4.4.1] but these conflict with your requirements or minimum-stability.
    - symfony/monolog-bundle v3.1.0 requires symfony/monolog-bridge ~2.7|~3.0 -> no matching package found.
    - Installation request for symfony/monolog-bundle ^3.1 -> satisfiable by symfony/monolog-bundle[v3.1.0, v3.1.1, v3.1.2, v3.2.0, v3.3.0, v3.3.1, v3.4.0, v3.5.0].

Potential causes:
 - A typo in the package name
 - The package is not available in a stable-enough version according to your minimum-stability setting
   see <https://getcomposer.org/doc/04-schema.md#minimum-stability> for more details.
 - It's a private package and you forgot to add a custom repository to find it

Read <https://getcomposer.org/doc/articles/troubleshooting.md> for further common problems.

问题仍然存在 - symfony 如何知道该软件包应受 v4.4 限制

据我所知,根据您的输出消息,Flex 使用 symfony/symfony 元包中的组件列表:

Restricting packages listed in "symfony/symfony" to "4.4.*"

您可以在相应的 composer.json 或 packagist 上找到软件包列表:

这是 4.4.1 的当前列表:

symfony/asset: v4.4.1
symfony/amazon-mailer: v4.4.1
symfony/browser-kit: v4.4.1
symfony/cache: v4.4.1
symfony/config: v4.4.1
symfony/console: v4.4.1
symfony/css-selector: v4.4.1
symfony/dependency-injection: v4.4.1
symfony/debug: v4.4.1
symfony/debug-bundle: v4.4.1
symfony/doctrine-bridge: v4.4.1
symfony/dom-crawler: v4.4.1
symfony/dotenv: v4.4.1
symfony/error-handler: v4.4.1
symfony/event-dispatcher: v4.4.1
symfony/expression-language: v4.4.1
symfony/filesystem: v4.4.1
symfony/finder: v4.4.1
symfony/form: v4.4.1
symfony/framework-bundle: v4.4.1
symfony/google-mailer: v4.4.1
symfony/http-client: v4.4.1
symfony/http-foundation: v4.4.1
symfony/http-kernel: v4.4.1
symfony/inflector: v4.4.1
symfony/intl: v4.4.1
symfony/ldap: v4.4.1
symfony/lock: v4.4.1
symfony/mailchimp-mailer: v4.4.1
symfony/mailer: v4.4.1
symfony/mailgun-mailer: v4.4.1
symfony/messenger: v4.4.1
symfony/mime: v4.4.1
symfony/monolog-bridge: v4.4.1
symfony/options-resolver: v4.4.1
symfony/postmark-mailer: v4.4.1
symfony/process: v4.4.1
symfony/property-access: v4.4.1
symfony/property-info: v4.4.1
symfony/proxy-manager-bridge: v4.4.1
symfony/routing: v4.4.1
symfony/security: v4.4.1
symfony/security-core: v4.4.1
symfony/security-csrf: v4.4.1
symfony/security-guard: v4.4.1
symfony/security-http: v4.4.1
symfony/security-bundle: v4.4.1
symfony/sendgrid-mailer: v4.4.1
symfony/serializer: v4.4.1
symfony/stopwatch: v4.4.1
symfony/templating: v4.4.1
symfony/translation: v4.4.1
symfony/twig-bridge: v4.4.1
symfony/twig-bundle: v4.4.1
symfony/validator: v4.4.1
symfony/var-dumper: v4.4.1
symfony/var-exporter: v4.4.1
symfony/web-link: v4.4.1
symfony/web-profiler-bundle: v4.4.1
symfony/web-server-bundle: v4.4.1
symfony/workflow: v4.4.1
symfony/yaml: v4.4.1

至于symfony/monolog-bundle,不在列表中,将安装在不与其他包冲突的版本中。换句话说,它将安装在最适合 Symfony 4 的任何版本中。