如何在composer.json中覆盖其他依赖项

12

我正在使用AliceFixturesBundles,它依赖于NelmioAliceFaker。 依赖项在内部处理,例如:

https://github.com/h4cc/AliceFixturesBundle/blob/master/composer.json

{
    "name": "h4cc/alice-fixtures-bundle",
    "description": "Symfony2 Bundle for loading fixture data with the Alice library.",
    "keywords": ["Symfony2", "Fixtures", "Alice", "Loader", "Doctrine", "ORM", "MongoDB"],
    "type": "symfony-bundle",
    "license": "MIT",
    "authors": [
        {
            "name": "Julius Beckmann",
            "email": "github@h4cc.de"
        }
    ],
    "require": {
        "php": ">=5.3.0",
        "nelmio/alice": "~1.6",
        "doctrine/common": "~2.1",
        "psr/log": "~1.0",
        "symfony/finder": "~2.0"
    },
    "require-dev": {
        "phpunit/phpunit": "~4.0",
        "symfony/framework-bundle": "~2.1",
        "doctrine/orm": "~2.1",
        "doctrine/mongodb-odm": "1.0.*@dev",
        "doctrine/mongodb-odm-bundle": "3.0.*@dev",
        "matthiasnoback/symfony-config-test": "~0.2.1"
    },
    "autoload": {
        "psr-4": {
            "h4cc\\AliceFixturesBundle\\": ""
        }
    }
}

依赖于:

https://github.com/nelmio/alice/blob/master/composer.json

{
    "name": "nelmio/alice",
    "description": "Expressive fixtures generator",
    "keywords": ["fixture", "data", "test", "orm"],
    "type": "library",
    "license": "MIT",
    "authors": [
        {
            "name": "Jordi Boggiano",
            "email": "j.boggiano@seld.be"
        },
        {
            "name": "Tim Shelburne",
            "email": "shelburt02@gmail.com"
        }
    ],
    "require": {
        "php": ">=5.4",
        "fzaninotto/faker": "~1.0",
        "symfony/yaml": "~2.0"
    },
    "require-dev": {
        "doctrine/common": "~2.3",
        "symfony/property-access": "~2.2",
        "phpunit/phpunit": "3.7.*"
    },
    "autoload": {
        "psr-4": { "Nelmio\\Alice\\": "src/Nelmio/Alice" }
    },
    "extra": {
        "branch-alias": {
            "dev-master": "2.0.x-dev"
        }
    }
}

我的问题就在这里,在这一行:"fzaninotto/faker": "~1.0",,我该如何在我的composer.json中覆盖那一行,以便使用"fzaninotto/faker": "1.5.*@dev"代替已定义的那个?


你为什么想要覆盖它? - James Spence
@JamesSpence 因为我需要使用 Faker 存储库中尚未标记的某些内容,而这些内容仅在 dev/master 分支上可用。 - ReynierPM
嗯,我明白了。看起来这种行为是可能的。请参阅使用Composer覆盖依赖项的链接。 - James Spence
警告:覆盖依赖项可能会对其他依赖项(需要被覆盖的依赖项)产生不良影响。 - James Spence
@JamesSpence 我之前已经查看了那个链接,但是不知道如何在我的环境中实现,你能提供一个带有解决方案的答案吗? - ReynierPM
Answer posted below. - James Spence
1个回答

32
在您自己的composer.json文件中,您可以这样做:
{
    "require": {
        "h4cc/alice-fixtures-bundle": "dev/master", //Whatever version you use
        "fzaninotto/faker": "dev-master as 1.0"
    }
}

首先出现了错误,提示Invalid version string "~1.0" in "1.5.*@dev as ~1.0",别名必须是一个精确的版本。然后你把这一行改成了"fzaninotto/faker": "1.5.*@dev as 1.0.0",,但是又出现了这个错误 Your requirements could not be resolved to an installable set of packages.我会联系包维护者看看该如何解决,谢谢。 - ReynierPM
看起来你的版本规范(1.5.*@dev)可能不准确。试试使用dev-master,看看是否有效。 - James Spence
没问题。根据更改更新了答案。 - James Spence

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接