PHP 项目开发

一、PHP Cursor 配置

1、安装 PHP 扩展

  • PHP Intelephense
  • PHP Debug
  • PHP DocBlocker
  • PHP Extension Pack

2、配置 PHP 路径

{
    "window.commandCenter": 1,
    "java.configuration.maven.userSettings": "F:\\Maven\\apache-maven-3.5.2\\conf\\settings.xml",
    "maven.excludedFolders": [
        "**/.*",
        "**/node_modules",
        "**/target",
        "**/bin",
        "**/archetype-resources"
    ],
    "pythonIndent.keepHangingBracketOnLine": true,
    "pythonIndent.trimLinesWithOnlyWhitespace": true,
    "pythonIndent.useTabOnHangingIndent": true,
    "git.ignoreMissingGitWarning": true,
    "php.validate.executablePath": "F:\\Development\\PHP\\php-7.4.29-Win32-vc15-x64\\php.exe"
}

3、配置 PHP 调试
在项目根目录创建 .vscode/launch.json 文件:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003,
            "pathMappings": {
                "/var/www/html": "${workspaceFolder}"
            }
        }
    ]
}

4、配置 PHP 代码格式化
在设置中配置 PHP 格式化工具
推荐使用 PHP-CS-Fixer 或 Prettier

5、配置 PHP 代码检查
在设置中启用 PHP 代码检查
可以配置 PHP_CodeSniffer 或 PHPStan

6、配置 PHP 自动完成
确保 PHP Intelephense 扩展已启用
在设置中配置自动完成选项

7、配置 PHP 文档生成
安装 PHP DocBlocker 扩展
配置文档注释模板

8、配置 PHP 测试
安装 PHPUnit 扩展
配置测试运行器

9、配置 PHP 项目结构
创建标准的 PHP 项目结构:

project/
├── src/
│   └── YourNamespace/
├── tests/
├── vendor/
├── composer.json
└── .gitignore

10、配置 Composer
安装 Composer
在项目根目录创建 composer.json

{
    "name": "your-vendor/your-project",
    "description": "Your project description",
    "type": "project",
    "require": {
        "php": ">=7.4"
    },
    "autoload": {
        "psr-4": {
            "YourNamespace\\": "src/"
        }
    }
}

11、配置 PHP 错误报告
php.ini 中设置:

error_reporting = E_ALL
display_errors = On
display_startup_errors = On
log_errors = On
error_log = "C:\php\logs\php_error.log"

12、配置 PHP 性能优化
php.ini 中设置:

opcache.enable=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1

13、配置 PHP 安全设置
php.ini 中设置:

expose_php = Off
session.cookie_httponly = 1
session.cookie_secure = 1

14、配置 PHP 开发工具
安装 Xdebug 用于调试
配置 Xdebug 设置:

[xdebug]
zend_extension=xdebug
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_port=9003

15、配置 PHP 代码质量工具
安装 PHP_CodeSniffer
配置编码标准。

评论

暂无

添加新评论