This post was updated 762 days ago and some of the ideas may be out of date.
新建一个composer.json文件,根据需求运行代码即可。
<?php
/**
* Created by PhpStorm.
* User: LinFei
* Created time 2022/09/17 17:31:15
* E-mail: fly@eyabc.cn
*/
declare (strict_types=1);
$content = `composer show --installed`;
preg_match_all('#([A-z0-9\/\-\.]+)\s+([A-z0-9\.\-]+)[\S\s]+?\n#', $content, $matches);
$packages = [
'php' => '>=7.2.5',
];
foreach ($matches[1] as $key => $name) {
$packages[$name] = $matches[2][$key];
}
$packages = json_encode($packages);
$data = <<<JSON
{
"name": "topthink/think",
"description": "the new thinkphp framework",
"type": "project",
"keywords": [
"framework",
"thinkphp",
"ORM"
],
"homepage": "https://www.thinkphp.cn/",
"license": "Apache-2.0",
"authors": [
{
"name": "liu21st",
"email": "liu21st@gmail.com"
},
{
"name": "yunwuxin",
"email": "448901948@qq.com"
}
],
"require": {$packages},
"require-dev": {
"symfony/var-dumper": "^4.2",
"topthink/think-trace": "^1.0"
},
"autoload": {
"psr-4": {
"app\\\\": "app"
},
"psr-0": {
"": "extend/"
}
},
"config": {
"preferred-install": "dist"
},
"scripts": {
"post-autoload-dump": [
"@php think service:discover",
"@php think vendor:publish"
]
}
}
JSON;
$data = json_encode(json_decode($data), JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
file_put_contents('./composer.json', stripslashes($data));
参与讨论