1. 程式人生 > 其它 >從已有安裝包(vendor)恢復thinkphp6 composer.json

從已有安裝包(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": "[email protected]"
        }
    ],
    "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 配置段。

 

 

 

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!