拿到的一个项目没有 composer.json,不过 /vendor 目录下是完整存在的。对此我们进行恢复。提供两个方式,都需要通过 /vendor/composer/installed.json 进行恢复。如果不存在则只能手动将所存在的项目逐个取出及对应版本号收集整理。
事实上,项目还不是使用默认的vendor目录,而是pkgs,所以可以通过环境变量来指定替代的vendor目录 COMPOSER_VENDOR_DIR=pkgs
其一,将上述文件内容所有的包名称及版本号提取出来标准规范写到 composer.json 即可。
其二,创建 composer.json ,运行 composer show --installed ,程序会将其列表出来,也需要收集提取。
# 可强制指定非vendor目录存放
COMPOSER_VENDOR_DIR=pkgs composer show --installed
aws/aws-sdk-php 3.133.1 AWS SDK for PHP - Use Amazon Web Services in your PHP project
firebase/php-jwt v5.0.0 A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.
google/auth v1.6.1 Google Auth Library for PHP
google/cloud v0.123.0 Google Cloud Client Library
google/common-protos 1.1 Google API Common Protos for PHP
google/crc32 v0.1.0 Various CRC32 implementations
google/gax 1.2.0 Google API Core for PHP
google/grpc-gcp 0.1.4 gRPC GCP library for channel management
google/protobuf v3.11.2 proto library for PHP
grpc/grpc 1.26.2 gRPC library for PHP
guzzlehttp/guzzle 6.5.2 Guzzle is a PHP HTTP client library
guzzlehttp/promises v1.3.1 Guzzle promises library
guzzlehttp/psr7 1.6.1 PSR-7 message implementation that also provides common utility methods
monolog/monolog 2.0.2 Sends your logs to files, sockets, inboxes, databases and various web services
mtdowling/jmespath.php 2.5.0 Declaratively specify how to extract elements from a JSON document
paragonie/random_compat v9.99.99 PHP 5.x polyfill for random_bytes() and random_int() from PHP 7
psr/cache 1.0.1 Common interface for caching libraries
psr/http-message 1.0.1 Common interface for HTTP messages
psr/log 1.1.2 Common interface for logging libraries
ralouphie/getallheaders 3.0.3 A polyfill for getallheaders.
ramsey/uuid 3.9.2 Formerly rhumsaa/uuid. A PHP 5.4+ library for generating RFC 4122 version 1, 3, 4, and 5 universally unique identifiers (UUID).
rize/uri-template 0.3.2 PHP URI Template (RFC 6570) supports both expansion & extraction
symfony/polyfill-ctype v1.13.1 Symfony polyfill for ctype functions
symfony/polyfill-mbstring v1.13.1 Symfony polyfill for the Mbstring extension
然后可以手动在composer.json的require中填入依赖
{
"name": "xxxxx",
"require": {
"aws/aws-sdk-php":"3.133.1",
"firebase/php-jwt":"v5.0.0",
"google/auth":"v1.6.1",
"google/cloud":"v0.123.0",
"google/common-protos":"1.1",
"google/crc32":"v0.1.0",
"google/gax":"1.2.0",
"google/grpc-gcp":"0.1.4",
"google/protobuf":"v3.11.2",
"grpc/grpc":"1.26.2",
"guzzlehttp/guzzle":"6.5.2",
"guzzlehttp/promises":"v1.3.1",
"guzzlehttp/psr7":"1.6.1",
"monolog/monolog":"2.0.2",
"mtdowling/jmespath.php":"2.5.0",
"paragonie/random_compat":"v9.99.99",
"psr/cache":"1.0.1",
"psr/http-message":"1.0.1",
"psr/log":"1.1.2",n
"ralouphie/getallheaders":"3.0.3",
"ramsey/uuid":"3.9.2",
"rize/uri-template":"0.3.2",
"symfony/polyfill-ctype":"v1.13.1",
"symfony/polyfill-mbstring":"v1.13.1",
"elasticsearch/elasticsearch": "7.14"
}
}
执行 composer update 进行更新并产生 composer.lock