PHPackages                             yangweijie/rector-thinkphp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. yangweijie/rector-thinkphp

ActiveRector-extension[Utility &amp; Helpers](/categories/utility)

yangweijie/rector-thinkphp
==========================

Rector rules for upgrading ThinkPHP projects from version 3.1.2 to 8.1

05PHP

Since Jul 2Pushed 10mo agoCompare

[ Source](https://github.com/yangweijie/rector-thinkphp)[ Packagist](https://packagist.org/packages/yangweijie/rector-thinkphp)[ RSS](/packages/yangweijie-rector-thinkphp/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Rector ThinkPHP
===============

[](#rector-thinkphp)

[![Build Status](https://github.com/rector/rector-thinkphp/workflows/CI/badge.svg)](https://github.com/rector/rector-thinkphp/actions)[![Downloads](https://camo.githubusercontent.com/7a35d5586f6405e184f20640e38c1e296b082811e441c42350b460803ef77027/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726563746f722f726563746f722d7468696e6b7068702e737667)](https://packagist.org/packages/rector/rector-thinkphp)

Rector rules for upgrading ThinkPHP projects from version 3.1.2 to 8.1.

Features
--------

[](#features)

### 🚀 **Core Transformation Engine**

[](#-core-transformation-engine)

- **Automated Code Transformation**: Converts ThinkPHP 3.2 code to modern versions (up to 8.0)
- **Namespace Updates**: Automatically updates class namespaces and imports
- **Method Modernization**: Converts deprecated method calls to new syntax
- **Database Query Updates**: Modernizes database query syntax
- **Template Syntax**: Converts template syntax between versions

### 🧙‍♂️ **Interactive Upgrade Wizard**

[](#‍️-interactive-upgrade-wizard)

- **Smart Version Detection**: Automatically detects your current ThinkPHP version
- **Guided Upgrade Process**: Step-by-step interactive upgrade wizard
- **Backup Creation**: Automatic backup before making changes
- **Comprehensive Analysis**: Code quality analysis and improvement suggestions

### 🔧 **Advanced Services**

[](#-advanced-services)

- **Configuration Migration**: Automatically migrates config files between versions
- **Dependency Management**: Updates composer.json with correct dependencies
- **Template Conversion**: Handles template syntax changes across versions
- **Code Quality Analysis**: Identifies issues and provides improvement suggestions
- **Upgrade Reports**: Generates detailed reports of all changes made

### 📊 **Quality Assurance**

[](#-quality-assurance)

- **Comprehensive Testing**: 49 test cases ensure reliable transformations
- **Dry Run Mode**: Preview changes before applying them
- **Validation**: Validates configurations and dependencies after upgrade
- **Error Handling**: Robust error handling with detailed feedback

Installation
------------

[](#installation)

```
composer require --dev yangweijie/rector-thinkphp
```

For detailed installation instructions, see [INSTALLATION.md](INSTALLATION.md).

Usage
-----

[](#usage)

### 🧙‍♂️ **Interactive Upgrade Wizard (Recommended)**

[](#‍️-interactive-upgrade-wizard-recommended)

The easiest way to upgrade your ThinkPHP project:

```
# Using the standalone tool (recommended)
./vendor/bin/thinkphp-rector thinkphp:upgrade-wizard /path/to/your/project

# Or using rector directly (if properly configured)
vendor/bin/rector thinkphp:upgrade-wizard /path/to/your/project
```

The wizard will:

- Automatically detect your current ThinkPHP version
- Guide you through selecting the target version
- Create backups if requested
- Migrate configurations and dependencies
- Convert template syntax
- Run code transformations
- Generate a comprehensive upgrade report

#### Wizard Options

[](#wizard-options)

```
# Specify versions explicitly
./vendor/bin/thinkphp-rector thinkphp:upgrade-wizard /path/to/project --from-version=5.0 --to-version=6.0

# Create backup before upgrading
./vendor/bin/thinkphp-rector thinkphp:upgrade-wizard /path/to/project --backup

# Preview changes without applying them
./vendor/bin/thinkphp-rector thinkphp:upgrade-wizard /path/to/project --dry-run
```

### 📦 **Batch Upgrade Multiple Projects**

[](#-batch-upgrade-multiple-projects)

For upgrading multiple projects at once:

```
./vendor/bin/thinkphp-rector thinkphp:batch-upgrade config/batch-upgrade.json
```

Example batch configuration file:

```
{
  "projects": {
    "project-alpha": {
      "path": "/var/www/project-alpha",
      "from_version": "3.2",
      "to_version": "6.0",
      "backup": true
    },
    "project-beta": {
      "path": "/var/www/project-beta",
      "from_version": "5.0",
      "to_version": "8.0",
      "backup": false
    }
  }
}
```

### ⚙️ **Manual Configuration**

[](#️-manual-configuration)

Create a `rector.php` configuration file in your project root:

```
