常見問題

ThinkPHP6.1 升級到 8.0

常見問題

3352

字體:

最近看見社區(qū)非常多小伙伴在問 ThinkPHP6.1 升級到 8.0 的問題,這里我就來簡單的介紹一下升級的方法。

首先,我先本地安裝個 ThinkPHP6.1 的開發(fā)版。

1
$ composer create-project topthink/think=6.1.x-dev thinkphp61

現(xiàn)在查看下項目的依賴信息。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$ cd thinkphp61
$ composer show
league/flysystem                1.1.10  Filesystem abstraction: Many filesystems, one API.
league/flysystem-cached-adapter 1.1.0   An adapter decorator to enable meta-data caching.
league/mime-type-detection      1.11.0  Mime-type detection for Flysystem
psr/cache                       1.0.1   Common interface for caching libraries
psr/container                   1.1.2   Common Container Interface (PHP FIG PSR-11)
psr/http-message                1.1     Common interface for HTTP messages
psr/log                         1.1.4   Common interface for logging libraries
psr/simple-cache                1.0.1   Common interfaces for simple caching
symfony/polyfill-mbstring       v1.27.0 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72          v1.27.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions
symfony/polyfill-php80          v1.27.0 Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions
symfony/var-dumper              v4.4.47 Provides mechanisms for walking through any arbitrary PHP variable
topthink/framework              v6.1.4  The ThinkPHP Framework.
topthink/think-filesystem       v1.0.3  The ThinkPHP6.1 Filesystem Package
topthink/think-helper           v3.1.6  The ThinkPHP6 Helper Package
topthink/think-orm              v2.0.61 think orm
topthink/think-trace            v1.6    thinkphp debug trace

貼一下項目的 composer.json 文件。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
{
   "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": {
       "php": ">=7.2.5",
       "topthink/framework": "^6.1.0",
       "topthink/think-orm": "^2.0",
       "topthink/think-filesystem": "^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"
       ]
   }
}

其中 require、 require-dev 是依賴的信息,里面進行了一些版本的鎖定,比如 ^6.1.0 那可以理解為 >=6.1.0<7.0.0,所以很多小伙伴進行升級的時候因為版本號鎖定問題就沒辦法直接升級,這里我們要對一些依賴進行調(diào)整。

修改前修改后
"php": ">=7.2.5""php": ">=8.0.0"
"topthink/framework": "^6.1.0""topthink/framework": "^8.0.0"
"topthink/think-orm": "^2.0""topthink/think-orm": "^3.0"
"topthink/think-filesystem": "^1.0""topthink/think-filesystem": "^2.0"
"symfony/var-dumper": "^4.2""symfony/var-dumper": ">=4.2"

這里我沒辦法把全部都提供,比如如果你使用 ThinkPHP 官方提供的依賴,那現(xiàn)在大多數(shù)都支持 8.0 了,你可以去相關(guān)的 github 倉庫查看。

在 composer.json 里面修改完依賴后,你還需要把本地的 composer.lock 刪除然后再執(zhí)行 composer install,這樣才能保證依賴的版本是最新的。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
$ rm -f composer.lock
$ composer install
Loading composer repositories with package information
Updating dependencies
Lock file operations: 13 installs, 0 updates, 0 removals
 - Locking league/flysystem (2.5.0)
 - Locking league/mime-type-detection (1.11.0)
 - Locking psr/container (2.0.2)
 - Locking psr/http-message (1.1)
 - Locking psr/log (3.0.0)
 - Locking psr/simple-cache (3.0.0)
 - Locking symfony/polyfill-mbstring (v1.27.0)
 - Locking symfony/var-dumper (v6.3.1)
 - Locking topthink/framework (v8.0.1)
 - Locking topthink/think-filesystem (v2.0.2)
 - Locking topthink/think-helper (v3.1.6)
 - Locking topthink/think-orm (v3.0.10)
 - Locking topthink/think-trace (v1.6)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 8 updates, 4 removals
 - Downloading topthink/framework (v8.0.1)
 - Removing symfony/polyfill-php80 (v1.27.0)
 - Removing symfony/polyfill-php72 (v1.27.0)
 - Removing psr/cache (1.0.1)
 - Removing league/flysystem-cached-adapter (1.1.0)
 - Upgrading psr/container (1.1.2 => 2.0.2): Extracting archive
 - Upgrading symfony/var-dumper (v4.4.47 => v6.3.1): Extracting archive
 - Upgrading psr/simple-cache (1.0.1 => 3.0.0): Extracting archive
 - Upgrading psr/log (1.1.4 => 3.0.0): Extracting archive
 - Upgrading topthink/think-orm (v2.0.61 => v3.0.10): Extracting archive
 - Upgrading topthink/framework (v6.1.4 => v8.0.1): Extracting archive
 - Upgrading league/flysystem (1.1.10 => 2.5.0): Extracting archive
 - Upgrading topthink/think-filesystem (v1.0.3 => v2.0.2): Extracting archive
Generating autoload files
> @php think service:discover
Succeed!
> @php think vendor:publish
File /code/thinkphp61/config/trace.php exist!
Succeed!
4 packages you are using are looking for funding.
Use the `composer fund` command to find out more!

重新打印下依賴信息。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ composer show
league/flysystem           2.5.0   File storage abstraction for PHP
league/mime-type-detection 1.11.0  Mime-type detection for Flysystem
psr/container              2.0.2   Common Container Interface (PHP FIG PSR-11)
psr/http-message           1.1     Common interface for HTTP messages
psr/log                    3.0.0   Common interface for logging libraries
psr/simple-cache           3.0.0   Common interfaces for simple caching
symfony/polyfill-mbstring  v1.27.0 Symfony polyfill for the Mbstring extension
symfony/var-dumper         v6.3.1  Provides mechanisms for walking through any arbitrary PHP variable
topthink/framework         v8.0.1  The ThinkPHP Framework.
topthink/think-filesystem  v2.0.2  The ThinkPHP6.1 Filesystem Package
topthink/think-helper      v3.1.6  The ThinkPHP6 Helper Package
topthink/think-orm         v3.0.10 the PHP Database&ORM Framework
topthink/think-trace       v1.6    thinkphp debug trace

好了,現(xiàn)在就算是升級到 ThinkPHP 8.0 了。


[聲明]原創(chuàng)不易,請轉(zhuǎn)發(fā)者備注下文章來源(hbsjsd.cn)【速建時代】。