如何使用较新的不稳定版本的 symfony?

How to use newer not stable yet version of symfony?

目前我使用 5.2.3 版本的 Symfony。我想使用此拉取请求 https://github.com/symfony/symfony/pull/36851 中的功能。这是 github / composer 相关的问题,而不是 symfony 本身。怎么做?

到目前为止我尝试:

{
    ...
    "symfony/form": "5.2.*-dev", // changes I made to composer.json
    ...
}

作曲家更新成功结束:

  - Upgrading symfony/form (v5.2.4 => 5.2.x-dev 7664ad9): Extracting archive

但是如果我在代码中使用 choice_translation_parameters,我会得到:

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        ...
        $builder->add('amount', ChoiceType::class, ["label" => "rese.amount?", "choices" => $roomAmountChoices, "choice_translation_parameters" => []]);
        ...
    }

An error has occurred resolving the options of the form "Symfony\Component\Form\Extension\Core\Type\ChoiceType": The option "choice_translation_parameters" does not exist. Defined options are: "action", "allow_file_upload", "attr", "attr_translation_parameters", "auto_initialize", "block_name", "block_prefix", "by_reference", "choice_attr", "choice_filter", "choice_label", "choice_loader", "choice_name", "choice_translation_domain", "choice_value", "choices", "compound", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "ea_crud_form", "empty_data", "error_bubbling", "expanded", "getter", "group_by", "help", "help_attr", "help_html", "help_translation_parameters", "inherit_data", "invalid_message", "invalid_message_parameters", "is_empty_callback", "label", "label_attr", "label_format", "label_html", "label_translation_parameters", "mapped", "method", "multiple", "placeholder", "post_max_size_message", "preferred_choices", "property_path", "required", "row_attr", "setter", "translation_domain", "trim", "upload_max_size_message".

使用 *-dev 是行不通的,因为代码仍在等待合并到 symfony/symfony

查看 http://vvv.tobiassjosten.net/php/have-composer-use-development-branches/ 了解如何使用不同存储库覆盖包的说明。

在您的情况下,composer.json 将具有:

"repositories": [
    {
        "type": "git",
        "url": "https://github.com/VincentLanglet/symfony.git"
    }
]

警告:这在短时间内会很好,但投入生产是有风险的。你会得到你想要的功能,但依赖于作者与真正的 symfony 大师保持更新。

由于是开放(未合并)分支,不能直接pull。您必须使用存储库模式在 composer.json 中注册它。

类似于

{
    "repositories": [
        {
            "type": "git",
            "url": "https://github.com/VincentLanglet/symfony.git"
        }
    ],
    "require": {
        "symfony/form": "^5.2"
    }
}

你(在这个例子中是我,因为我回答了我自己的问题)做对了一切,只是选择了错误的分支。将其更改为:

{
    ...
    "symfony/form": "5.*-dev",
    ...
}

如果您仔细查看 symfony/form 存储库历史记录,您会注意到之前 composer 选择的分支不包含具有您请求的功能的提交。