дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 01:01:17 +02:00
PHPantom has its own Blade, Twig and framework support, but Twig, YAML and XML files were never sent to it, laravel-lsp kept running alongside it, and it was never told the project is trusted. PHPantom now joins twig, yaml and xml (XML limited to *.xml, *.xlf, *.xliff), replaces laravel-lsp, gets .phpantom.toml as a root marker, and configure_phpantom sends workspaceTrusted (servers only start outside Restricted Mode) plus the excluded folders and PHP file-type extensions as its indexing filters at startup and on every configuration change. Docs updated. Co-authored-by: AJenbo <[email protected]>
154 рядки
18 KiB
Plaintext
154 рядки
18 KiB
Plaintext
---
|
||
title: "PHP"
|
||
description: "Intelephense, PHPantom and Phoxite, PHP interpreters and language level, Composer, PHPUnit and Pest, PHPStan, Xdebug debugging, Blade and Twig templates, and Laravel, Symfony and other framework support."
|
||
---
|
||
|
||
OpenIDEA highlights PHP files (`.php`, `.phtml`, `.phpt` and older `.php3`–`.php5`, plus files starting with `<?php` or a `php` shebang), Blade views (`.blade.php`) and Twig templates (`.twig`) out of the box. Completion, navigation, refactoring and diagnostics come from Intelephense. Composer scripts, PHPUnit/Pest suites and Laravel's development server are detected as run configurations, and Xdebug sessions run through the PHP Debug adapter. See the [support matrix](/en/languages/index) for other languages.
|
||
|
||
## Language servers
|
||
|
||
| Server | When it runs |
|
||
| ----------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||
| `intelephense` | Default. Workspace root: `composer.json`, `.phpactor.json` or `index.php`. |
|
||
| `phpantom` | Fallback with its own framework, Blade and Twig support (see [Frameworks](#frameworks)): used while Intelephense is not installed, or when you pick it in **Settings › Languages & Frameworks › Language Servers**. |
|
||
| `phpactor` | Fallback: used only while neither server above is installed. |
|
||
| `phoxite` | Alternative with its own framework, Blade and Twig support (see [Frameworks](#frameworks)): used while no server above is installed, or when you pick it in **Settings › Languages & Frameworks › Language Servers**. |
|
||
| `devsense-php-ls` | Alternative whose engine ships as native builds, so the server itself needs no Node or PHP: used while no server above is installed, or when you pick it in **Settings › Languages & Frameworks › Language Servers**. |
|
||
| `laravel-lsp` | Laravel projects only (below an `artisan` file): hover, definition and completion inside `config('…')`, `route('…')` and `view('…')`. |
|
||
|
||
A Blade view is served by the same servers as the project's PHP files. While PHPantom, Phoxite or DEVSENSE serves a project, `laravel-lsp` is not started: they answer the Laravel strings themselves.
|
||
|
||
PHPantom, where it is the project's PHP server, also reads Twig templates, and YAML and XML files: Symfony and Drupal configuration, Doctrine mappings and XLIFF translation catalogues. It runs once for all of them, next to those languages' own servers, and is never started for a project without PHP.
|
||
|
||
Phoxite, where it is the project's PHP server, also reads files of other languages: Twig templates, `.env` files and Laravel's `lang/*.json`. It runs once for all of them, next to those languages' own servers, and is never started for a project without PHP.
|
||
|
||
Phoxite, once it finds one of these platforms in the project, also reads the platform's own files, so the names it knows in PHP (services, routes, hooks, configuration paths, language keys) complete and navigate there too:
|
||
|
||
| Platform | Files |
|
||
| --------- | ---------------------------------------------------------------------------------------------- |
|
||
| WordPress | JavaScript and TypeScript files, and `block.json` |
|
||
| Drupal | A module's or theme's `*.yml` (`*.services.yml`, `*.routing.yml`, `*.info.yml`, …) and `.info` |
|
||
| Magento | A module's `etc/**/*.xml`, layout and UI component XML, and `schema.graphqls` |
|
||
| Joomla | Manifests, forms and other XML, `language/**/*.ini` and `joomla.asset.json` |
|
||
|
||
Those files keep their own language servers (the YAML, XML and TypeScript ones); Phoxite adds its answers to theirs, in the project where it already runs for PHP.
|
||
|
||
DEVSENSE is usable without a licence for everyday code insight (completion, hover, go to definition, references, diagnostics, Laravel and Blade support); its refactorings and call/type hierarchy need a DEVSENSE licence.
|
||
|
||
Intelephense checks code against the project's PHP version (see [Language level](#language-level)) and indexes the stubs and include paths you configure.
|
||
|
||
## Setup
|
||
|
||
### Installing the tools
|
||
|
||
When a `.php` file opens and Intelephense is missing, a notification offers **Install**. The IDE installs it with npm into its own tools folder (needs `npm` or `pnpm` on `PATH`). Everything is also listed in **Settings › Languages & Frameworks › Language Servers**.
|
||
|
||
| Tool | Installed with |
|
||
| ------------------ | ------------------------------------------------------------------ |
|
||
| Intelephense | npm (`intelephense`) |
|
||
| PHPantom | GitHub release (`PHPantom-dev/phpantom_lsp`) |
|
||
| Phpactor | GitHub release (`phpactor/phpactor`, `phpactor.phar`); runs on PHP |
|
||
| Laravel LSP | GitHub release (`laravel/lsp`) |
|
||
| Phoxite | GitHub release (`samehelhawary/phoxite`) |
|
||
| DEVSENSE | npm (`devsense-php-ls`); needs Node.js to launch |
|
||
| PHP Debug (Xdebug) | Open VSX (`xdebug.php-debug`); needs Node.js to run |
|
||
|
||
### PHP interpreter
|
||
|
||
**Settings › Languages & Frameworks › PHP**, section **CLI Interpreter**:
|
||
|
||
- **PHP interpreter**: the `php` that runs scripts, PHPUnit, Composer, `artisan` and PHP-based servers such as phpactor. **Default** uses `php` on `PATH`. Its folder is put first on `PATH`, so `vendor/bin/phpunit` and other `#!/usr/bin/env php` scripts use the same PHP. The list includes PHP found on `PATH` (also versioned binaries like `php8.3`), Homebrew, phpbrew, phpenv, Laravel Herd, and on Windows XAMPP and Laragon.
|
||
- **Run in target**: run PHP and Composer commands locally or in a run target from **Settings › Build, Execution, Deployment › Run Targets**. A target runs the `php` on its own `PATH`; set the target's **PHP interpreter** to run another one, such as `/usr/local/bin/php8.3`.
|
||
- The page shows the selected PHP's version and the loaded Xdebug version (or **Not installed**). When PHP runs in a Docker or Docker Compose run target, it shows the version and Xdebug of the PHP in the container instead: the IDE starts that PHP once in a new container, removed when it exits, and keeps the answer. Click the refresh button after the image changes.
|
||
|
||
### Language level
|
||
|
||
**PHP language level** on the same page sets the version Intelephense checks against (5.6 to 8.5); newer syntax and functions are reported. **Auto** uses `config.platform.php` from `composer.json`, else the lowest version `require.php` allows. The status bar shows the current level; click it to switch.
|
||
|
||
Also on this page:
|
||
|
||
- **Include paths**: folders outside the project that Intelephense indexes too, such as a platform your module extends.
|
||
- **Additional stubs**: Intelephense stub sets on top of its defaults (for example `wordpress`). Each `ext-*` in `require` / `require-dev` of `composer.json` adds its own stubs automatically.
|
||
|
||
Phoxite receives the same settings: a language level you choose (for **Auto** it reads `composer.json` itself), the include paths, the additional stubs, and the PHP interpreter for the analysers it runs. Its own settings, such as `frameworks` to turn a framework's support on or off (`{ "frameworks": { "wordpress": "disabled" } }`), go in **Settings › Languages & Frameworks › Language Servers › Phoxite › Workspace Configuration**, or in a `phoxite.json` at the project root.
|
||
|
||
PHPantom reads the PHP version from `composer.json` (or its own `.phpantom.toml`) and does not use the include paths or additional stubs. It is told the project is trusted, so it runs the project's PHPStan, PHP_CodeSniffer and formatters without asking, and it skips the folders excluded in **Settings › Project Structure** and **Settings › Editor › File Types** and indexes the extensions added to PHP there (such as `module` for Drupal). Its own settings go in a `.phpantom.toml` at the project root.
|
||
|
||
### Composer
|
||
|
||
In a Composer project without `vendor/`, or whose installed packages differ from `composer.lock`, a banner "Composer dependencies are not installed" appears above PHP files and `composer.json`, with **Install** (runs `composer install` on the configured PHP) and **Ignore**.
|
||
|
||
## Static analysis and formatting
|
||
|
||
- **PHPStan**: when the project has `vendor/bin/phpstan`, saved files are checked with it and its findings appear as diagnostics. The **PHPStan › Configuration file** setting picks the config; empty uses `phpstan.neon`, `phpstan.neon.dist` or `phpstan.dist.neon` in the project root.
|
||
- **In a Docker or Compose run target**: when **Run in target** is such a target, PHPStan and PHP-CS-Fixer run with the target's PHP, each in a new container that is removed when it ends, and PHPStan's findings open the files here. The container gets no published ports, skips the image's entrypoint and does not start the service's dependencies. `vendor` and the configuration files must be in a folder the container mounts. PHPStan keeps its result cache in the container's temporary folder by default, which is gone with the container: set `tmpDir` in `phpstan.neon` to a folder of the project to keep it between checks.
|
||
- **PHP-CS-Fixer**: when a folder above the file has `.php-cs-fixer.php` or `.php-cs-fixer.dist.php` and the project has `vendor/bin/php-cs-fixer`, **Reformat Code** (`⌥⌘L` / `Ctrl+Alt+L`) uses PHP-CS-Fixer instead of the language server.
|
||
- **Alignment**: **Settings › Editor › Code Style › PHP › Alignment** has PhpStorm's **Align key-value pairs** (`=>` in multi-line arrays) and **Align consecutive assignments** (`=` in assignment statements on consecutive lines), both off by default. They apply after the language server or PHP-CS-Fixer formats, on save too; for a selection, only to its lines. A blank line, a comment line, another statement or a value spanning several lines starts a new group, and nested arrays align on their own.
|
||
|
||
## Run and test
|
||
|
||
Detected when the project has `composer.json` or a PHPUnit configuration:
|
||
|
||
- `composer <script>` for each script in `composer.json` (Composer event hooks are skipped); a script named `test` is a test configuration.
|
||
- **PHPUnit** (or **Pest**, when `vendor/bin/pest` exists) when there is `phpunit.xml`, `phpunit.xml.dist`, `phpunit.dist.xml`, a `phpunit/phpunit` or `pestphp/pest` dependency, or a runner in `vendor/bin`.
|
||
- `artisan serve` in Laravel projects.
|
||
|
||
The PHPUnit run configuration type has **Target**, **Configuration file**, **Test filter** and **PHPUnit options** fields.
|
||
|
||
**Run Context Configuration** (`⌃⇧R` / `Ctrl+Shift+F10`) runs a `*Test.php` file through the PHPUnit configuration, and any other PHP file with the selected interpreter. In `*Test.php` files and files under `test/` or `tests/`, gutter icons run a single test class or method, or a Pest test. Results appear in the test tree with **Rerun Failed Tests**. See [Testing](/en/guide/testing).
|
||
|
||
## 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, `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.
|
||
- **In a Docker or Docker Compose run target** (**Run in target**), Debug works on the same configurations. The debugger listens on a free port first, then the run starts in a new container with `XDEBUG_MODE=debug`, `XDEBUG_SESSION=1` and `XDEBUG_CONFIG` pointing Xdebug at `host.docker.internal` and that port; the folders the container mounts are mapped onto their folders here. The image's PHP must load Xdebug 3 (the PHP settings page shows whether it does). Docker Desktop resolves `host.docker.internal`; on Linux a Docker target gets it with `--add-host`, and a Compose service needs `extra_hosts: ["host.docker.internal:host-gateway"]`. PHP on an SSH run target is not debugged this way: use PHP Remote Debug.
|
||
- **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).
|
||
|
||
## Frameworks
|
||
|
||
Run configurations and template highlighting work with any PHP server. The names a framework gives things (routes, views, services, configuration keys, hooks) are understood by PHPantom and Phoxite: where a section says "with PHPantom" or "with Phoxite", pick that server as the PHP server in **Settings › Languages & Frameworks › Language Servers**. Both find the frameworks of a project from the project itself and need no setup.
|
||
|
||
### Laravel
|
||
|
||
- **Run and debug**: an `artisan serve` configuration.
|
||
- **Blade views** (`.blade.php`) are highlighted: HTML, directives, `{{ }}` and `{!! !!}` echoes and the PHP inside them, with `{{-- --}}` comments.
|
||
- **Laravel LSP**, with Intelephense: hover, definition and completion inside `config('…')`, `route('…')` and `view('…')`.
|
||
- **With PHPantom**: completion, navigation, Find Usages and "unknown" warnings for route names, views, config keys, translation keys, middleware, gates and policies, Eloquent relations, scopes and columns, Livewire components and Folio pages; completion, hover, navigation and problems inside Blade views, with the types of the variables a view is rendered with.
|
||
- **With Phoxite**: completion, navigation, Find Usages, rename and "undefined" warnings for route names, views, config keys, translation keys, environment variables, validation rules, Eloquent columns and relations, Livewire components and Inertia pages; completion, hover, signature help and navigation inside Blade views; Find Usages and Rename of a key in `.env` and in `lang/*.json`.
|
||
|
||
### Symfony
|
||
|
||
- **Twig templates** (`.twig`) are highlighted: HTML, with tags, expressions and `{# #}` comments; blocks fold.
|
||
- **With PHPantom**: completion, navigation, Find Usages and "unknown" warnings for route names, template names, services and parameters, translation keys, form and validation options, events and Messenger handlers, across PHP, YAML, XML and Twig; Doctrine entities, repositories, mapping files and DQL. In Twig templates, in Symfony projects or not: completion, hover, navigation and problems for template names, blocks, filters, functions and the variables a render passes.
|
||
- **With Phoxite**: completion, navigation and rename for route names, template names, services and parameters, translation keys and Doctrine fields; in Twig templates, completion, hover, navigation (to an extended or included template, a function, a filter, a route), rename, the outline, formatting and problems.
|
||
|
||
### WordPress, Drupal, Magento and Joomla
|
||
|
||
With PHPantom, for WordPress and Drupal: WordPress core's types come from `php-stubs/wordpress-stubs` once Composer installs it, with return types that follow the arguments, and hook names complete, navigate between the places that fire and listen to them, and rename. Drupal services, entity types, hooks, routes, permissions, configuration names and plugin IDs complete and navigate in PHP and in a module's YAML, and the ones nothing declares are reported.
|
||
|
||
With Phoxite, in PHP: completion, navigation and Find Usages for the platform's names, such as WordPress hooks, shortcodes, options and block names, Drupal services, routes and permissions, Magento's events, configuration paths, ACL resources and layout handles, Joomla's language keys, layouts and form fields.
|
||
|
||
With Intelephense, add a platform's stubs under **Additional stubs** (for example `wordpress`) and its folder under **Include paths**.
|
||
|
||
### CodeIgniter, Yii, CakePHP and Laminas
|
||
|
||
With Phoxite, in PHP: completion, navigation and Find Usages for the framework's names (routes, views or templates, config keys, translation messages, services and components), and the types of the services, models and view variables the framework provides.
|
||
|
||
With PHPantom, for Yii 3: route names, views, aliases, DI definitions, params and translation message IDs complete, navigate and are checked, read from the application's configuration without booting it.
|
||
|
||
### Tempest
|
||
|
||
With PHPantom: completion, hover, navigation and problems inside `.view.php` templates and view components, with the types of the data a view is rendered with; component tags and view paths complete and navigate.
|
||
|
||
## Limitations
|
||
|
||
- With Intelephense, Phpactor or DEVSENSE, Blade views and Twig templates are highlighted but get no code insight of their own (a Blade view is read as PHP); with PHPantom or Phoxite they do.
|
||
- Run with Coverage is not available for PHPUnit.
|
||
- Debugging needs the Xdebug extension in your PHP; the IDE does not install it.
|
||
- With **Run in target** set to a Docker or Compose target, the language servers still run on this machine and read the mounted files; Phpactor still needs a local `php`.
|