如何从供应商目录生成 laravel composer.json?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41183742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to generate laravel composer.json from a vendor directory?
提问by Amine
in my laravel project the composer.json and composer.lock files was deleted and i don't know how to rebuild the composer.json file from an existan the vendor directory . please i need some help or at least some guidence that can help me solve this problme
在我的 Laravel 项目中,composer.json 和 composer.lock 文件被删除,我不知道如何从现有的供应商目录重建 composer.json 文件。请我需要一些帮助或至少一些可以帮助我解决这个问题的指导
回答by aimme
Note
笔记
downside of using this method is that the main composer.json file would include some of the packages that have been required by existing or sub packages or multiple packages. but don't worry it would be installed only one time. but there might be problem with versions.
使用这种方法的缺点是主 composer.json 文件将包含现有或子包或多个包所需的一些包。但别担心它只会安装一次。但是版本可能有问题。
Advice
建议
I recommend you use some version control like git to overcome such situations in future.
我建议你使用一些像 git 这样的版本控制来克服将来的这种情况。
can't guarantee about the following method i am going to present as its not a usual case. but might work.
不能保证我将介绍的以下方法不是通常的情况。但可能会起作用。
create a new composer.json
file like this in project root. you could use composer init
command if you wish.
composer.json
在项目根目录中创建一个这样的新文件。composer init
如果你愿意,你可以使用命令。
{
"name": "laravel/laravel",
"description": "The Laravel Framework.",
"keywords": ["framework", "laravel"],
"license": "MIT",
"type": "project",
"require": {
"php": ">=5.6.4",
"laravel/framework": "5.3.*"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "5.6",
"symfony/css-selector": "3.1.*",
"symfony/dom-crawler": "3.1.*"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"Blog\": "app/"
}
},
"autoload-dev": {
"classmap": [
"tests/TestCase.php"
]
},
"scripts": {
"post-root-package-install": [
"php -r \"file_exists('.env') || copy('.env.example', '.env');\""
],
"post-create-project-cmd": [
"php artisan key:generate"
],
"post-install-cmd": [
"Illuminate\Foundation\ComposerScripts::postInstall",
"php artisan optimize"
],
"post-update-cmd": [
"Illuminate\Foundation\ComposerScripts::postUpdate",
"php artisan optimize"
]
},
"config": {
"preferred-install": "dist"
}
}
- go to every package folder inside vendor folder and find the package's composer.jsonfile. from that file find the
"name"
of that package from that composer.json file. add that name of the package to the main composer.jsonfile's
"require"
part. if you want to add that package to development add it to "require-dev" part.composer install
orcomposer update
composer dump-autoload
- 转到 vendor 文件夹中的每个包文件夹并找到包的 composer.json文件。从那个文件中找到
"name"
那个 composer.json 文件中的那个包。 将该包的名称添加到主 composer.json文件的
"require"
部分。如果您想将该包添加到开发中,请将其添加到“require-dev”部分。composer install
或者composer update
composer dump-autoload