PHP& Composer,我如何组合composer.json文件

时间:2013-10-25 06:15:23

标签: php composer-php fuelphp package-managers

有人可以解释我应该如何使用php的作曲家。我在我的doc根目录下有一个composer.json文件,它下载了我的项目的核心包,但是当我想添加另一个像google + php sdk这样的项目时https://github.com/googleplus/gplus-quickstart-php/

我该怎么处理composer.json文件?我手动组合它们?我只是将composer.json下载到另一个目录中吗?

我当前的composer.json文件看起来像这样

 {
"name": "fuel/fuel",
"type": "metapackage",
"description": "The FuelPHP framework",
"keywords": ["framework"],
"homepage": "http://fuelphp.com",
"license": "MIT",
"authors": [
    {
        "name": "FuelPHP Development Team",
        "email": "team@fuelphp.com"
    }
],
"support": {
    "irc": "irc://irc.freenode.org/fuelphp",
    "forum": "http://fuelphp.com/forums"
},
"require": {
    "php": ">=5.3.3",
    "monolog/monolog": "1.5.*",
    "fuelphp/upload": "2.0",
    "omissis/php-cloudfiles": "dev-master",
    "mustache/mustache": "*"
},
"suggest": {
    "mustache/mustache": "Allow Mustache templating with the Parser package",
    "smarty/smarty": "Allow Smarty templating with the Parser package",
    "twig/twig": "Allow Twig templating with the Parser package",
    "mthaml/mthaml": "Allow Haml templating with Twig supports with the Parser package"
},
"config": {
    "vendor-dir": "fuel/vendor"
},
"minimum-stability": "dev"
}

g + composer.json文件看起来像

 {
"name": "googleplus/quickstart",
"description": "This quick-start app is built in PHP and lets you get started with the Google+ platform in a few minutes.",
"license": "Apache-2.0",
"repositories": [
    {
        "type": "package",
        "package": {
            "name": "google/google-api-php-client",
            "version": "0.6.2",
            "dist": {
                "url": "http://google-api-php-client.googlecode.com/files/google-api-php-client-0.6.2.tar.gz",
                "type": "tar"
            },
            "autoload": {
                "classmap": [
                    "src/"
                ]
            }
        }
    }
],
"require": {
    "silex/silex": "1.0.*@dev",
    "twig/twig": ">=1.8,<2.0-dev",
    "google/google-api-php-client": "0.6.2"
}
}

2 个答案:

答案 0 :(得分:6)

只需将其添加到原始作曲家文件的require块中即可:

"googleplus/quickstart": "*",

答案 1 :(得分:2)

我对Composer的经验不多,但我可以告诉你,当你需要一个lib时,你可以将lib添加到你的main composer.json文件中。安装或更新后,将下载新的lib,Composer将读取其composer.json文件;它的依赖项将自动下载,依此类推。

所以我们可以说你不应该手动下载你的要求,你必须使用Composer,它会照顾你。