дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-06 10:07:11 +02:00
feat(run): Symfony server run configuration (#7557)
Symfony projects (framework dependency, bin/console and public/index.php present) get a detected PHP built-in server run configuration serving through the front controller; Debug keeps PHP's web-server arguments. Co-authored-by: samehelhawary <[email protected]>
Цей коміт міститься в:
1 джерело
15b55c66ca
коміт
3785b75582
8 files changed
+89
-5
No files matched your search
@@ -1450,6 +1450,17 @@ fn detect_php(root: &Path, out: &mut Vec<RunConfig>) {
|
||||
if root.join("artisan").is_file() {
|
||||
out.push(config("php:artisan-serve", "artisan serve", "php", "php", &["artisan", "serve"]).debug("php-debug"));
|
||||
}
|
||||
// A Symfony application: PHP's own web server on the front controller's folder. The
|
||||
// Symfony CLI's `symfony serve` is not required, and cannot be given Xdebug's options.
|
||||
if requires("symfony/framework-bundle")
|
||||
&& root.join("bin/console").is_file()
|
||||
&& root.join("public/index.php").is_file()
|
||||
{
|
||||
out.push(
|
||||
config("php:symfony-serve", "Symfony server", "php", "php", &["-S", "127.0.0.1:8000", "-t", "public"])
|
||||
.debug("php-debug"),
|
||||
);
|
||||
}
|
||||
let scripts = composer.as_ref().and_then(|c| c.get("scripts")).and_then(Json::as_object);
|
||||
for name in scripts.into_iter().flat_map(|m| m.keys()) {
|
||||
if is_composer_event(name) {
|
||||
|
||||
@@ -1286,6 +1286,41 @@ fn php_pest_project() {
|
||||
assert_eq!(find(&detect(dir.path()), "phpunit").name, "PHPUnit");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn php_framework_servers() {
|
||||
// Laravel: `artisan` at the root.
|
||||
let dir = project(&[("composer.json", r#"{"require":{"laravel/framework":"^12"}}"#), ("artisan", "")]);
|
||||
let c = detect(dir.path());
|
||||
assert_eq!(ids(&c), ["php:artisan-serve"]);
|
||||
let serve = find(&c, "php:artisan-serve");
|
||||
assert_eq!((serve.kind.as_str(), cmdline(serve).as_str()), ("php", "php artisan serve"));
|
||||
assert_eq!(serve.debug_adapter.as_deref(), Some("php-debug"));
|
||||
assert!(!serve.is_test);
|
||||
|
||||
// Symfony: the framework bundle, its console and a front controller.
|
||||
let symfony = r#"{"require":{"symfony/framework-bundle":"^7.2"}}"#;
|
||||
let dir = project(&[("composer.json", symfony), ("bin/console", ""), ("public/index.php", "<?php")]);
|
||||
let c = detect(dir.path());
|
||||
assert_eq!(ids(&c), ["php:symfony-serve"]);
|
||||
let serve = find(&c, "php:symfony-serve");
|
||||
assert_eq!(serve.name, "Symfony server");
|
||||
assert_eq!((serve.kind.as_str(), cmdline(serve).as_str()), ("php", "php -S 127.0.0.1:8000 -t public"));
|
||||
assert_eq!(serve.debug_adapter.as_deref(), Some("php-debug"));
|
||||
|
||||
// A library that uses the bundle, or a console tool without a front controller, serves nothing.
|
||||
for files in [
|
||||
&[("composer.json", symfony), ("public/index.php", "<?php")][..],
|
||||
&[("composer.json", symfony), ("bin/console", "")][..],
|
||||
&[
|
||||
("composer.json", r#"{"require":{"symfony/console":"^7.2"}}"#),
|
||||
("bin/console", ""),
|
||||
("public/index.php", ""),
|
||||
][..],
|
||||
] {
|
||||
assert!(detect(project(files).path()).is_empty(), "{files:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn php_detection_needs_a_marker() {
|
||||
let dir = project(&[("index.php", "<?php")]);
|
||||
|
||||
@@ -206,7 +206,7 @@ Run configurations are detected from the build files in your project. The table
|
||||
| Go | `go.mod` | Go Build, Go Test |
|
||||
| Java / Kotlin | `pom.xml`, Gradle build files | Maven goals, Gradle tasks, Application, JAR Application, Spring Boot, Tomcat |
|
||||
| Python | `pyproject.toml`, `setup.py`, `requirements.txt`, `manage.py`, a `.venv`, ... | `python -m <package>`, pytest, Django `runserver` and tests |
|
||||
| PHP | `composer.json`, `phpunit.xml` | Composer scripts, PHPUnit or Pest, Laravel `artisan serve` |
|
||||
| PHP | `composer.json`, `phpunit.xml` | Composer scripts, PHPUnit or Pest, Laravel `artisan serve`, Symfony server |
|
||||
| Ruby | `Gemfile`, `Rakefile`, `*.gemspec`, `config.ru` | Rails server, Rake tasks, RSpec, Minitest |
|
||||
| C / C++ | `CMakeLists.txt` | CMake targets |
|
||||
| C# | `.sln`, `.slnx`, `.csproj` | .NET Project, `dotnet test` |
|
||||
|
||||
@@ -83,9 +83,11 @@ The PHPUnit run configuration type has **Target**, **Configuration file**, **Tes
|
||||
|
||||
## Debugging
|
||||
|
||||
- **Symfony server** in Symfony applications (`symfony/framework-bundle`, `bin/console` and `public/index.php`): PHP's own web server, `php -S 127.0.0.1:8000 -t public`. The Symfony CLI is not needed.
|
||||
|
||||
Debugging uses PHP Debug (vscode-php-debug) with Xdebug. The selected PHP must load the Xdebug extension; the PHP settings page shows whether it does.
|
||||
|
||||
- **Debug** works on PHP files, PHPUnit/Pest and `artisan serve`. The IDE turns on Xdebug for the session with `-d` options and a free port, so you don't need to edit `php.ini`, and another IDE listening on 9003 doesn't conflict.
|
||||
- **Debug** works on PHP files, PHPUnit/Pest, `artisan serve` and the Symfony server. The IDE turns on Xdebug for the session with `-d` options and a free port, so you don't need to edit `php.ini`, and another IDE listening on 9003 doesn't conflict.
|
||||
- **PHP Remote Debug (Xdebug)** is a run configuration type that listens for incoming Xdebug connections (default port 9003), for requests served elsewhere such as php-fpm or a container. Its **Start the remote side with** field shows the matching `php -dxdebug.mode=debug …` command; for web requests use the `XDEBUG_SESSION` cookie or query parameter. Set **Local root** and **Remote root** to map paths.
|
||||
|
||||
See [Debugging](/en/guide/debugging).
|
||||
|
||||
@@ -200,7 +200,7 @@ IDE 安装工具从不需要 `sudo`。工具装在本地数据目录下 IDE 自
|
||||
| Go | `go.mod` | Go Build、Go Test |
|
||||
| Java / Kotlin | `pom.xml`、Gradle 构建文件 | Maven 目标、Gradle 任务、Application、JAR Application、Spring Boot、Tomcat |
|
||||
| Python | `pyproject.toml`、`setup.py`、`requirements.txt`、`manage.py`、`.venv` 等 | `python -m <package>`、pytest、Django `runserver` 和测试 |
|
||||
| PHP | `composer.json`、`phpunit.xml` | Composer 脚本、PHPUnit 或 Pest、Laravel `artisan serve` |
|
||||
| PHP | `composer.json`、`phpunit.xml` | Composer 脚本、PHPUnit 或 Pest、Laravel `artisan serve`、Symfony server |
|
||||
| Ruby | `Gemfile`、`Rakefile`、`*.gemspec`、`config.ru` | Rails server、Rake 任务、RSpec、Minitest |
|
||||
| C / C++ | `CMakeLists.txt` | CMake 目标 |
|
||||
| C# | `.sln`、`.slnx`、`.csproj` | .NET Project、`dotnet test` |
|
||||
|
||||
@@ -83,9 +83,11 @@ PHPUnit 运行配置类型包含 **目标**、**配置文件**、**测试过滤
|
||||
|
||||
## 调试
|
||||
|
||||
- Symfony 应用(依赖 `symfony/framework-bundle`,并有 `bin/console` 和 `public/index.php`)中的 **Symfony server**:PHP 自带的 Web 服务器,`php -S 127.0.0.1:8000 -t public`,不需要 Symfony CLI。
|
||||
|
||||
调试使用 PHP Debug(vscode-php-debug)配合 Xdebug。所选 PHP 必须已加载 Xdebug 扩展,PHP 设置页会显示是否已加载。
|
||||
|
||||
- **调试** 适用于 PHP 文件、PHPUnit/Pest 和 `artisan serve`。IDE 通过 `-d` 选项为本次会话开启 Xdebug 并使用空闲端口,不需要改 `php.ini`,也不会与另一个监听 9003 端口的 IDE 冲突。
|
||||
- **调试** 适用于 PHP 文件、PHPUnit/Pest、`artisan serve` 和 Symfony server。IDE 通过 `-d` 选项为本次会话开启 Xdebug 并使用空闲端口,不需要改 `php.ini`,也不会与另一个监听 9003 端口的 IDE 冲突。
|
||||
- **PHP 远程调试 (Xdebug)** 是一种运行配置类型,用于监听外部的 Xdebug 连接(默认端口 9003),适合调试 php-fpm、容器等其他地方处理的请求。其 **远程端启动命令** 字段给出对应的 `php -dxdebug.mode=debug …` 命令;Web 请求可使用 `XDEBUG_SESSION` cookie 或查询参数。用 **本地根目录** 和 **远程根目录** 做路径映射。
|
||||
|
||||
详见[调试](/zh/guide/debugging)。
|
||||
|
||||
@@ -158,6 +158,26 @@ describe("run config → launch config", () => {
|
||||
runtimeArgs: [...xdebug, "-dmemory_limit=1G"],
|
||||
runtimeExecutable: "/usr/bin/php8.4",
|
||||
});
|
||||
// PHP's own web server (Symfony): an option's value is not the script, and there is none.
|
||||
const server = launchConfigFor(
|
||||
rc({ kind: "php", command: "php", args: ["-S", "127.0.0.1:8000", "-t", "public"], debugAdapter: "php-debug" }),
|
||||
"/app",
|
||||
"/opt/[email protected]/bin/php",
|
||||
)!;
|
||||
expect(server).toMatchObject({ adapter: "php-debug", program: "", args: [], cwd: "/app" });
|
||||
expect(extra(server).runtimeArgs).toEqual([...xdebug, "-S", "127.0.0.1:8000", "-t", "public"]);
|
||||
// … and with a router script, that is the program.
|
||||
const router = launchConfigFor(
|
||||
rc({
|
||||
kind: "php",
|
||||
command: "php",
|
||||
args: ["-S", "127.0.0.1:8000", "public/router.php"],
|
||||
debugAdapter: "php-debug",
|
||||
}),
|
||||
"/app",
|
||||
)!;
|
||||
expect(router).toMatchObject({ program: "/app/public/router.php", args: [] });
|
||||
expect(extra(router).runtimeArgs).toEqual([...xdebug, "-S", "127.0.0.1:8000"]);
|
||||
// PHPUnit runs its script directly; without a PHP in Settings, php-debug uses the `php` on PATH.
|
||||
const unit = launchConfigFor(
|
||||
rc({ kind: "phpunit", command: "vendor/bin/phpunit", args: ["--filter", "testA"], debugAdapter: "php-debug" }),
|
||||
|
||||
@@ -484,6 +484,19 @@ function flutterAttach(rc: RunConfig, cwd: string, adapter: string): LaunchConfi
|
||||
|
||||
const PHP_NAME = /^php(\d+(\.\d+)*)?(\.exe)?$/i;
|
||||
|
||||
/** PHP's options whose value is the next argument (`-S 127.0.0.1:8000`, `-t public`). */
|
||||
const PHP_VALUE_OPTIONS = new Set(["-S", "-t", "-c", "-d", "-z"]);
|
||||
|
||||
/** Where the script is among `php`'s arguments, after its options and their values; -1 without one. */
|
||||
function phpScriptIndex(args: string[]): number {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const arg = args[i]!;
|
||||
if (PHP_VALUE_OPTIONS.has(arg)) i++;
|
||||
else if (!arg.startsWith("-")) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* php-debug runs `runtimeExecutable runtimeArgs program args` and doesn't enable Xdebug: debug mode and
|
||||
* the connection back come from `-d` options, to the free port php-debug picks for `port: 0` (another
|
||||
@@ -497,8 +510,9 @@ function phpDebugLaunch(rc: RunConfig, cwd: string, php: string | null): LaunchC
|
||||
let args: string[];
|
||||
if (PHP_NAME.test(name)) {
|
||||
// `php [options] script args`: the options stay with PHP; the script is a file (`artisan`).
|
||||
// Its own web server (`php -S … -t public`) has none: every request is a session.
|
||||
if (name !== rc.command) runtime = resolveCommand(rc.command, cwd);
|
||||
const at = rc.args.findIndex((a) => !a.startsWith("-"));
|
||||
const at = phpScriptIndex(rc.args);
|
||||
runtimeArgs.push(...(at < 0 ? rc.args : rc.args.slice(0, at)));
|
||||
program = at < 0 ? "" : join(cwd, rc.args[at]!);
|
||||
args = at < 0 ? [] : rc.args.slice(at + 1);
|
||||
|
||||
Reference in new issue
Заблокувати користувача