生龙活虎1986

导航

从已有安装包(vendor)恢复thinkphp6 composer.json

从已有安装包(vendor)恢复 composer.json

拿到的一个项目没有 composer.json,不过 /vendor 目录下是完整存在的。对此我们进行恢复。提供两个方式,都需要通过 /vendor/composer/installed.json 进行恢复。如果不存在则只能手动将所存在的项目逐个取出及对应版本号收集整理。

其一,将上述文件内容所有的包名称及版本号提取出来标准规范写到 composer.json 即可。

其二,创建thinkphp6文件 composer.json ,新建thinkphp6文件 composer.json

{
    "name": "topthink/think",
    "description": "the new thinkphp framework",
    "type": "project",
    "keywords": [
        "framework",
        "thinkphp",
        "ORM"
    ],
    "homepage": "http://thinkphp.cn/",
    "license": "Apache-2.0",
    "authors": [
        {
            "name": "liu21st",
            "email": "liu21st@gmail.com"
        }
    ],
    "require": {
        "php": ">=7.1.0",
        "topthink/framework": "^6.0.0",
        "topthink/think-orm": "^2.0",
        "topthink/think-multi-app": "^1.0"
    },
    "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"
        ]
    }
}

  

运行 composer show --installed ,程序会将其列表出来,也需要收集提取。

 

 

匹配正则:

([A-z0-9\/\-\.]+)\s+([A-z0-9\.\-]+)[\S\s]+?\n

替换正则:

"$1":"$2",####

在线正则测试:https://c.runoob.com/front-end/854/

我们将 composer 返回的内容复制出来,使用正则提取出来并将其替换,最后将其中的 #### 替换为相应的换行符 \r\n ,格式化后将其放置到 composer.json 文件里的 require 或者 require-dev 配置段。

 

 

 

最后,更新。

  1.  
    > composer update
  2.  
    .....
  3.  
    Writing lock file
  4.  
    Generating autoload files

 

实践:

C:\phpstudy_pro\WWW>composer show --installed


You are using the deprecated option "installed". Only installed packages are sho
wn by default now. The --all option can be used to show all packages.
doctrine/instantiator 1.3.1 A small, lightweight utility...
guzzlehttp/guzzle 6.5.5 Guzzle is a PHP HTTP client ...
guzzlehttp/promises 1.4.0 Guzzle promises library
guzzlehttp/psr7 1.7.0 PSR-7 message implementation...
league/flysystem 1.1.3 Filesystem abstraction: Many...
league/flysystem-cached-adapter 1.1.0 An adapter decorator to enab...
league/mime-type-detection 1.5.0 Mime-type detection for Flys...
maennchen/zipstream-php 2.1.0 ZipStream is a library for d...
markbaker/complex 1.5.0 PHP Class for working with c...
markbaker/matrix 1.2.1 PHP Class for working with m...
myclabs/deep-copy 1.10.1 Create deep copies (clones) ...
myclabs/php-enum 1.7.6 PHP Enum implementation
paragonie/random_compat v9.99.99 PHP 5.x polyfill for random_...
phar-io/manifest 1.0.3 Component for reading phar.i...
phar-io/version 2.0.1 Library for handling version...
phpdocumentor/reflection-common 2.2.0 Common reflection classes us...
phpdocumentor/reflection-docblock 5.2.2 With this component, a libra...
phpdocumentor/type-resolver 1.4.0 A PSR-5 based resolver of Cl...
phpoffice/phpspreadsheet 1.14.1 PHPSpreadsheet - Read, Creat...
phpspec/prophecy 1.12.1 Highly opinionated mocking f...
phpunit/php-code-coverage 7.0.10 Library that provides collec...
phpunit/php-file-iterator 2.0.2 FilterIterator implementatio...
phpunit/php-text-template 1.2.1 Simple template engine.
phpunit/php-timer 2.1.2 Utility class for timing
phpunit/php-token-stream 3.1.1 Wrapper around PHP's tokeniz...
phpunit/phpunit 8.5.4 The PHP Unit Testing framework.
psr/cache 1.0.1 Common interface for caching...
psr/container 1.0.0 Common Container Interface (...
psr/http-client 1.0.1 Common interface for HTTP cl...
psr/http-factory 1.0.1 Common interfaces for PSR-7 ...
psr/http-message 1.0.1 Common interface for HTTP me...
psr/log 1.1.3 Common interface for logging...
psr/simple-cache 1.0.1 Common interfaces for simple...
ralouphie/getallheaders 3.0.3 A polyfill for getallheaders.
sebastian/code-unit-reverse-lookup 1.0.1 Looks up which function or m...
sebastian/comparator 3.0.2 Provides the functionality t...
sebastian/diff 3.0.2 Diff implementation
sebastian/environment 4.2.3 Provides functionality to ha...
sebastian/exporter 3.1.2 Provides the functionality t...
sebastian/global-state 3.0.0 Snapshotting of global state
sebastian/object-enumerator 3.0.3 Traverses array structures a...
sebastian/object-reflector 1.1.1 Allows reflection of object ...
sebastian/recursion-context 3.0.0 Provides functionality to re...
sebastian/resource-operations 2.0.1 Provides a list of PHP built...
sebastian/type 1.1.3 Collection of value objects ...
sebastian/version 2.0.1 Library that helps with mana...
symfony/polyfill-ctype v1.18.1 Symfony polyfill for ctype f...
symfony/polyfill-intl-idn v1.18.1 Symfony polyfill for intl's ...
symfony/polyfill-intl-normalizer v1.18.1 Symfony polyfill for intl's ...
symfony/polyfill-mbstring v1.18.1 Symfony polyfill for the Mbs...
symfony/polyfill-php70 v1.18.1 Symfony polyfill backporting...
symfony/polyfill-php72 v1.18.1 Symfony polyfill backporting...
symfony/polyfill-php80 v1.18.1 Symfony polyfill backporting...
symfony/var-dumper v4.4.15 Symfony mechanism for explor...
theseer/tokenizer 1.2.0 A small library for converti...
topthink/framework v6.0.4 The ThinkPHP Framework.
topthink/think-helper v3.1.4 The ThinkPHP6 Helper Package
topthink/think-multi-app v1.0.14 thinkphp6 multi app support
topthink/think-orm v2.0.34 think orm
topthink/think-trace v1.4 thinkphp debug trace
webmozart/assert 1.9.1 Assertions to validate metho...

 

在线正则测试:https://c.runoob.com/front-end/854/

匹配正则:

([A-z0-9\/\-\.]+)\s+([A-z0-9\.\-]+)[\S\s]+?\n

 

 

 

替换正则:

"$1":"$2",####

 

 我们将 composer 返回的内容复制出来,使用正则提取出来并将其替换,最后将其中的 #### 替换为相应的换行符 \r\n ,格式化后将其放置到 composer.json 文件里的 require 或者 require-dev 配置段。

 

 最终加上本地veryinf/mb-helper 本地库的composer.json

 

{
    "name": "topthink/think",
    "description": "the new thinkphp framework",
    "type": "project",
    "keywords": [
        "framework",
        "thinkphp",
        "ORM"
    ],
    "homepage": "http://thinkphp.cn/",
    "license": "Apache-2.0",
    "authors": [
        {
            "name": "liu21st",
            "email": "liu21st@gmail.com"
        }
    ],
    "require": {
        "php": ">=7.1.0",
        "doctrine/instantiator": "1.3.1",
        "guzzlehttp/promises": "1.4.0",
        "league/flysystem": "1.1.3",
        "league/flysystem-cached-adapter": "1.1.0",
        "league/mime-type-detection": "1.5.0",
        "maennchen/zipstream-php": "2.1.0",
        "markbaker/complex": "1.5.0",
        "markbaker/matrix": "1.2.3",
        "myclabs/deep-copy": "1.10.1",
        "myclabs/php-enum": "1.8.3",
        "paragonie/random_compat": "v9.99.99",
        "phar-io/version": "2.0.1",
        "phpdocumentor/reflection-common": "2.2.0",
        "phpdocumentor/reflection-docblock": "5.2.2",
        "phpdocumentor/type-resolver": "1.6.1",
        "phpoffice/phpspreadsheet": "1.14.1",
        "phpunit/php-code-coverage": "7.0.10",
        "phpunit/php-file-iterator": "2.0.5",
        "phpunit/php-text-template": "1.2.1",
        "phpunit/php-token-stream": "3.1.1",
        "psr/cache": "1.0.1",
        "psr/container": "1.1.1",
        "psr/http-client": "1.0.1",
        "psr/http-factory": "1.0.1",
        "psr/http-message": "1.0.1",
        "psr/log": "1.1.4",
        "psr/simple-cache": "1.0.1",
        "sebastian/code-unit-reverse-lookup": "1.0.1",
        "sebastian/diff": "3.0.2",
        "sebastian/environment": "4.2.4",
        "sebastian/exporter": "3.1.2",
        "sebastian/object-enumerator": "3.0.3",
        "sebastian/object-reflector": "1.1.2",
        "sebastian/recursion-context": "3.0.0",
        "sebastian/type": "1.1.3",
        "sebastian/version": "2.0.1",
        "symfony/polyfill-ctype": "v1.18.1",
        "symfony/polyfill-intl-normalizer": "v1.18.1",
        "symfony/polyfill-mbstring": "v1.25.0",
        "symfony/polyfill-php70": "v1.18.1",
        "symfony/polyfill-php72": "v1.25.0",
        "symfony/polyfill-php80": "v1.18.1",
        "symfony/var-dumper": "v4.4.39",
        "theseer/tokenizer": "1.2.0",
        "topthink/framework": "v6.0.8",
        "topthink/think-helper": "v3.1.4",
        "topthink/think-multi-app": "v1.0.14",
        "topthink/think-orm": "v2.0.34",
        "topthink/think-trace": "v1.4",
        
        "webmozart/assert": "1.9.1"
    },
    "require-dev": {
        "php": ">=7.1.0",
        "doctrine/instantiator": "1.3.1",
        "guzzlehttp/promises": "1.4.0",
        "league/flysystem": "1.1.3",
        "league/flysystem-cached-adapter": "1.1.0",
        "league/mime-type-detection": "1.5.0",
        "maennchen/zipstream-php": "2.1.0",
        "markbaker/complex": "1.5.0",
        "markbaker/matrix": "1.2.3",
        "myclabs/deep-copy": "1.10.1",
        "myclabs/php-enum": "1.8.3",
        "paragonie/random_compat": "v9.99.99",
        "phar-io/version": "2.0.1",
        "phpdocumentor/reflection-common": "2.2.0",
        "phpdocumentor/reflection-docblock": "5.2.2",
        "phpdocumentor/type-resolver": "1.6.1",
        "phpoffice/phpspreadsheet": "1.14.1",
        "phpunit/php-code-coverage": "7.0.10",
        "phpunit/php-file-iterator": "2.0.5",
        "phpunit/php-text-template": "1.2.1",
        "phpunit/php-token-stream": "3.1.1",
        "psr/cache": "1.0.1",
        "psr/container": "1.1.1",
        "psr/http-client": "1.0.1",
        "psr/http-factory": "1.0.1",
        "psr/http-message": "1.0.1",
        "psr/log": "1.1.4",
        "psr/simple-cache": "1.0.1",
        "sebastian/code-unit-reverse-lookup": "1.0.1",
        "sebastian/diff": "3.0.2",
        "sebastian/environment": "4.2.4",
        "sebastian/exporter": "3.1.2",
        "sebastian/object-enumerator": "3.0.3",
        "sebastian/object-reflector": "1.1.2",
        "sebastian/recursion-context": "3.0.0",
        "sebastian/type": "1.1.3",
        "sebastian/version": "2.0.1",
        "symfony/polyfill-ctype": "v1.18.1",
        "symfony/polyfill-intl-normalizer": "v1.18.1",
        "symfony/polyfill-mbstring": "v1.25.0",
        "symfony/polyfill-php70": "v1.18.1",
        "symfony/polyfill-php72": "v1.25.0",
        "symfony/polyfill-php80": "v1.18.1",
        "symfony/var-dumper": "v4.4.39",
        "theseer/tokenizer": "1.2.0",
        "topthink/framework": "v6.0.8",
        "topthink/think-helper": "v3.1.4",
        "topthink/think-multi-app": "v1.0.14",
        "topthink/think-orm": "v2.0.34",
        "topthink/think-trace": "v1.4",

        "webmozart/assert": "1.9.1"
    },
    "autoload": {
        "psr-4": {
            "app\\": "app",
            "mb\\helper\\": "./vendor/veryinf/mb-helper/src"
        },
        "psr-0": {
            "": "extend/"
        },
        "files": [
            "./vendor/veryinf/mb-helper/src/function.php"
        ]
    },
    "config": {
        "preferred-install": "dist"
    },
    "scripts": {
        "post-autoload-dump": [
            "@php think service:discover",
            "@php think vendor:publish"
        ]
    },
    "repositories": {
        "packagist": {
            "type": "composer",
            "url": "https://mirrors.aliyun.com/composer/"
        },
        "foo": {
             "type": "path",
             "url": "./vendor/veryinf/mb-helper"
         }
    }
}

  

 

C:\phpstudy_pro\WWW>composer update


Loading composer repositories with package information
Updating dependencies
Lock file operations: 50 installs, 0 updates, 0 removals
- Locking doctrine/instantiator (1.3.1)
- Locking guzzlehttp/promises (1.4.0)
- Locking league/flysystem (1.1.3)
- Locking league/flysystem-cached-adapter (1.1.0)
- Locking league/mime-type-detection (1.5.0)
- Locking maennchen/zipstream-php (2.1.0)
- Locking markbaker/complex (1.5.0)
- Locking markbaker/matrix (1.2.3)
- Locking myclabs/deep-copy (1.10.1)
- Locking myclabs/php-enum (1.8.3)
- Locking paragonie/random_compat (v9.99.99)
- Locking phar-io/version (2.0.1)
- Locking phpdocumentor/reflection-common (2.2.0)
- Locking phpdocumentor/reflection-docblock (5.2.2)
- Locking phpdocumentor/type-resolver (1.6.1)
- Locking phpoffice/phpspreadsheet (1.14.1)
- Locking phpunit/php-code-coverage (7.0.10)
- Locking phpunit/php-file-iterator (2.0.5)
- Locking phpunit/php-text-template (1.2.1)
- Locking phpunit/php-token-stream (3.1.1)
- Locking psr/cache (1.0.1)
- Locking psr/container (1.1.1)
- Locking psr/http-client (1.0.1)
- Locking psr/http-factory (1.0.1)
- Locking psr/http-message (1.0.1)
- Locking psr/log (1.1.4)
- Locking psr/simple-cache (1.0.1)
- Locking sebastian/code-unit-reverse-lookup (1.0.1)
- Locking sebastian/diff (3.0.2)
- Locking sebastian/environment (4.2.4)
- Locking sebastian/exporter (3.1.2)
- Locking sebastian/object-enumerator (3.0.3)
- Locking sebastian/object-reflector (1.1.2)
- Locking sebastian/recursion-context (3.0.0)
- Locking sebastian/type (1.1.3)
- Locking sebastian/version (2.0.1)
- Locking symfony/polyfill-ctype (v1.18.1)
- Locking symfony/polyfill-intl-normalizer (v1.18.1)
- Locking symfony/polyfill-mbstring (v1.25.0)
- Locking symfony/polyfill-php70 (v1.18.1)
- Locking symfony/polyfill-php72 (v1.25.0)
- Locking symfony/polyfill-php80 (v1.18.1)
- Locking symfony/var-dumper (v4.4.39)
- Locking theseer/tokenizer (1.2.0)
- Locking topthink/framework (v6.0.8)
- Locking topthink/think-helper (v3.1.4)
- Locking topthink/think-multi-app (v1.0.14)
- Locking topthink/think-orm (v2.0.34)
- Locking topthink/think-trace (v1.4)
- Locking webmozart/assert (1.9.1)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 12 updates, 11 removals
- Downloading myclabs/php-enum (1.8.3)
- Downloading phpdocumentor/type-resolver (1.6.1)
- Downloading markbaker/matrix (1.2.3)
- Downloading symfony/polyfill-mbstring (v1.25.0)
- Downloading sebastian/environment (4.2.4)
- Downloading phpunit/php-file-iterator (2.0.5)
- Downloading psr/container (1.1.1)
- Downloading sebastian/object-reflector (1.1.2)
- Downloading symfony/polyfill-php72 (v1.25.0)
- Downloading symfony/var-dumper (v4.4.39)
- Downloading psr/log (1.1.4)
- Downloading topthink/framework (v6.0.8)
0/12 [>---------------------------] 0%
9/12 [=====================>------] 75%
12/12 [============================] 100%
- Removing symfony/polyfill-intl-idn (v1.18.1)
- Removing sebastian/resource-operations (2.0.1)
- Removing sebastian/global-state (3.0.0)
- Removing sebastian/comparator (3.0.2)
- Removing ralouphie/getallheaders (3.0.3)
- Removing phpunit/phpunit (8.5.4)
- Removing phpunit/php-timer (2.1.2)
- Removing phpspec/prophecy (1.12.1)
- Removing phar-io/manifest (1.0.3)
- Removing guzzlehttp/psr7 (1.7.0)
- Removing guzzlehttp/guzzle (6.5.5)
- Upgrading myclabs/php-enum (1.7.6 => 1.8.3): Extracting archive
- Upgrading phpdocumentor/type-resolver (1.4.0 => 1.6.1): Extracting archive
- Upgrading markbaker/matrix (1.2.1 => 1.2.3): Extracting archive
- Upgrading symfony/polyfill-mbstring (v1.18.1 => v1.25.0): Extracting archive

- Upgrading sebastian/environment (4.2.3 => 4.2.4): Extracting archive
- Upgrading phpunit/php-file-iterator (2.0.2 => 2.0.5): Extracting archive
- Upgrading psr/container (1.0.0 => 1.1.1): Extracting archive
- Upgrading sebastian/object-reflector (1.1.1 => 1.1.2): Extracting archive
- Upgrading symfony/polyfill-php72 (v1.18.1 => v1.25.0): Extracting archive
- Upgrading symfony/var-dumper (v4.4.15 => v4.4.39): Extracting archive
- Upgrading psr/log (1.1.3 => 1.1.4): Extracting archive
- Upgrading topthink/framework (v6.0.4 => v6.0.8): Extracting archive
0/14 [>---------------------------] 0%
10/14 [====================>-------] 71%
13/14 [==========================>-] 92%
14/14 [============================] 100%
22 package suggestions were added by new dependencies, use `composer suggest` to
see details.
Package phpunit/php-token-stream is abandoned, you should avoid using it. No rep
lacement was suggested.
Generating autoload files
> @php think service:discover
Succeed!
> @php think vendor:publish
File C:\phpstudy_pro\WWW\config\trace.php exist!
Succeed!
7 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

posted on 2022-04-04 17:12  生龙活虎1986  阅读(999)  评论(0编辑  收藏  举报