This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+lang/php/README.org

113 lines
3.7 KiB
Org Mode
Raw Normal View History

#+TITLE: PHP layer
#+TAGS: general|layer|multi-paradigm|programming
2019-05-05 17:26:40 +00:00
2015-06-10 16:44:30 +00:00
[[file:img/php.png]]
2019-05-07 20:05:06 +00:00
* Table of Contents :TOC_5_gh:noexport:
2017-05-22 14:16:12 +00:00
- [[#description][Description]]
- [[#features][Features:]]
- [[#install][Install]]
2019-01-02 21:34:56 +00:00
- [[#layer][Layer]]
- [[#backends][Backends]]
2019-01-02 21:34:56 +00:00
- [[#intelephense][intelephense]]
- [[#php-language-server][php-language-server]]
- [[#ac-php-core][ac-php-core]]
- [[#setup][Setup]]
2017-05-22 14:16:12 +00:00
- [[#key-bindings][Key bindings]]
2015-06-10 16:44:30 +00:00
* Description
This layer adds PHP language support to Spacemacs.
** Features:
2015-06-10 16:44:30 +00:00
- Edit PHP files using [[https://github.com/ejmr/php-mode][php-mode]]
- Edit Drupal files
2017-05-24 05:18:41 +00:00
- Complete and jump to define with [[https://github.com/xcwen/ac-php][company-php]]
2015-06-10 16:44:30 +00:00
- Run tests with PHPUnit
- Reformat code with PHP CBF
2019-01-02 21:34:56 +00:00
- Support for the [[https://langserver.org/][Language Server Protocol]] (experimental)
2015-06-10 16:44:30 +00:00
The =gtags= layer is recommended to benefit from better =eldoc= and
=helm-gtags=.
* Install
2019-01-02 21:34:56 +00:00
** Layer
To use this configuration layer, add it to your =~/.spacemacs=. You will need to
add =php= to the existing =dotspacemacs-configuration-layers= list in this
file.
2015-06-10 16:44:30 +00:00
** Backends
For php you have the choice between a set of possible LSP backends with
different setup instructions and different capabilities.
Note that you'll need to use the =lsp= layer to enable these backends.
*** intelephense
This is the recommended LSP server solution. To activate it set the
layer variable =php-backend=:
2019-01-02 21:34:56 +00:00
#+BEGIN_SRC elisp
(php :variables php-backend 'lsp)
#+END_SRC
and install the npm server with:
2019-01-02 21:34:56 +00:00
#+BEGIN_SRC sh
npm install -g intelephense
2019-01-02 21:34:56 +00:00
#+END_SRC
You can find further information on the project's [[http://intelephense.net/][website]] and [[https://github.com/bmewburn/vscode-intelephense][GitHub page]].
*** php-language-server
This is an alternative LSP server implementation working on PHP basis rather than nodejs.
To activate it set the layer variable =php-backend= like for the intelephense backend and
install the server via [[https://getcomposer.org/][composer]]:
2019-01-02 21:34:56 +00:00
#+BEGIN_SRC sh
composer require felixfbecker/language-server
composer run-script --working-dir=vendor/felixfbecker/language-server parse-stubs
#+END_SRC
2019-11-10 14:11:03 +00:00
You can find further information on the project's [[https://github.com/felixfbecker/php-language-server][GitHub page]].
2019-01-02 21:34:56 +00:00
*** ac-php-core
This is a non server solution working entirely from an elisp package.
This requires no installation of external services but also delivers
the least amount of IDE like integrations with spacemacs.
2015-06-10 16:44:30 +00:00
To activate it just don't set the variable =php-backend= in your dotfile.
Remember that additional setup instructions are necessary on a per
project basis which you can find below.
2017-11-18 22:34:08 +00:00
**** Setup
2019-04-08 16:59:32 +00:00
Because of the way that the ac-php-core package works, there are a couple of simple
2017-11-18 22:34:08 +00:00
initialization tasks which must occur to get the completion working as it should.
On any new project make sure to perform the following initialization tasks:
1. Run the following
2018-09-19 03:54:47 +00:00
#+BEGIN_SRC shell
cd /root/of/project
touch .ac-php-conf.json
#+END_SRC
2018-09-19 03:54:47 +00:00
2017-11-18 22:34:08 +00:00
2. Inside of spacemacs run:
2019-04-08 16:59:32 +00:00
= ac-php-remake-tags =
The =.ac-php-conf.json= file is required to enable auto-completion. When you run
=ac-php-remake-tags= and your =.ac-php-conf.json= file is empty the default configuration
will be used and inserted in the file.
If your project contains the following files at the root folder:
1. =.projectile=
2. =vendor/autoload.php=
the necessary configuration file (=.ac-php-conf.json=) will be created automatically
if it does not exist.
* Key bindings
| Key binding | Description |
|-------------+-------------------------|
| ~SPC m g g~ | jump to define at point |
| ~C-t~ | jump back |